refactor: user relation

This commit is contained in:
Methapon2001 2024-07-01 13:24:02 +07:00
parent a74d8b63b1
commit 2bd30b735d
21 changed files with 607 additions and 185 deletions

View file

@ -51,18 +51,14 @@ export class EmployeeOtherInfo extends Controller {
@Body() body: EmployeeOtherInfoPayload,
) {
if (!(await prisma.employee.findUnique({ where: { id: employeeId } })))
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Employee cannot be found.",
"employeeBadReq",
);
throw new HttpError(HttpStatus.BAD_REQUEST, "Employee cannot be found.", "employeeBadReq");
const record = await prisma.employeeOtherInfo.create({
data: {
...body,
employee: { connect: { id: employeeId } },
createdBy: req.user.name,
updatedBy: req.user.name,
createdBy: { connect: { id: req.user.sub } },
updatedBy: { connect: { id: req.user.sub } },
},
});
@ -88,7 +84,7 @@ export class EmployeeOtherInfo extends Controller {
const record = await prisma.employeeOtherInfo.update({
where: { id: otherInfoId, employeeId },
data: { ...body, createdBy: req.user.name, updatedBy: req.user.name },
data: { ...body, updatedByUserId: req.user.sub },
});
this.setStatus(HttpStatus.CREATED);