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

@@ -32,10 +32,7 @@ export async function listNotificationsHandler(
const queryParams = req.query as PageQueryParams;
try {
const notificationList = await listNotifications(
queryParams,
req.user.tenantId
);
const notificationList = await listNotifications(queryParams, req.user);
return res.code(200).send(notificationList);
} catch (err) {
return err;

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] },
},
];

View File

@@ -120,6 +120,7 @@ export const rules: Record<
"org:read",
"rts:read",
"rts:write",
"notification:read",
"view:read",
"view:write",
"view:delete",