refactor: use utility function
This commit is contained in:
parent
42d5e3e26d
commit
2fff5f7e47
1 changed files with 4 additions and 13 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue