Fix id handling on update
This commit is contained in:
@@ -72,7 +72,6 @@ export default function WorkflowForm({ workflow, onWorkflowChange, entityApprove
|
|||||||
|
|
||||||
return { ...step, assignees: newAssignees };
|
return { ...step, assignees: newAssignees };
|
||||||
});
|
});
|
||||||
|
|
||||||
onWorkflowChange({ ...workflow, steps: updatedSteps });
|
onWorkflowChange({ ...workflow, steps: updatedSteps });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { sessionOptions } from "@/lib/session";
|
|||||||
import { requestUser } from "@/utils/api";
|
import { requestUser } from "@/utils/api";
|
||||||
import { updateConfiguredWorkflow } from "@/utils/approval.workflows.be";
|
import { updateConfiguredWorkflow } from "@/utils/approval.workflows.be";
|
||||||
import { withIronSessionApiRoute } from "iron-session/next";
|
import { withIronSessionApiRoute } from "iron-session/next";
|
||||||
|
import { ObjectId } from "mongodb";
|
||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
|
||||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||||
@@ -24,6 +25,7 @@ async function put(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
const approvalWorkflow: ApprovalWorkflow = req.body;
|
const approvalWorkflow: ApprovalWorkflow = req.body;
|
||||||
|
|
||||||
if (id && approvalWorkflow) {
|
if (id && approvalWorkflow) {
|
||||||
|
approvalWorkflow._id = new ObjectId(id);
|
||||||
await updateConfiguredWorkflow(approvalWorkflow);
|
await updateConfiguredWorkflow(approvalWorkflow);
|
||||||
return res.status(204).end();
|
return res.status(204).end();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { sessionOptions } from "@/lib/session";
|
|||||||
import { requestUser } from "@/utils/api";
|
import { requestUser } from "@/utils/api";
|
||||||
import { deleteConfiguredWorkflow, updateConfiguredWorkflow } from "@/utils/approval.workflows.be";
|
import { deleteConfiguredWorkflow, updateConfiguredWorkflow } from "@/utils/approval.workflows.be";
|
||||||
import { withIronSessionApiRoute } from "iron-session/next";
|
import { withIronSessionApiRoute } from "iron-session/next";
|
||||||
|
import { ObjectId } from "mongodb";
|
||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
|
||||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||||
@@ -35,9 +36,10 @@ async function put(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { id } = req.query as { id?: string };
|
const { id } = req.query as { id?: string };
|
||||||
const workflow = req.body;
|
const workflow: ApprovalWorkflow = req.body;
|
||||||
|
|
||||||
if (id && workflow) {
|
if (id && workflow) {
|
||||||
|
workflow._id = new ObjectId(id);
|
||||||
await updateConfiguredWorkflow(workflow);
|
await updateConfiguredWorkflow(workflow);
|
||||||
return res.status(204).end();
|
return res.status(204).end();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export default function Home({ user, workflow, workflowEntityApprovers }: Props)
|
|||||||
completed: step.completed,
|
completed: step.completed,
|
||||||
completedBy: step.completedBy || undefined,
|
completedBy: step.completedBy || undefined,
|
||||||
completedDate: step.completedDate || undefined,
|
completedDate: step.completedDate || undefined,
|
||||||
assignees: step.assignees.map(id => id),
|
assignees: step.assignees,
|
||||||
firstStep: step.firstStep || false,
|
firstStep: step.firstStep || false,
|
||||||
finalStep: step.finalStep || false,
|
finalStep: step.finalStep || false,
|
||||||
onDelete: undefined,
|
onDelete: undefined,
|
||||||
@@ -98,7 +98,6 @@ export default function Home({ user, workflow, workflowEntityApprovers }: Props)
|
|||||||
...updatedWorkflow,
|
...updatedWorkflow,
|
||||||
steps: updatedWorkflow.steps.map(step => ({
|
steps: updatedWorkflow.steps.map(step => ({
|
||||||
...step,
|
...step,
|
||||||
completed: false,
|
|
||||||
assignees: step.assignees.filter((assignee): assignee is string => assignee !== null && assignee !== undefined)
|
assignees: step.assignees.filter((assignee): assignee is string => assignee !== null && assignee !== undefined)
|
||||||
}))
|
}))
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export const createConfiguredWorkflows = async (workflows: ApprovalWorkflow[]) =
|
|||||||
|
|
||||||
export const updateConfiguredWorkflow = async (workflow: ApprovalWorkflow) => {
|
export const updateConfiguredWorkflow = async (workflow: ApprovalWorkflow) => {
|
||||||
const { _id, ...workflowWithoutId } = workflow as ApprovalWorkflow;
|
const { _id, ...workflowWithoutId } = workflow as ApprovalWorkflow;
|
||||||
return await db.collection("configured-workflows").replaceOne({ _id: new ObjectId(_id) }, workflowWithoutId);
|
return await db.collection("configured-workflows").replaceOne({ _id: _id }, workflowWithoutId);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateConfiguredWorkflows = async (workflows: ApprovalWorkflow[]) => {
|
export const updateConfiguredWorkflows = async (workflows: ApprovalWorkflow[]) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user