fix: branch code

This commit is contained in:
puriphat 2024-06-14 05:44:03 +00:00
parent c978d3adec
commit 5cc0f1c659
3 changed files with 24 additions and 24 deletions

View file

@ -62,7 +62,7 @@ export class BranchContactController extends Controller {
throw new HttpError(
HttpStatus.NOT_FOUND,
"Branch contact cannot be found.",
"data_not_found",
"branchContactNotFound",
);
}
@ -78,8 +78,8 @@ export class BranchContactController extends Controller {
if (!(await prisma.branch.findFirst({ where: { id: branchId } }))) {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Branch not found.",
"missing_or_invalid_parameter",
"Branch cannot be found.",
"branchBadReq",
);
}
const record = await prisma.branchContact.create({
@ -106,7 +106,7 @@ export class BranchContactController extends Controller {
throw new HttpError(
HttpStatus.NOT_FOUND,
"Branch contact cannot be found.",
"data_not_found",
"branchContactNotFound",
);
}
@ -125,7 +125,7 @@ export class BranchContactController extends Controller {
throw new HttpError(
HttpStatus.NOT_FOUND,
"Branch contact cannot be found.",
"data_not_found",
"branchContactNotFound",
);
}
}

View file

@ -208,7 +208,7 @@ export class BranchController extends Controller {
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "data_not_found");
throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "branchNotFound");
}
return Object.assign(record, {
@ -229,25 +229,25 @@ export class BranchController extends Controller {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Province cannot be found.",
"missing_or_invalid_parameter",
"relationProvinceNotFound",
);
if (body.districtId && !district)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"District cannot be found.",
"missing_or_invalid_parameter",
"relationDistrictNotFound",
);
if (body.subDistrictId && !subDistrict)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Sub-district cannot be found.",
"missing_or_invalid_parameter",
"relationSubDistrictNotFound",
);
if (body.headOfficeId && !head)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Head branch cannot be found.",
"missing_or_invalid_parameter",
"Headquaters cannot be found.",
"relationHQNotFound",
);
const { provinceId, districtId, subDistrictId, headOfficeId, contact, ...rest } = body;
@ -337,8 +337,8 @@ export class BranchController extends Controller {
if (body.headOfficeId === branchId)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Cannot make this as head office and branch at the same time.",
"missing_or_invalid_parameter",
"Cannot make this as headquaters and branch at the same time.",
"cantMakeHQAndBranchSameTime",
);
if (body.subDistrictId || body.districtId || body.provinceId || body.headOfficeId) {
@ -352,32 +352,32 @@ export class BranchController extends Controller {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Province cannot be found.",
"missing_or_invalid_parameter",
"relationProvinceNotFound",
);
if (body.districtId && !district)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"District cannot be found.",
"missing_or_invalid_parameter",
"relationDistrictNotFound",
);
if (body.subDistrictId && !subDistrict)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Sub-district cannot be found.",
"missing_or_invalid_parameter",
"relationSubDistrictNotFound",
);
if (body.headOfficeId && !branch)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Head branch cannot be found.",
"missing_or_invalid_parameter",
"Headquaters cannot be found.",
"relationHQNotFound",
);
}
const { provinceId, districtId, subDistrictId, headOfficeId, contact, ...rest } = body;
if (!(await prisma.branch.findUnique({ where: { id: branchId } }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "data_not_found");
throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "branchNotFound");
}
const record = await prisma.branch.update({
@ -445,11 +445,11 @@ export class BranchController extends Controller {
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "data_not_found");
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.", "data_in_used");
throw new HttpError(HttpStatus.FORBIDDEN, "Branch is in used.", "branchInUsed");
}
await minio.removeObject(MINIO_BUCKET, lineImageLoc(branchId), {

View file

@ -116,7 +116,7 @@ export class BranchUserController extends Controller {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Branch cannot be found.",
"missing_or_invalid_parameter",
"branchBadReq",
);
}
@ -124,7 +124,7 @@ export class BranchUserController extends Controller {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"One or more user cannot be found.",
"missing_or_invalid_parameter",
"oneOrMoreUserBadReq",
);
}
@ -234,7 +234,7 @@ export class UserBranchController extends Controller {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"One or more branch cannot be found.",
"missing_or_invalid_parameter",
"oneOrMoreBranchBadReq",
);
}