refactor: user relation
This commit is contained in:
parent
a74d8b63b1
commit
2bd30b735d
21 changed files with 607 additions and 185 deletions
|
|
@ -46,7 +46,11 @@ export class EmployeeWorkController extends Controller {
|
|||
where: { id: workId, employeeId },
|
||||
});
|
||||
if (!record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "Employee work cannot be found.", "employeeWorkNotFound");
|
||||
throw new HttpError(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"Employee work cannot be found.",
|
||||
"employeeWorkNotFound",
|
||||
);
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
|
@ -58,18 +62,14 @@ export class EmployeeWorkController extends Controller {
|
|||
@Body() body: EmployeeWorkPayload,
|
||||
) {
|
||||
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.employeeWork.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 } },
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -86,12 +86,16 @@ export class EmployeeWorkController extends Controller {
|
|||
@Body() body: EmployeeWorkPayload,
|
||||
) {
|
||||
if (!(await prisma.employeeWork.findUnique({ where: { id: workId, employeeId } }))) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "Employee work cannot be found.", "employeeWorkNotFound");
|
||||
throw new HttpError(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"Employee work cannot be found.",
|
||||
"employeeWorkNotFound",
|
||||
);
|
||||
}
|
||||
|
||||
const record = await prisma.employeeWork.update({
|
||||
where: { id: workId, employeeId },
|
||||
data: { ...body, createdBy: req.user.name, updatedBy: req.user.name },
|
||||
data: { ...body, updatedByUserId: req.user.sub },
|
||||
});
|
||||
|
||||
this.setStatus(HttpStatus.CREATED);
|
||||
|
|
@ -104,7 +108,11 @@ export class EmployeeWorkController extends Controller {
|
|||
const record = await prisma.employeeWork.findFirst({ where: { id: workId, employeeId } });
|
||||
|
||||
if (!record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "Employee work cannot be found.", "employeeWorkNotFound");
|
||||
throw new HttpError(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"Employee work cannot be found.",
|
||||
"employeeWorkNotFound",
|
||||
);
|
||||
}
|
||||
|
||||
return await prisma.employeeWork.delete({ where: { id: workId, employeeId } });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue