Fix id handling on update

This commit is contained in:
Joao Correia
2025-02-01 23:14:17 +00:00
parent ac539332e6
commit b684262759
5 changed files with 7 additions and 5 deletions

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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)
}))
};