diff --git a/src/controllers/01-branch-controller.ts b/src/controllers/01-branch-controller.ts index 179e313..adf928d 100644 --- a/src/controllers/01-branch-controller.ts +++ b/src/controllers/01-branch-controller.ts @@ -26,6 +26,7 @@ import { } from "../services/permission"; import { filterStatus } from "../services/prisma"; import { connectOrDisconnect, connectOrNot } from "../utils/relation"; +import { throwNotFound } from "../utils/error"; if (!process.env.MINIO_BUCKET) { throw Error("Require MinIO bucket."); @@ -297,9 +298,7 @@ export class BranchController extends Controller { where: { id: branchId }, }); - if (!record) { - throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "branchNotFound"); - } + if (!record) return throwNotFound("Branch"); return record; } @@ -541,16 +540,10 @@ export class BranchController extends Controller { where: { id: branchId }, }); - if (!record) { - throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "branchNotFound"); - } + if (!record) return throwNotFound("Branch"); await permissionCheck(req.user, record); - if (!record) { - throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "branchNotFound"); - } - if (record.status !== Status.CREATED) { throw new HttpError(HttpStatus.FORBIDDEN, "Branch is in used.", "branchInUsed"); } @@ -596,9 +589,7 @@ export class BranchFileController extends Controller { include: branchRelationPermInclude(user), where: { id }, }); - if (!data) { - throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "branchNotFound"); - } + if (!data) return throwNotFound("Branch"); await permissionCheck(user, data); }