let client view notifications
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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] },
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -120,6 +120,7 @@ export const rules: Record<
|
||||
"org:read",
|
||||
"rts:read",
|
||||
"rts:write",
|
||||
"notification:read",
|
||||
"view:read",
|
||||
"view:write",
|
||||
"view:delete",
|
||||
|
||||
Reference in New Issue
Block a user