filter workflows user can see based on entities

This commit is contained in:
Joao Correia
2025-02-08 19:23:42 +00:00
parent cbe353c2c5
commit 3a3d3d014d
4 changed files with 27 additions and 15 deletions

View File

@@ -4,11 +4,18 @@ import { ObjectId } from "mongodb";
const db = client.db(process.env.MONGODB_DB);
export const getApprovalWorkflows = async (collection: string, ids?: string[]) => {
return await db
.collection<ApprovalWorkflow>(collection)
.find(ids ? { _id: { $in: ids.map((id) => new ObjectId(id)) } } : {})
.toArray();
export const getApprovalWorkflows = async (collection: string, entityIds?: string[], ids?: string[]) => {
const filters: any = {};
if (ids && ids.length > 0) {
filters.id = { $in: ids };
}
if (entityIds && entityIds.length > 0) {
filters.entityId = { $in: entityIds };
}
return await db.collection<ApprovalWorkflow>(collection).find(filters).toArray();
};
export const getApprovalWorkflow = async (collection: string, id: string) => {