feat: update now detect already exists step
This commit is contained in:
parent
af37ac850c
commit
6be298acfb
1 changed files with 27 additions and 9 deletions
|
|
@ -28,6 +28,7 @@ import { filterStatus } from "../services/prisma";
|
||||||
type WorkflowPayload = {
|
type WorkflowPayload = {
|
||||||
name: string;
|
name: string;
|
||||||
step: {
|
step: {
|
||||||
|
id?: string;
|
||||||
name: string;
|
name: string;
|
||||||
type?: string;
|
type?: string;
|
||||||
value?: string[];
|
value?: string[];
|
||||||
|
|
@ -176,16 +177,33 @@ export class FlowTemplateController extends Controller {
|
||||||
...body,
|
...body,
|
||||||
statusOrder: +(body.status === "INACTIVE"),
|
statusOrder: +(body.status === "INACTIVE"),
|
||||||
step: {
|
step: {
|
||||||
deleteMany: {},
|
deleteMany: {
|
||||||
create: body.step.map((v, i) => ({
|
id: { notIn: body.step.flatMap((v) => v.id || []) },
|
||||||
type: v.type,
|
},
|
||||||
name: v.name,
|
upsert: body.step.map((v, i) => ({
|
||||||
order: i + 1,
|
where: { id: v.id || "" },
|
||||||
value: {
|
create: {
|
||||||
create: v.value?.map((val) => ({ value: val })),
|
type: v.type,
|
||||||
|
name: v.name,
|
||||||
|
order: i + 1,
|
||||||
|
value: {
|
||||||
|
create: v.value?.map((val) => ({ value: val })),
|
||||||
|
},
|
||||||
|
responsiblePerson: {
|
||||||
|
create: v.responsiblePersonId?.map((id) => ({ userId: id })),
|
||||||
|
},
|
||||||
|
id: undefined,
|
||||||
},
|
},
|
||||||
responsiblePerson: {
|
update: {
|
||||||
create: v.responsiblePersonId?.map((id) => ({ userId: id })),
|
type: v.type,
|
||||||
|
name: v.name,
|
||||||
|
order: i + 1,
|
||||||
|
value: {
|
||||||
|
create: v.value?.map((val) => ({ value: val })),
|
||||||
|
},
|
||||||
|
responsiblePerson: {
|
||||||
|
create: v.responsiblePersonId?.map((id) => ({ userId: id })),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue