diff --git a/src/pages/api/approval-workflows/index.ts b/src/pages/api/approval-workflows/index.ts index a2cd2ea4..91c1417d 100644 --- a/src/pages/api/approval-workflows/index.ts +++ b/src/pages/api/approval-workflows/index.ts @@ -23,5 +23,10 @@ async function get(req: NextApiRequest, res: NextApiResponse) { const entityIdsArray = entityIdsString.split(","); - return res.status(200).json(await getApprovalWorkflows("active-workflows", entityIdsArray)); + if (!["admin", "developer"].includes(user.type)) { + // filtering workflows that have user as assignee in at least one of the steps + return res.status(200).json(await getApprovalWorkflows("active-workflows", entityIdsArray, undefined, user.id)); + } else { + return res.status(200).json(await getApprovalWorkflows("active-workflows", entityIdsArray)); + } } diff --git a/src/utils/approval.workflows.be.ts b/src/utils/approval.workflows.be.ts index 9998a06e..833c5b06 100644 --- a/src/utils/approval.workflows.be.ts +++ b/src/utils/approval.workflows.be.ts @@ -4,7 +4,7 @@ import { ObjectId } from "mongodb"; const db = client.db(process.env.MONGODB_DB); -export const getApprovalWorkflows = async (collection: string, entityIds?: string[], ids?: string[]) => { +export const getApprovalWorkflows = async (collection: string, entityIds?: string[], ids?: string[], assignee?: string) => { const filters: any = {}; if (ids && ids.length > 0) { @@ -15,6 +15,10 @@ export const getApprovalWorkflows = async (collection: string, entityIds?: strin filters.entityId = { $in: entityIds }; } + if (assignee) { + filters["steps.assignees"] = assignee; + } + return await db.collection(collection).find(filters).toArray(); };