BOD-21 Bug fixes for production columns.

This commit is contained in:
Patrick Fic
2020-04-23 10:34:52 -07:00
parent 7544549e10
commit faa93a5e21
12 changed files with 182 additions and 67 deletions

View File

@@ -0,0 +1,49 @@
import {
QUERY_ALL_JOB_FIELDS,
INSERT_NEW_JOB,
} from "../../graphql/jobs.queries";
export default function DuplicateJob(
apolloClient,
jobId,
config,
completionCallback
) {
const { defaultOpenStatus } = config;
//get a list of all fields on the job
apolloClient
.query({ query: QUERY_ALL_JOB_FIELDS, variables: { id: jobId } })
.then((res) => {
const { jobs_by_pk: existingJob } = res.data;
delete existingJob.__typename;
delete existingJob.id;
existingJob.date_estimated = new Date();
existingJob.status = defaultOpenStatus;
const _tempLines = existingJob.joblines;
_tempLines.forEach((line) => {
delete line.id;
delete line.__typename;
});
delete existingJob.joblines;
existingJob.joblines = { data: _tempLines };
apolloClient
.mutate({
mutation: INSERT_NEW_JOB,
variables: { job: [existingJob] },
})
.then((res2) => {
console.log("res2", res2);
if (completionCallback)
completionCallback(res2.data.insert_jobs.returning[0].id);
});
});
//insert the new job. call the callback with the returned ID when done.
return;
}