feat: add relation businessType
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 5s

This commit is contained in:
Kanjana 2025-07-11 15:49:49 +07:00
parent fc22c38472
commit 463a3cafd8
2 changed files with 14 additions and 1 deletions

View file

@ -789,6 +789,7 @@ model BusinessType {
updatedByUserId String?
customerBranch CustomerBranch[]
employeeWork EmployeeWork[]
}
model Employee {
@ -965,7 +966,6 @@ model EmployeeWork {
ownerName String?
positionName String?
businessTypeId String?
workplace String?
identityNo String?
workPermitNo String?
@ -973,6 +973,9 @@ model EmployeeWork {
workPermitExpireDate DateTime? @db.Date
workPermitAt String?
businessType BusinessType? @relation(fields: [businessTypeId], references: [id], onDelete: SetNull)
businessTypeId String?
createdAt DateTime @default(now())
createdBy User? @relation(name: "EmployeeWorkCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
createdByUserId String?

View file

@ -72,6 +72,7 @@ export class EmployeeWorkController extends Controller {
include: {
createdBy: true,
updatedBy: true,
businessType: true,
},
where: { id: workId, employeeId },
});
@ -86,10 +87,17 @@ export class EmployeeWorkController extends Controller {
@Path() employeeId: string,
@Body() body: EmployeeWorkPayload,
) {
const businessType = await prisma.businessType.findUnique({
where: { id: body.businessTypeId },
});
if (!businessType) throw notFoundError("Business Type");
const record = await prisma.employeeWork.create({
include: {
createdBy: true,
updatedBy: true,
businessType: true,
},
data: {
...body,
@ -120,6 +128,7 @@ export class EmployeeWorkController extends Controller {
include: {
createdBy: true,
updatedBy: true,
businessType: true,
},
where: { id: workId, employeeId },
data: { ...body, updatedByUserId: req.user.sub },
@ -137,6 +146,7 @@ export class EmployeeWorkController extends Controller {
include: {
createdBy: true,
updatedBy: true,
businessType: true,
},
where: { id: workId, employeeId },
});