feat: create / update customer branch
This commit is contained in:
parent
c5317d60f1
commit
8d446113da
1 changed files with 104 additions and 93 deletions
|
|
@ -42,30 +42,35 @@ function attachmentLocation(customerId: string, branchId: string) {
|
||||||
return `customer/${customerId}/branch/${branchId}`;
|
return `customer/${customerId}/branch/${branchId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CustomerBranchCreate = {
|
export type CustomerBranchCreate = (
|
||||||
|
| {
|
||||||
|
// NOTE: About (Natural Person)
|
||||||
|
citizenId: string;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
// NOTE: About (Legal Entity)
|
||||||
|
legalPersonNo: string;
|
||||||
|
registerName: string;
|
||||||
|
registerNameEN: string;
|
||||||
|
registerDate: Date;
|
||||||
|
authorizedCapital: string;
|
||||||
|
}
|
||||||
|
) & {
|
||||||
customerId: string;
|
customerId: string;
|
||||||
|
|
||||||
status?: Status;
|
status?: Status;
|
||||||
|
|
||||||
legalPersonNo: string;
|
workplace: string;
|
||||||
|
workplaceEN: string;
|
||||||
branchNo: number;
|
|
||||||
taxNo: string | null;
|
|
||||||
name: string;
|
|
||||||
nameEN: string;
|
|
||||||
addressEN: string;
|
|
||||||
address: string;
|
address: string;
|
||||||
zipCode: string;
|
addressEN: string;
|
||||||
|
|
||||||
email: string;
|
email: string;
|
||||||
telephoneNo: string;
|
telephoneNo: string;
|
||||||
|
|
||||||
registerName: string;
|
|
||||||
registerDate: Date;
|
|
||||||
authorizedCapital: string;
|
|
||||||
|
|
||||||
employmentOffice: string;
|
employmentOffice: string;
|
||||||
bussinessType: string;
|
businessType: string;
|
||||||
bussinessTypeEN: string;
|
businessTypeEN: string;
|
||||||
jobPosition: string;
|
jobPosition: string;
|
||||||
jobPositionEN: string;
|
jobPositionEN: string;
|
||||||
jobDescription: string;
|
jobDescription: string;
|
||||||
|
|
@ -78,26 +83,32 @@ export type CustomerBranchCreate = {
|
||||||
provinceId?: string | null;
|
provinceId?: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CustomerBranchUpdate = {
|
export type CustomerBranchUpdate = (
|
||||||
|
| {
|
||||||
|
// NOTE: About (Natural Person)
|
||||||
|
citizenId: string;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
// NOTE: About (Legal Entity)
|
||||||
|
legalPersonNo: string;
|
||||||
|
registerName?: string;
|
||||||
|
registerNameEN?: string;
|
||||||
|
registerDate?: Date;
|
||||||
|
authorizedCapital?: string;
|
||||||
|
}
|
||||||
|
) & {
|
||||||
customerId?: string;
|
customerId?: string;
|
||||||
|
|
||||||
status?: "ACTIVE" | "INACTIVE";
|
status?: "ACTIVE" | "INACTIVE";
|
||||||
|
|
||||||
legalPersonNo?: string;
|
workplace: string;
|
||||||
|
workplaceEN: string;
|
||||||
|
address: string;
|
||||||
|
addressEN: string;
|
||||||
|
|
||||||
taxNo?: string | null;
|
|
||||||
name?: string;
|
|
||||||
nameEN?: string;
|
|
||||||
addressEN?: string;
|
|
||||||
address?: string;
|
|
||||||
zipCode?: string;
|
|
||||||
email?: string;
|
email?: string;
|
||||||
telephoneNo?: string;
|
telephoneNo?: string;
|
||||||
|
|
||||||
registerName?: string;
|
|
||||||
registerDate?: Date;
|
|
||||||
authorizedCapital?: string;
|
|
||||||
|
|
||||||
employmentOffice?: string;
|
employmentOffice?: string;
|
||||||
bussinessType?: string;
|
bussinessType?: string;
|
||||||
bussinessTypeEN?: string;
|
bussinessTypeEN?: string;
|
||||||
|
|
@ -305,37 +316,42 @@ export class CustomerBranchController extends Controller {
|
||||||
|
|
||||||
const record = await prisma.$transaction(
|
const record = await prisma.$transaction(
|
||||||
async (tx) => {
|
async (tx) => {
|
||||||
// const last = await tx.runningNo.upsert({
|
let runningKey = "";
|
||||||
// where: {
|
|
||||||
// key: `CUSTOMER_${customer.code.slice(0, -6)}`,
|
if ("citizenId" in body) {
|
||||||
// },
|
runningKey = `CUSTOMER_BRANCH_${body.citizenId}`;
|
||||||
// create: {
|
} else {
|
||||||
// key: `CUSTOMER_${customer.code.slice(0, -6)}`,
|
runningKey = `CUSTOMER_BRANCH_${body.legalPersonNo}`;
|
||||||
// value: 1,
|
}
|
||||||
// },
|
|
||||||
// update: { value: { increment: 1 } },
|
const last = await tx.runningNo.upsert({
|
||||||
// });
|
where: { key: runningKey },
|
||||||
//
|
create: {
|
||||||
// return await tx.customerBranch.create({
|
key: runningKey,
|
||||||
// include: {
|
value: 1,
|
||||||
// province: true,
|
},
|
||||||
// district: true,
|
update: { value: { increment: 1 } },
|
||||||
// subDistrict: true,
|
});
|
||||||
// createdBy: true,
|
|
||||||
// updatedBy: true,
|
return await tx.customerBranch.create({
|
||||||
// },
|
include: {
|
||||||
// data: {
|
province: true,
|
||||||
// ...rest,
|
district: true,
|
||||||
// statusOrder: +(rest.status === "INACTIVE"),
|
subDistrict: true,
|
||||||
// code: `${customer.code.slice(0, -6)}${`${last.value - 1}`.padStart(6, "0")}`,
|
createdBy: true,
|
||||||
// customer: { connect: { id: customerId } },
|
updatedBy: true,
|
||||||
// province: { connect: provinceId ? { id: provinceId } : undefined },
|
},
|
||||||
// district: { connect: districtId ? { id: districtId } : undefined },
|
data: {
|
||||||
// subDistrict: { connect: subDistrictId ? { id: subDistrictId } : undefined },
|
...rest,
|
||||||
// createdBy: { connect: { id: req.user.sub } },
|
code: `${"citizenId" in body ? body.citizenId : body.legalPersonNo}-${last.value - 1}`,
|
||||||
// updatedBy: { connect: { id: req.user.sub } },
|
customer: { connect: { id: customerId } },
|
||||||
// },
|
province: { connect: provinceId ? { id: provinceId } : undefined },
|
||||||
// });
|
district: { connect: districtId ? { id: districtId } : undefined },
|
||||||
|
subDistrict: { connect: subDistrictId ? { id: subDistrictId } : undefined },
|
||||||
|
createdBy: { connect: { id: req.user.sub } },
|
||||||
|
updatedBy: { connect: { id: req.user.sub } },
|
||||||
|
},
|
||||||
|
});
|
||||||
},
|
},
|
||||||
{ isolationLevel: Prisma.TransactionIsolationLevel.Serializable },
|
{ isolationLevel: Prisma.TransactionIsolationLevel.Serializable },
|
||||||
);
|
);
|
||||||
|
|
@ -391,41 +407,36 @@ export class CustomerBranchController extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// const { provinceId, districtId, subDistrictId, customerId, ...rest } = body;
|
const { provinceId, districtId, subDistrictId, customerId, ...rest } = body;
|
||||||
//
|
|
||||||
//
|
return await prisma.customerBranch.update({
|
||||||
// const record = await prisma.customerBranch.update({
|
where: { id: branchId },
|
||||||
// where: { id: branchId },
|
include: {
|
||||||
// include: {
|
province: true,
|
||||||
// province: true,
|
district: true,
|
||||||
// district: true,
|
subDistrict: true,
|
||||||
// subDistrict: true,
|
createdBy: true,
|
||||||
// createdBy: true,
|
updatedBy: true,
|
||||||
// updatedBy: true,
|
},
|
||||||
// },
|
data: {
|
||||||
// data: {
|
...rest,
|
||||||
// ...rest,
|
statusOrder: +(rest.status === "INACTIVE"),
|
||||||
// statusOrder: +(rest.status === "INACTIVE"),
|
customer: { connect: customerId ? { id: customerId } : undefined },
|
||||||
// customer: { connect: customerId ? { id: customerId } : undefined },
|
province: {
|
||||||
// province: {
|
connect: provinceId ? { id: provinceId } : undefined,
|
||||||
// connect: provinceId ? { id: provinceId } : undefined,
|
disconnect: provinceId === null || undefined,
|
||||||
// disconnect: provinceId === null || undefined,
|
},
|
||||||
// },
|
district: {
|
||||||
// district: {
|
connect: districtId ? { id: districtId } : undefined,
|
||||||
// connect: districtId ? { id: districtId } : undefined,
|
disconnect: districtId === null || undefined,
|
||||||
// disconnect: districtId === null || undefined,
|
},
|
||||||
// },
|
subDistrict: {
|
||||||
// subDistrict: {
|
connect: subDistrictId ? { id: subDistrictId } : undefined,
|
||||||
// connect: subDistrictId ? { id: subDistrictId } : undefined,
|
disconnect: subDistrictId === null || undefined,
|
||||||
// disconnect: subDistrictId === null || undefined,
|
},
|
||||||
// },
|
updatedBy: { connect: { id: req.user.sub } },
|
||||||
// updatedBy: { connect: { id: req.user.sub } },
|
},
|
||||||
// },
|
});
|
||||||
// });
|
|
||||||
//
|
|
||||||
// this.setStatus(HttpStatus.CREATED);
|
|
||||||
//
|
|
||||||
// return record;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete("{branchId}")
|
@Delete("{branchId}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue