fix: customer branch code

This commit is contained in:
puriphat 2024-06-14 05:58:14 +00:00
parent 5cc0f1c659
commit d97b1260cf
2 changed files with 26 additions and 26 deletions

View file

@ -211,7 +211,7 @@ export class CustomerController extends Controller {
where: { id: customerId },
});
if (!record)
throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "data_not_found");
throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "customerNotFound");
return Object.assign(record, {
imageUrl: await presignedGetObjectIfExist(
MINIO_BUCKET,
@ -249,21 +249,21 @@ export class CustomerController extends Controller {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Some province cannot be found.",
"missing_or_invalid_parameter",
"relationProvinceNotFound",
);
}
if (districtId && district.length !== districtId?.length) {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Some district cannot be found.",
"missing_or_invalid_parameter",
"relationDistrictNotFound",
);
}
if (subDistrictId && subDistrict.length !== subDistrictId?.length) {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Some sub district cannot be found.",
"missing_or_invalid_parameter",
"relationSubDistrictNotFound",
);
}
@ -338,7 +338,7 @@ export class CustomerController extends Controller {
const customer = await prisma.customer.findUnique({ where: { id: customerId } });
if (!customer) {
throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "data_not_found");
throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "customerNotFound");
}
const provinceId = body.customerBranch?.reduce<string[]>((acc, cur) => {
@ -365,21 +365,21 @@ export class CustomerController extends Controller {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Some province cannot be found.",
"missing_or_invalid_parameter",
"relationProvinceNotFound",
);
}
if (districtId && district.length !== districtId?.length) {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Some district cannot be found.",
"missing_or_invalid_parameter",
"relationDistrictNotFound",
);
}
if (subDistrictId && subDistrict.length !== subDistrictId?.length) {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Some sub district cannot be found.",
"missing_or_invalid_parameter",
"relationSubDistrictNotFound",
);
}
@ -398,7 +398,7 @@ export class CustomerController extends Controller {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"One or more branch cannot be delete and is missing.",
"missing_or_invalid_parameter",
"oneOrMoreBranchMissing",
);
}
@ -490,11 +490,11 @@ export class CustomerController extends Controller {
const record = await prisma.customer.findFirst({ where: { id: customerId } });
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "data_not_found");
throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "customerNotFound");
}
if (record.status !== Status.CREATED) {
throw new HttpError(HttpStatus.FORBIDDEN, "Customer is in used.", "data_in_used");
throw new HttpError(HttpStatus.FORBIDDEN, "Customer is in used.", "customerInUsed");
}
return await prisma.customer.delete({ where: { id: customerId } }).then((v) => {