refactor: use helper
This commit is contained in:
parent
3394ff0caa
commit
77739da154
4 changed files with 29 additions and 93 deletions
|
|
@ -15,8 +15,8 @@ import {
|
|||
import { RequestWithUser } from "../interfaces/user";
|
||||
import prisma from "../db";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { permissionCheck } from "../middlewares/employee";
|
||||
import { notFoundError } from "../utils/error";
|
||||
|
||||
const MANAGE_ROLES = [
|
||||
"system",
|
||||
|
|
@ -71,13 +71,7 @@ export class EmployeeWorkController extends Controller {
|
|||
},
|
||||
where: { id: workId, employeeId },
|
||||
});
|
||||
if (!record) {
|
||||
throw new HttpError(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"Employee work cannot be found.",
|
||||
"employeeWorkNotFound",
|
||||
);
|
||||
}
|
||||
if (!record) throw notFoundError("Employee Work");
|
||||
return record;
|
||||
}
|
||||
|
||||
|
|
@ -88,9 +82,6 @@ export class EmployeeWorkController extends Controller {
|
|||
@Path() employeeId: string,
|
||||
@Body() body: EmployeeWorkPayload,
|
||||
) {
|
||||
if (!(await prisma.employee.findUnique({ where: { id: employeeId } })))
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "Employee cannot be found.", "employeeBadReq");
|
||||
|
||||
const record = await prisma.employeeWork.create({
|
||||
include: {
|
||||
createdBy: true,
|
||||
|
|
@ -117,13 +108,9 @@ export class EmployeeWorkController extends Controller {
|
|||
@Path() workId: string,
|
||||
@Body() body: EmployeeWorkPayload,
|
||||
) {
|
||||
if (!(await prisma.employeeWork.findUnique({ where: { id: workId, employeeId } }))) {
|
||||
throw new HttpError(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"Employee work cannot be found.",
|
||||
"employeeWorkNotFound",
|
||||
);
|
||||
}
|
||||
const work = await prisma.employeeWork.findUnique({ where: { id: workId, employeeId } });
|
||||
|
||||
if (!work) throw notFoundError("Employee Work");
|
||||
|
||||
const record = await prisma.employeeWork.update({
|
||||
include: {
|
||||
|
|
@ -150,13 +137,7 @@ export class EmployeeWorkController extends Controller {
|
|||
where: { id: workId, employeeId },
|
||||
});
|
||||
|
||||
if (!record) {
|
||||
throw new HttpError(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"Employee work cannot be found.",
|
||||
"employeeWorkNotFound",
|
||||
);
|
||||
}
|
||||
if (!record) throw notFoundError("Employee Work");
|
||||
|
||||
return await prisma.employeeWork.delete({ where: { id: workId, employeeId } });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue