feat: add user relation on query

This commit is contained in:
Methapon2001 2024-07-01 14:38:07 +07:00
parent 2bd30b735d
commit 9f3b8cd290
14 changed files with 259 additions and 41 deletions

View file

@ -39,6 +39,10 @@ export class EmployeeOtherInfo extends Controller {
@Get()
async list(@Path() employeeId: string) {
return prisma.employeeOtherInfo.findFirst({
include: {
createdBy: true,
updatedBy: true,
},
orderBy: { createdAt: "asc" },
where: { employeeId },
});
@ -54,6 +58,10 @@ export class EmployeeOtherInfo extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "Employee cannot be found.", "employeeBadReq");
const record = await prisma.employeeOtherInfo.create({
include: {
createdBy: true,
updatedBy: true,
},
data: {
...body,
employee: { connect: { id: employeeId } },
@ -83,6 +91,10 @@ export class EmployeeOtherInfo extends Controller {
}
const record = await prisma.employeeOtherInfo.update({
include: {
createdBy: true,
updatedBy: true,
},
where: { id: otherInfoId, employeeId },
data: { ...body, updatedByUserId: req.user.sub },
});
@ -106,6 +118,12 @@ export class EmployeeOtherInfo extends Controller {
);
}
return await prisma.employeeOtherInfo.delete({ where: { id: otherInfoId, employeeId } });
return await prisma.employeeOtherInfo.delete({
include: {
createdBy: true,
updatedBy: true,
},
where: { id: otherInfoId, employeeId },
});
}
}