diff --git a/src/controllers/service/service-controller.ts b/src/controllers/service/service-controller.ts index edba6d1..bdbb259 100644 --- a/src/controllers/service/service-controller.ts +++ b/src/controllers/service/service-controller.ts @@ -178,6 +178,26 @@ export class ServiceController extends Controller { update: { value: { increment: 1 } }, }); + const workList = await Promise.all( + (work || []).map(async (w, wIdx) => + tx.work.create({ + data: { + name: w.name, + order: wIdx + 1, + attributes: w.attributes, + productOnWork: { + createMany: { + data: w.productId.map((p, pIdx) => ({ + productId: p, + order: pIdx + 1, + })), + }, + }, + }, + }), + ), + ); + return tx.service.create({ include: { work: { @@ -194,15 +214,7 @@ export class ServiceController extends Controller { data: { ...payload, code: `${body.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`, - work: { - createMany: { - data: - work?.map((v, i) => ({ - ...v, - order: i + 1, - })) || [], - }, - }, + work: { connect: workList.map((v) => ({ id: v.id })) }, createdBy: req.user.name, updateBy: req.user.name, },