refactor: update isolation level
This commit is contained in:
parent
784c245557
commit
73265c8965
2 changed files with 46 additions and 40 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue