feat: add code to customer branch for query purpose

This commit is contained in:
Methapon2001 2024-06-11 15:11:08 +07:00
parent 88ac8c4b81
commit 7e104a0020
2 changed files with 38 additions and 38 deletions

View file

@ -290,6 +290,7 @@ export class CustomerController extends Controller {
customerBranch?.map((v, i) => ({
...v,
branchNo: i + 1,
code: `${last.key.slice(9)}${last.value.toString().padStart(6, "0")}-${(i + 1).toString().padStart(2, "0")}`,
createdBy: req.user.name,
updateBy: req.user.name,
})) || [],
@ -325,7 +326,9 @@ export class CustomerController extends Controller {
@Request() req: RequestWithUser,
@Body() body: CustomerUpdate,
) {
if (!(await prisma.customer.findUnique({ where: { id: customerId } }))) {
const customer = await prisma.customer.findUnique({ where: { id: customerId } });
if (!customer) {
throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "data_not_found");
}
@ -417,6 +420,7 @@ export class CustomerController extends Controller {
create: {
...v,
branchNo: i + 1,
code: `${customer.code}-${(i + 1).toString().padStart(2, "0")}`,
createdBy: req.user.name,
updateBy: req.user.name,
id: undefined,
@ -424,6 +428,7 @@ export class CustomerController extends Controller {
update: {
...v,
branchNo: i + 1,
code: `${customer.code}-${(i + 1).toString().padStart(2, "0")}`,
updateBy: req.user.name,
},
})),