Start implementing with back-end. Create workflows completed and fetching workflows on server side as well, to show them in the table.

This commit is contained in:
Joao Correia
2025-01-29 17:50:03 +00:00
parent 42a8ec2f8a
commit 011c6e9e30
6 changed files with 82 additions and 18 deletions

View File

@@ -3,6 +3,22 @@ import client from "@/lib/mongodb";
const db = client.db(process.env.MONGODB_DB);
export const getApprovalWorkflows = async (ids?: string[]) => {
return await db
.collection("approval-workflows")
.find<ApprovalWorkflow>(ids ? { id: { $in: ids } } : {})
.toArray();
};
export const getApprovalWorkflow = async (id: string) => {
return await db.collection("approval-workflows").findOne<ApprovalWorkflow>({ id });
};
export const createApprovalWorkflow = async (workflow: ApprovalWorkflow) => {
await db.collection("approval-workflows").insertOne(workflow);
}
export const createApprovalWorkflows = async (workflows: ApprovalWorkflow[]) => {
if (workflows.length === 0) return;
await db.collection<ApprovalWorkflow>("approval-workflows").insertMany(workflows);
};