refactor: reduce code
This commit is contained in:
parent
b9a616b9a9
commit
20725b0357
1 changed files with 8 additions and 14 deletions
|
|
@ -378,25 +378,19 @@ export class BranchController extends Controller {
|
||||||
update: { value: { increment: 1 } },
|
update: { value: { increment: 1 } },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const errorBranchExists = new HttpError(
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
"Branch with same code already exists.",
|
||||||
|
"sameBranchCodeExists",
|
||||||
|
);
|
||||||
|
|
||||||
if (last.value === 1) {
|
if (last.value === 1) {
|
||||||
const exist = await tx.branch.findFirst({
|
const exist = await tx.branch.findFirst({
|
||||||
where: { code: `${code?.toLocaleUpperCase()}${`${last.value - 1}`.padStart(5, "0")}` },
|
where: { code: `${code?.toLocaleUpperCase()}${`${last.value - 1}`.padStart(5, "0")}` },
|
||||||
});
|
});
|
||||||
if (exist)
|
if (exist) throw errorBranchExists;
|
||||||
throw new HttpError(
|
|
||||||
HttpStatus.BAD_REQUEST,
|
|
||||||
"Branch with same code already exists.",
|
|
||||||
"sameBranchCodeExists",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (last.value !== 1 && !headOfficeId) {
|
|
||||||
throw new HttpError(
|
|
||||||
HttpStatus.BAD_REQUEST,
|
|
||||||
"Branch with same code already exists.",
|
|
||||||
"sameBranchCodeExists",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
if (last.value !== 1 && !headOfficeId) throw errorBranchExists;
|
||||||
|
|
||||||
return await tx.branch.create({
|
return await tx.branch.create({
|
||||||
include: {
|
include: {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue