feat: must not delete if status is not CREATED

This commit is contained in:
Methapon2001 2024-06-07 14:34:34 +07:00
parent c3f8673ac8
commit 23f05503c5

View file

@ -371,6 +371,17 @@ export class CustomerController extends Controller {
},
});
if (
customerBranch &&
relation.find((a) => !customerBranch.find((b) => a.id === b.id) && a.status !== "CREATED")
) {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"One or more branch cannot be delete and is missing.",
"missing_or_invalid_parameter",
);
}
const record = await prisma.customer
.update({
include: {
@ -391,6 +402,7 @@ export class CustomerController extends Controller {
id: {
notIn: customerBranch.map((v) => v.id).filter((v): v is string => !!v) || [],
},
status: Status.CREATED,
},
upsert: customerBranch.map((v, i) => ({
where: { id: v.id || "" },
@ -415,7 +427,7 @@ export class CustomerController extends Controller {
.then((v) => {
if (customerBranch) {
relation
.filter((a) => !customerBranch?.find((b) => b.id === a.id))
.filter((a) => !customerBranch.find((b) => b.id === a.id))
.forEach((deleted) => {
new Promise<string[]>((resolve, reject) => {
const item: string[] = [];