Added duplicate without repair data IO-580
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import {
|
||||
QUERY_ALL_JOB_FIELDS,
|
||||
INSERT_NEW_JOB,
|
||||
} from "../../graphql/jobs.queries";
|
||||
import _ from "lodash";
|
||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||
|
||||
import {
|
||||
INSERT_NEW_JOB,
|
||||
QUERY_ALL_JOB_FIELDS,
|
||||
} from "../../graphql/jobs.queries";
|
||||
export default function DuplicateJob(
|
||||
apolloClient,
|
||||
jobId,
|
||||
config,
|
||||
completionCallback
|
||||
completionCallback,
|
||||
keepJobLines = false
|
||||
) {
|
||||
logImEXEvent("job_duplicate");
|
||||
|
||||
@@ -18,25 +19,26 @@ export default function DuplicateJob(
|
||||
.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 newJob = _.cloneDeep(existingJob);
|
||||
delete newJob.__typename;
|
||||
delete newJob.id;
|
||||
newJob.date_estimated = new Date();
|
||||
newJob.status = defaultOpenStatus;
|
||||
|
||||
const _tempLines = existingJob.joblines;
|
||||
const _tempLines = newJob.joblines;
|
||||
_tempLines.forEach((line) => {
|
||||
delete line.id;
|
||||
delete line.__typename;
|
||||
});
|
||||
|
||||
delete existingJob.joblines;
|
||||
existingJob.joblines = { data: _tempLines };
|
||||
delete newJob.joblines;
|
||||
newJob.joblines = keepJobLines ? { data: _tempLines } : null;
|
||||
|
||||
apolloClient
|
||||
.mutate({
|
||||
mutation: INSERT_NEW_JOB,
|
||||
variables: { job: [existingJob] },
|
||||
variables: { job: [newJob] },
|
||||
})
|
||||
.then((res2) => {
|
||||
if (completionCallback)
|
||||
|
||||
Reference in New Issue
Block a user