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()
|
@Post()
|
||||||
async createProductGroup(@Request() req: RequestWithUser, @Body() body: ProductGroupCreate) {
|
async createProductGroup(@Request() req: RequestWithUser, @Body() body: ProductGroupCreate) {
|
||||||
const record = await prisma.$transaction(async (tx) => {
|
const record = await prisma.$transaction(
|
||||||
const last = await tx.runningNo.upsert({
|
async (tx) => {
|
||||||
where: {
|
const last = await tx.runningNo.upsert({
|
||||||
key: `PRODGRP`,
|
where: {
|
||||||
},
|
key: `PRODGRP`,
|
||||||
create: {
|
},
|
||||||
key: `PRODGRP`,
|
create: {
|
||||||
value: 1,
|
key: `PRODGRP`,
|
||||||
},
|
value: 1,
|
||||||
update: { value: { increment: 1 } },
|
},
|
||||||
});
|
update: { value: { increment: 1 } },
|
||||||
|
});
|
||||||
|
|
||||||
return await tx.productGroup.create({
|
return await tx.productGroup.create({
|
||||||
data: {
|
data: {
|
||||||
...body,
|
...body,
|
||||||
code: `G${last.value.toString().padStart(2, "0")}`,
|
code: `G${last.value.toString().padStart(2, "0")}`,
|
||||||
createdBy: req.user.name,
|
createdBy: req.user.name,
|
||||||
updateBy: req.user.name,
|
updateBy: req.user.name,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
{ isolationLevel: Prisma.TransactionIsolationLevel.Serializable },
|
||||||
|
);
|
||||||
|
|
||||||
this.setStatus(HttpStatus.CREATED);
|
this.setStatus(HttpStatus.CREATED);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,27 +77,30 @@ export class ProductType extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const record = await prisma.$transaction(async (tx) => {
|
const record = await prisma.$transaction(
|
||||||
const last = await tx.runningNo.upsert({
|
async (tx) => {
|
||||||
where: {
|
const last = await tx.runningNo.upsert({
|
||||||
key: `PRODTYP_T${productGroup.code}`,
|
where: {
|
||||||
},
|
key: `PRODTYP_T${productGroup.code}`,
|
||||||
create: {
|
},
|
||||||
key: `PRODTYP_T${productGroup.code}`,
|
create: {
|
||||||
value: 1,
|
key: `PRODTYP_T${productGroup.code}`,
|
||||||
},
|
value: 1,
|
||||||
update: { value: { increment: 1 } },
|
},
|
||||||
});
|
update: { value: { increment: 1 } },
|
||||||
|
});
|
||||||
|
|
||||||
return await tx.productType.create({
|
return await tx.productType.create({
|
||||||
data: {
|
data: {
|
||||||
...body,
|
...body,
|
||||||
code: `T${productGroup.code}${last.value.toString().padStart(2, "0")}`,
|
code: `T${productGroup.code}${last.value.toString().padStart(2, "0")}`,
|
||||||
createdBy: req.user.name,
|
createdBy: req.user.name,
|
||||||
updateBy: req.user.name,
|
updateBy: req.user.name,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
{ isolationLevel: Prisma.TransactionIsolationLevel.Serializable },
|
||||||
|
);
|
||||||
|
|
||||||
this.setStatus(HttpStatus.CREATED);
|
this.setStatus(HttpStatus.CREATED);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue