fix: customer branch code
This commit is contained in:
parent
5cc0f1c659
commit
d97b1260cf
2 changed files with 26 additions and 26 deletions
|
|
@ -182,7 +182,7 @@ export class CustomerBranchController 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 record;
|
||||
|
|
@ -250,25 +250,25 @@ export class CustomerBranchController 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 (!customer)
|
||||
throw new HttpError(
|
||||
HttpStatus.BAD_REQUEST,
|
||||
"Customer cannot be found.",
|
||||
"missing_or_invalid_parameter",
|
||||
"relationCustomerNotFound",
|
||||
);
|
||||
|
||||
const { provinceId, districtId, subDistrictId, customerId, ...rest } = body;
|
||||
|
|
@ -328,32 +328,32 @@ export class CustomerBranchController 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.customerId && !customer)
|
||||
throw new HttpError(
|
||||
HttpStatus.BAD_REQUEST,
|
||||
"Customer cannot be found.",
|
||||
"missing_or_invalid_parameter",
|
||||
"relationCustomerNotFound",
|
||||
);
|
||||
}
|
||||
|
||||
const { provinceId, districtId, subDistrictId, customerId, ...rest } = body;
|
||||
|
||||
if (!(await prisma.customerBranch.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.customerBranch.update({
|
||||
|
|
@ -398,12 +398,12 @@ export class CustomerBranchController extends Controller {
|
|||
throw new HttpError(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"Customer branch cannot be found.",
|
||||
"data_not_found",
|
||||
"customerBranchNotFound",
|
||||
);
|
||||
}
|
||||
|
||||
if (record.status !== Status.CREATED) {
|
||||
throw new HttpError(HttpStatus.FORBIDDEN, "Customer branch is in used.", "data_in_used");
|
||||
throw new HttpError(HttpStatus.FORBIDDEN, "Customer branch is in used.", "customerBranchInUsed");
|
||||
}
|
||||
|
||||
return await prisma.customerBranch.delete({ where: { id: branchId } }).then((v) => {
|
||||
|
|
@ -444,7 +444,7 @@ export class CustomerAttachmentController extends Controller {
|
|||
throw new HttpError(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"Customer branch cannot be found.",
|
||||
"data_not_found",
|
||||
"customerBranchNotFound",
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -479,7 +479,7 @@ export class CustomerAttachmentController extends Controller {
|
|||
throw new HttpError(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"Customer branch cannot be found.",
|
||||
"data_not_found",
|
||||
"customerBranchNotFound",
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -509,7 +509,7 @@ export class CustomerAttachmentController extends Controller {
|
|||
throw new HttpError(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"Customer branch cannot be found.",
|
||||
"data_not_found",
|
||||
"customerBranchNotFound",
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue