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 };
|
||||
});
|
||||
|
||||
onWorkflowChange({ ...workflow, steps: updatedSteps });
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { sessionOptions } from "@/lib/session";
|
||||
import { requestUser } from "@/utils/api";
|
||||
import { updateConfiguredWorkflow } from "@/utils/approval.workflows.be";
|
||||
import { withIronSessionApiRoute } from "iron-session/next";
|
||||
import { ObjectId } from "mongodb";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
@@ -24,6 +25,7 @@ async function put(req: NextApiRequest, res: NextApiResponse) {
|
||||
const approvalWorkflow: ApprovalWorkflow = req.body;
|
||||
|
||||
if (id && approvalWorkflow) {
|
||||
approvalWorkflow._id = new ObjectId(id);
|
||||
await updateConfiguredWorkflow(approvalWorkflow);
|
||||
return res.status(204).end();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { sessionOptions } from "@/lib/session";
|
||||
import { requestUser } from "@/utils/api";
|
||||
import { deleteConfiguredWorkflow, updateConfiguredWorkflow } from "@/utils/approval.workflows.be";
|
||||
import { withIronSessionApiRoute } from "iron-session/next";
|
||||
import { ObjectId } from "mongodb";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
@@ -35,9 +36,10 @@ async function put(req: NextApiRequest, res: NextApiResponse) {
|
||||
}
|
||||
|
||||
const { id } = req.query as { id?: string };
|
||||
const workflow = req.body;
|
||||
const workflow: ApprovalWorkflow = req.body;
|
||||
|
||||
if (id && workflow) {
|
||||
workflow._id = new ObjectId(id);
|
||||
await updateConfiguredWorkflow(workflow);
|
||||
return res.status(204).end();
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ export default function Home({ user, workflow, workflowEntityApprovers }: Props)
|
||||
completed: step.completed,
|
||||
completedBy: step.completedBy || undefined,
|
||||
completedDate: step.completedDate || undefined,
|
||||
assignees: step.assignees.map(id => id),
|
||||
assignees: step.assignees,
|
||||
firstStep: step.firstStep || false,
|
||||
finalStep: step.finalStep || false,
|
||||
onDelete: undefined,
|
||||
@@ -98,7 +98,6 @@ export default function Home({ user, workflow, workflowEntityApprovers }: Props)
|
||||
...updatedWorkflow,
|
||||
steps: updatedWorkflow.steps.map(step => ({
|
||||
...step,
|
||||
completed: false,
|
||||
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) => {
|
||||
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[]) => {
|
||||
|
||||
Reference in New Issue
Block a user