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()) id String @id @default(cuid())
customerType CustomerType customerType CustomerType
telephoneNo String
namePrefix String? namePrefix String?
firstName String firstName String?
firstNameEN String? firstNameEN String?
lastName String lastName String?
lastNameEN String? lastNameEN String?
gender String gender String?
birthDate DateTime @db.Date birthDate DateTime? @db.Date
citizenId String?
legalPersonNo String?
registerName String?
registerNameEN String?
businessType String?
jobPosition String?
status Status @default(CREATED) status Status @default(CREATED)
statusOrder Int @default(0) statusOrder Int @default(0)
registeredBranchId String? registeredBranchId String
registeredBranch Branch? @relation(fields: [registeredBranchId], references: [id]) registeredBranch Branch @relation(fields: [registeredBranchId], references: [id])
selectedImage String? selectedImage String?

View file

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