import axios from "axios";

function filed2json(value) {
  return {
    job: {
      name: value.name.trim(),
      job_classify_root: value.class.father.trim(),
      job_classify: value.class.son.trim(),
      num: value.num,
      job_category: value.prop,
      city: value.city[1],
      address: value.address.trim(),
      max_salary: Number(value.max),
      min_salary: Number(value.min),
      education: value.edu,
      work_year: value.exp,
      description: value.desc.trim(),
      introduce: value.intro ? value.intro.trim() : "",
    },
  };
}
export async function submitJobInfo(value) {
  await axios.post(`/jobs.json`, filed2json(value));
  return;
}
export async function updateJobInfo(jobID, value) {
  return (await axios.put(`/jobs/${jobID}.json`, filed2json(value))).data;
}

export async function applyProfile(JobID) {
  return (await axios.post(`/jobs/${JobID}/apply.json`)).data;
}
