feat: must not delete if status is not CREATED
This commit is contained in:
parent
c3f8673ac8
commit
23f05503c5
1 changed files with 13 additions and 1 deletions
|
|
@ -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
|
const record = await prisma.customer
|
||||||
.update({
|
.update({
|
||||||
include: {
|
include: {
|
||||||
|
|
@ -391,6 +402,7 @@ export class CustomerController extends Controller {
|
||||||
id: {
|
id: {
|
||||||
notIn: customerBranch.map((v) => v.id).filter((v): v is string => !!v) || [],
|
notIn: customerBranch.map((v) => v.id).filter((v): v is string => !!v) || [],
|
||||||
},
|
},
|
||||||
|
status: Status.CREATED,
|
||||||
},
|
},
|
||||||
upsert: customerBranch.map((v, i) => ({
|
upsert: customerBranch.map((v, i) => ({
|
||||||
where: { id: v.id || "" },
|
where: { id: v.id || "" },
|
||||||
|
|
@ -415,7 +427,7 @@ export class CustomerController extends Controller {
|
||||||
.then((v) => {
|
.then((v) => {
|
||||||
if (customerBranch) {
|
if (customerBranch) {
|
||||||
relation
|
relation
|
||||||
.filter((a) => !customerBranch?.find((b) => b.id === a.id))
|
.filter((a) => !customerBranch.find((b) => b.id === a.id))
|
||||||
.forEach((deleted) => {
|
.forEach((deleted) => {
|
||||||
new Promise<string[]>((resolve, reject) => {
|
new Promise<string[]>((resolve, reject) => {
|
||||||
const item: string[] = [];
|
const item: string[] = [];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue