refactor: helper function manual throw
This change is to prevent swagger to infer empty type from return type
This commit is contained in:
parent
5b9472b466
commit
4da867cde1
4 changed files with 22 additions and 22 deletions
|
|
@ -26,7 +26,7 @@ import {
|
|||
} from "../services/permission";
|
||||
import { filterStatus } from "../services/prisma";
|
||||
import { connectOrDisconnect, connectOrNot } from "../utils/relation";
|
||||
import { throwNotFound } from "../utils/error";
|
||||
import { notFoundError } from "../utils/error";
|
||||
|
||||
if (!process.env.MINIO_BUCKET) {
|
||||
throw Error("Require MinIO bucket.");
|
||||
|
|
@ -298,7 +298,7 @@ export class BranchController extends Controller {
|
|||
where: { id: branchId },
|
||||
});
|
||||
|
||||
if (!record) return throwNotFound("Branch");
|
||||
if (!record) throw notFoundError("Branch");
|
||||
|
||||
return record;
|
||||
}
|
||||
|
|
@ -540,7 +540,7 @@ export class BranchController extends Controller {
|
|||
where: { id: branchId },
|
||||
});
|
||||
|
||||
if (!record) return throwNotFound("Branch");
|
||||
if (!record) throw notFoundError("Branch");
|
||||
|
||||
await permissionCheck(req.user, record);
|
||||
|
||||
|
|
@ -589,7 +589,7 @@ export class BranchFileController extends Controller {
|
|||
include: branchRelationPermInclude(user),
|
||||
where: { id },
|
||||
});
|
||||
if (!data) return throwNotFound("Branch");
|
||||
if (!data) throw notFoundError("Branch");
|
||||
await permissionCheck(user, data);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import {
|
|||
createPermCondition,
|
||||
} from "../services/permission";
|
||||
import { connectOrDisconnect, connectOrNot } from "../utils/relation";
|
||||
import { throwNotFound, throwRelationError } from "../utils/error";
|
||||
import { notFoundError, relationError } from "../utils/error";
|
||||
import { deleteFile, fileLocation, getFile, listFile, setFile } from "../utils/minio";
|
||||
|
||||
if (!process.env.MINIO_BUCKET) {
|
||||
|
|
@ -357,7 +357,7 @@ export class EmployeeController extends Controller {
|
|||
where: { id: employeeId },
|
||||
});
|
||||
|
||||
if (!record) return throwNotFound("Employee");
|
||||
if (!record) throw notFoundError("Employee");
|
||||
|
||||
return record;
|
||||
}
|
||||
|
|
@ -382,10 +382,10 @@ export class EmployeeController extends Controller {
|
|||
},
|
||||
}),
|
||||
]);
|
||||
if (body.provinceId !== province?.id) return throwRelationError("Province");
|
||||
if (body.districtId !== district?.id) return throwRelationError("District");
|
||||
if (body.subDistrictId !== subDistrict?.id) return throwRelationError("Sub-district");
|
||||
if (!customerBranch) return throwRelationError("Customer Branch");
|
||||
if (body.provinceId !== province?.id) throw relationError("Province");
|
||||
if (body.districtId !== district?.id) throw relationError("District");
|
||||
if (body.subDistrictId !== subDistrict?.id) throw relationError("Sub-district");
|
||||
if (!customerBranch) throw relationError("Customer Branch");
|
||||
|
||||
await permissionCheck(req.user, customerBranch.customer.registeredBranch);
|
||||
|
||||
|
|
@ -541,10 +541,10 @@ export class EmployeeController extends Controller {
|
|||
}),
|
||||
]);
|
||||
|
||||
if (body.provinceId && !province) return throwRelationError("Province");
|
||||
if (body.districtId && !district) return throwRelationError("District");
|
||||
if (body.subDistrictId && !subDistrict) return throwRelationError("SubDistrict");
|
||||
if (body.customerBranchId && !customerBranch) return throwRelationError("Customer");
|
||||
if (body.provinceId && !province) throw relationError("Province");
|
||||
if (body.districtId && !district) throw relationError("District");
|
||||
if (body.subDistrictId && !subDistrict) throw relationError("SubDistrict");
|
||||
if (body.customerBranchId && !customerBranch) throw relationError("Customer");
|
||||
if (!employee) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "Employee cannot be found.", "employeeNotFound");
|
||||
}
|
||||
|
|
@ -735,7 +735,7 @@ export class EmployeeController extends Controller {
|
|||
},
|
||||
});
|
||||
|
||||
if (!record) return throwNotFound("Employee");
|
||||
if (!record) throw notFoundError("Employee");
|
||||
|
||||
await permissionCheck(req.user, record.customerBranch.customer.registeredBranch);
|
||||
|
||||
|
|
@ -783,7 +783,7 @@ export class EmployeeFileController extends Controller {
|
|||
},
|
||||
},
|
||||
});
|
||||
if (!data) return throwNotFound("Employee");
|
||||
if (!data) throw notFoundError("Employee");
|
||||
await permissionCheck(user, data.customerBranch.customer.registeredBranch);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import {
|
|||
createPermCondition,
|
||||
} from "../services/permission";
|
||||
import { filterStatus } from "../services/prisma";
|
||||
import { throwRelationError } from "../utils/error";
|
||||
import { relationError } from "../utils/error";
|
||||
import { deleteFile, fileLocation, getFile, listFile, setFile } from "../utils/minio";
|
||||
|
||||
const MANAGE_ROLES = [
|
||||
|
|
@ -253,7 +253,7 @@ export class ServiceController extends Controller {
|
|||
}),
|
||||
]);
|
||||
|
||||
if (!productGroup) return throwRelationError("Product Type");
|
||||
if (!productGroup) throw relationError("Product Type");
|
||||
|
||||
await permissionCheck(req.user, productGroup.registeredBranch);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
|
||||
export function throwRelationError(name: string) {
|
||||
throw new HttpError(
|
||||
export function relationError(name: string) {
|
||||
return new HttpError(
|
||||
HttpStatus.BAD_REQUEST,
|
||||
`${name} cannot be found.`,
|
||||
`relation${name.replaceAll(" ", "")}NotFound`,
|
||||
);
|
||||
}
|
||||
|
||||
export function throwNotFound(name: string) {
|
||||
throw new HttpError(
|
||||
export function notFoundError(name: string) {
|
||||
return new HttpError(
|
||||
HttpStatus.BAD_REQUEST,
|
||||
`${name} cannot be found.`,
|
||||
`${name.charAt(0).toLowerCase() + name.replaceAll(" ", "").slice(1)}NotFound`,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue