refactor: throw common error with util function instead
This commit is contained in:
parent
68f9dc203e
commit
4de0e1da87
12 changed files with 67 additions and 142 deletions
|
|
@ -16,7 +16,6 @@ import {
|
|||
import { RequestWithUser } from "../interfaces/user";
|
||||
import prisma from "../db";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { isSystem } from "../utils/keycloak";
|
||||
import {
|
||||
branchRelationPermInclude,
|
||||
|
|
@ -25,7 +24,7 @@ import {
|
|||
} from "../services/permission";
|
||||
import { filterStatus } from "../services/prisma";
|
||||
import { connectOrDisconnect, connectOrNot, whereAddressQuery } from "../utils/relation";
|
||||
import { notFoundError, relationError } from "../utils/error";
|
||||
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
||||
import { deleteFile, deleteFolder, fileLocation, getFile, listFile, setFile } from "../utils/minio";
|
||||
|
||||
const MANAGE_ROLES = [
|
||||
|
|
@ -415,9 +414,7 @@ export class CustomerBranchController extends Controller {
|
|||
},
|
||||
});
|
||||
|
||||
if (!branch) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "branchNotFound");
|
||||
}
|
||||
if (!branch) throw notFoundError("Customer Branch");
|
||||
|
||||
await permissionCheck(req.user, branch.customer.registeredBranch);
|
||||
|
||||
|
|
@ -487,13 +484,7 @@ export class CustomerBranchController extends Controller {
|
|||
|
||||
await permissionCheck(req.user, record.customer.registeredBranch);
|
||||
|
||||
if (record.status !== Status.CREATED) {
|
||||
throw new HttpError(
|
||||
HttpStatus.FORBIDDEN,
|
||||
"Customer branch is in used.",
|
||||
"customerBranchInUsed",
|
||||
);
|
||||
}
|
||||
if (record.status !== Status.CREATED) throw isUsedError("Customer Branch");
|
||||
|
||||
return await prisma.$transaction(async (tx) => {
|
||||
if (record.code.endsWith("00")) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue