feat: add fields customer

This commit is contained in:
Methapon Metanipat 2024-09-12 15:08:07 +07:00
parent 20725b0357
commit 2f85dab0a3
2 changed files with 56 additions and 35 deletions

View file

@ -420,20 +420,28 @@ model Customer {
id String @id @default(cuid())
customerType CustomerType
telephoneNo String
namePrefix String?
firstName String
firstName String?
firstNameEN String?
lastName String
lastName String?
lastNameEN String?
gender String
birthDate DateTime @db.Date
gender String?
birthDate DateTime? @db.Date
citizenId String?
legalPersonNo String?
registerName String?
registerNameEN String?
businessType String?
jobPosition String?
status Status @default(CREATED)
statusOrder Int @default(0)
registeredBranchId String?
registeredBranch Branch? @relation(fields: [registeredBranchId], references: [id])
registeredBranchId String
registeredBranch Branch @relation(fields: [registeredBranchId], references: [id])
selectedImage String?

View file

@ -45,35 +45,55 @@ function globalAllow(user: RequestWithUser["user"]) {
const permissionCond = createPermCondition(globalAllow);
const permissionCheck = createPermCheck(globalAllow);
export type CustomerCreate = {
registeredBranchId?: string;
export type CustomerCreate = (
| {
namePrefix: string;
firstName: string;
firstNameEN?: string;
lastName: string;
lastNameEN?: string;
gender: string;
birthDate: Date;
telephoneNo: string;
}
| {
legalPersonNo: string;
registerName: string;
registerNameEN?: string;
businessType: string;
jobPosition: string;
telephoneNo: string;
}
) & {
registeredBranchId: string;
status?: Status;
customerType: CustomerType;
namePrefix: string;
firstName: string;
firstNameEN?: string;
lastName: string;
lastNameEN?: string;
gender: string;
birthDate: Date;
selectedImage?: string;
};
export type CustomerUpdate = {
export type CustomerUpdate = (
| {
namePrefix: string;
firstName: string;
firstNameEN?: string;
lastName: string;
lastNameEN?: string;
gender: string;
birthDate: Date;
telephoneNo: string;
}
| {
legalPersonNo: string;
registerName: string;
registerNameEN: string;
businessType: string;
jobPosition: string;
telephoneNo: string;
}
) & {
registeredBranchId?: string;
status?: "ACTIVE" | "INACTIVE";
customerType?: CustomerType;
namePrefix?: string;
firstName?: string;
firstNameEN?: string;
lastName?: string;
lastNameEN?: string;
gender?: string;
birthDate?: Date;
selectedImage?: string;
};
@ -184,9 +204,6 @@ export class CustomerController extends Controller {
@Post()
@Security("keycloak", MANAGE_ROLES)
async create(@Request() req: RequestWithUser, @Body() body: CustomerCreate) {
// NOTE: handle empty string
if (!body.registeredBranchId) body.registeredBranchId = undefined;
const [branch] = await prisma.$transaction([
prisma.branch.findFirst({
where: { id: body.registeredBranchId },
@ -194,11 +211,7 @@ export class CustomerController extends Controller {
}),
]);
if (!!body.registeredBranchId && !branch) throw relationError("Branch");
if (body.registeredBranchId !== undefined && branch) {
await permissionCheck(req.user, branch);
}
await permissionCheck(req.user, branch);
const record = await prisma.$transaction(
async (tx) => {