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; const queryParams = req.query as PageQueryParams;
try { try {
const notificationList = await listNotifications( const notificationList = await listNotifications(queryParams, req.user);
queryParams,
req.user.tenantId
);
return res.code(200).send(notificationList); return res.code(200).send(notificationList);
} catch (err) { } catch (err) {
return err; return err;

View File

@@ -1,3 +1,5 @@
import mongoose from "mongoose";
import { AuthenticatedUser } from "../auth";
import { orgModel } from "../organization/organization.schema"; import { orgModel } from "../organization/organization.schema";
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination"; import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
import { userModel } from "../user/user.schema"; import { userModel } from "../user/user.schema";
@@ -44,16 +46,20 @@ export async function updateNotification(
export async function listNotifications( export async function listNotifications(
params: PageQueryParams, params: PageQueryParams,
tenantId: string user: AuthenticatedUser
) { ) {
const page = params.page || 1; const page = params.page || 1;
const pageSize = params.pageSize || 10; const pageSize = params.pageSize || 10;
const sortObj = getSortObject(params, notificationFields); const sortObj = getSortObject(params, notificationFields);
const filterObj = getFilterObject(params) || []; const filterObj = getFilterObject(params) || [];
if (user.role == "client") {
filterObj.push({ client: new mongoose.Types.ObjectId(user.orgId) });
}
const pipeline: any = [ 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", "org:read",
"rts:read", "rts:read",
"rts:write", "rts:write",
"notification:read",
"view:read", "view:read",
"view:write", "view:write",
"view:delete", "view:delete",