refactor: prevent recreation of work
This commit is contained in:
parent
c7ae96d119
commit
6580c17273
1 changed files with 31 additions and 11 deletions
|
|
@ -91,6 +91,7 @@ type ServiceUpdate = {
|
||||||
status?: "ACTIVE" | "INACTIVE";
|
status?: "ACTIVE" | "INACTIVE";
|
||||||
workflowId?: string;
|
workflowId?: string;
|
||||||
work?: {
|
work?: {
|
||||||
|
id?: string;
|
||||||
name: string;
|
name: string;
|
||||||
product: {
|
product: {
|
||||||
id: string;
|
id: string;
|
||||||
|
|
@ -401,8 +402,14 @@ export class ServiceController extends Controller {
|
||||||
...payload,
|
...payload,
|
||||||
statusOrder: +(payload.status === "INACTIVE"),
|
statusOrder: +(payload.status === "INACTIVE"),
|
||||||
work: {
|
work: {
|
||||||
deleteMany: {},
|
deleteMany: {
|
||||||
create: (work || []).map((w, wIdx) => ({
|
id: work?.some((v) => !!v.id)
|
||||||
|
? { notIn: work.flatMap((v) => (!!v.id ? v.id : [])) }
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
upsert: (work || []).map((w, wIdx) => ({
|
||||||
|
where: { id: w.id },
|
||||||
|
create: {
|
||||||
name: w.name,
|
name: w.name,
|
||||||
order: wIdx + 1,
|
order: wIdx + 1,
|
||||||
attributes: w.attributes,
|
attributes: w.attributes,
|
||||||
|
|
@ -413,6 +420,19 @@ export class ServiceController extends Controller {
|
||||||
order: pIdx + 1,
|
order: pIdx + 1,
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
update: {
|
||||||
|
name: w.name,
|
||||||
|
order: wIdx + 1,
|
||||||
|
attributes: w.attributes,
|
||||||
|
productOnWork: {
|
||||||
|
create: w.product.map((p, pIdx) => ({
|
||||||
|
productId: p.id,
|
||||||
|
installmentNo: p.installmentNo,
|
||||||
|
order: pIdx + 1,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
},
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
updatedByUserId: req.user.sub,
|
updatedByUserId: req.user.sub,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue