let client view notifications

This commit is contained in:
2025-05-16 17:55:43 +05:30
parent a16bd408c2
commit 23c18c4875
3 changed files with 10 additions and 6 deletions

View File

@@ -1,3 +1,5 @@
import mongoose from "mongoose";
import { AuthenticatedUser } from "../auth";
import { orgModel } from "../organization/organization.schema";
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
import { userModel } from "../user/user.schema";
@@ -44,16 +46,20 @@ export async function updateNotification(
export async function listNotifications(
params: PageQueryParams,
tenantId: string
user: AuthenticatedUser
) {
const page = params.page || 1;
const pageSize = params.pageSize || 10;
const sortObj = getSortObject(params, notificationFields);
const filterObj = getFilterObject(params) || [];
if (user.role == "client") {
filterObj.push({ client: new mongoose.Types.ObjectId(user.orgId) });
}
const pipeline: any = [
{
$match: { $and: [{ tenantId: tenantId }, ...filterObj] },
$match: { $and: [{ tenantId: user.tenantId }, ...filterObj] },
},
];