diff --git a/src/controllers/customer-controller.ts b/src/controllers/customer-controller.ts index 9319525..03dfa38 100644 --- a/src/controllers/customer-controller.ts +++ b/src/controllers/customer-controller.ts @@ -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((resolve, reject) => { const item: string[] = [];