diff --git a/src/controllers/product/group-controller.ts b/src/controllers/product/group-controller.ts index dd4873f..fb6ace0 100644 --- a/src/controllers/product/group-controller.ts +++ b/src/controllers/product/group-controller.ts @@ -63,27 +63,30 @@ export class ProductGroup extends Controller { @Post() async createProductGroup(@Request() req: RequestWithUser, @Body() body: ProductGroupCreate) { - const record = await prisma.$transaction(async (tx) => { - const last = await tx.runningNo.upsert({ - where: { - key: `PRODGRP`, - }, - create: { - key: `PRODGRP`, - value: 1, - }, - update: { value: { increment: 1 } }, - }); + const record = await prisma.$transaction( + async (tx) => { + const last = await tx.runningNo.upsert({ + where: { + key: `PRODGRP`, + }, + create: { + key: `PRODGRP`, + value: 1, + }, + update: { value: { increment: 1 } }, + }); - return await tx.productGroup.create({ - data: { - ...body, - code: `G${last.value.toString().padStart(2, "0")}`, - createdBy: req.user.name, - updateBy: req.user.name, - }, - }); - }); + return await tx.productGroup.create({ + data: { + ...body, + code: `G${last.value.toString().padStart(2, "0")}`, + createdBy: req.user.name, + updateBy: req.user.name, + }, + }); + }, + { isolationLevel: Prisma.TransactionIsolationLevel.Serializable }, + ); this.setStatus(HttpStatus.CREATED); diff --git a/src/controllers/product/type-controller.ts b/src/controllers/product/type-controller.ts index d27d834..c450cd5 100644 --- a/src/controllers/product/type-controller.ts +++ b/src/controllers/product/type-controller.ts @@ -77,27 +77,30 @@ export class ProductType extends Controller { ); } - const record = await prisma.$transaction(async (tx) => { - const last = await tx.runningNo.upsert({ - where: { - key: `PRODTYP_T${productGroup.code}`, - }, - create: { - key: `PRODTYP_T${productGroup.code}`, - value: 1, - }, - update: { value: { increment: 1 } }, - }); + const record = await prisma.$transaction( + async (tx) => { + const last = await tx.runningNo.upsert({ + where: { + key: `PRODTYP_T${productGroup.code}`, + }, + create: { + key: `PRODTYP_T${productGroup.code}`, + value: 1, + }, + update: { value: { increment: 1 } }, + }); - return await tx.productType.create({ - data: { - ...body, - code: `T${productGroup.code}${last.value.toString().padStart(2, "0")}`, - createdBy: req.user.name, - updateBy: req.user.name, - }, - }); - }); + return await tx.productType.create({ + data: { + ...body, + code: `T${productGroup.code}${last.value.toString().padStart(2, "0")}`, + createdBy: req.user.name, + updateBy: req.user.name, + }, + }); + }, + { isolationLevel: Prisma.TransactionIsolationLevel.Serializable }, + ); this.setStatus(HttpStatus.CREATED);