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";
|
||||
workflowId?: string;
|
||||
work?: {
|
||||
id?: string;
|
||||
name: string;
|
||||
product: {
|
||||
id: string;
|
||||
|
|
@ -401,17 +402,36 @@ export class ServiceController extends Controller {
|
|||
...payload,
|
||||
statusOrder: +(payload.status === "INACTIVE"),
|
||||
work: {
|
||||
deleteMany: {},
|
||||
create: (work || []).map((w, wIdx) => ({
|
||||
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,
|
||||
})),
|
||||
deleteMany: {
|
||||
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,
|
||||
order: wIdx + 1,
|
||||
attributes: w.attributes,
|
||||
productOnWork: {
|
||||
create: w.product.map((p, pIdx) => ({
|
||||
productId: p.id,
|
||||
installmentNo: p.installmentNo,
|
||||
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,
|
||||
})),
|
||||
},
|
||||
},
|
||||
})),
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue