From 18ef97cc713aafa07f42e4a31cf23d3e8f7ccabe Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Mon, 23 Sep 2024 17:52:12 +0700 Subject: [PATCH] Revert "feat: allow company change" This reverts commit 6ba5234587797fa4033e0c40b4312f84f7c9b82d. --- .../04-product-group-controller.ts | 43 +++++++------------ 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/src/controllers/04-product-group-controller.ts b/src/controllers/04-product-group-controller.ts index 4ecc7f1..50b77f7 100644 --- a/src/controllers/04-product-group-controller.ts +++ b/src/controllers/04-product-group-controller.ts @@ -230,34 +230,21 @@ export class ProductGroup extends Controller { let companyAfter = !!body.registeredBranchId && branch ? (branch.headOffice || branch).code : false; - const result = await prisma.$transaction(async (tx) => { - let code = ""; - if (companyBefore && companyAfter && companyBefore !== companyAfter) { - const last = await tx.runningNo.upsert({ - where: { - key: `PRODGRP_${companyAfter}`, - }, - create: { - key: `PRODGRP_${companyAfter}`, - value: 1, - }, - update: { value: { increment: 1 } }, - }); - code = `G${last.value.toString().padStart(2, "0")}`; - } - return await prisma.productGroup.update({ - include: { - createdBy: true, - updatedBy: true, - }, - data: { - ...body, - code: !!code ? code : undefined, - statusOrder: +(body.status === "INACTIVE"), - updatedByUserId: req.user.sub, - }, - where: { id: groupId }, - }); + if (companyBefore && companyAfter && companyBefore !== companyAfter) { + throw new HttpError( + HttpStatus.BAD_REQUEST, + "Cannot move between different headoffice", + "crossCompanyNotPermit", + ); + } + + const result = await prisma.productGroup.update({ + include: { + createdBy: true, + updatedBy: true, + }, + data: { ...body, statusOrder: +(body.status === "INACTIVE"), updatedByUserId: req.user.sub }, + where: { id: groupId }, }); return result;