feat: auto gen branch no

This commit is contained in:
Methapon2001 2024-04-18 09:22:53 +07:00
parent a352b87470
commit d4cfd138d9

View file

@ -34,7 +34,6 @@ type CustomerBranchCreate = {
status?: Status;
branchNo: string;
legalPersonNo: string;
taxNo: string;
@ -62,7 +61,6 @@ type CustomerBranchUpdate = {
status?: "ACTIVE" | "INACTIVE";
branchNo?: string;
legalPersonNo?: string;
taxNo?: string;
@ -228,6 +226,10 @@ export class CustomerBranchController extends Controller {
const { provinceId, districtId, subDistrictId, customerId, ...rest } = body;
const count = await prisma.customerBranch.count({
where: { customerId },
});
const record = await prisma.customerBranch.create({
include: {
province: true,
@ -236,6 +238,7 @@ export class CustomerBranchController extends Controller {
},
data: {
...rest,
branchNo: `${count + 1}`,
customer: { connect: { id: customerId } },
province: { connect: provinceId ? { id: provinceId } : undefined },
district: { connect: districtId ? { id: districtId } : undefined },