update role claims, refactor getUniqueValues
This commit is contained in:
@@ -6,8 +6,8 @@ import {
|
||||
listNotificationsHandler,
|
||||
updateNotificationHandler,
|
||||
} from "./notification.controller";
|
||||
import { getUniqueValuesNotification } from "./notification.service";
|
||||
import { noteRoutes } from "../note/note.route";
|
||||
import { getUniqueFields } from "../unique";
|
||||
|
||||
export async function notificationRoutes(fastify: FastifyInstance) {
|
||||
fastify.post(
|
||||
@@ -95,9 +95,10 @@ export async function notificationRoutes(fastify: FastifyInstance) {
|
||||
const { field } = req.params as { field: string };
|
||||
|
||||
try {
|
||||
const uniqueValues = await getUniqueValuesNotification(
|
||||
const uniqueValues = await getUniqueFields(
|
||||
field,
|
||||
req.user.tenantId
|
||||
"notifications",
|
||||
req.user
|
||||
);
|
||||
return res.code(200).send(uniqueValues);
|
||||
} catch (err) {
|
||||
@@ -106,9 +107,5 @@ export async function notificationRoutes(fastify: FastifyInstance) {
|
||||
}
|
||||
);
|
||||
|
||||
await noteRoutes(fastify, {
|
||||
read: "rts:read",
|
||||
write: "rts:write",
|
||||
delete: "rts:delete",
|
||||
});
|
||||
await noteRoutes(fastify);
|
||||
}
|
||||
|
||||
@@ -139,29 +139,3 @@ export async function deleteNotification(notifId: string, tenantId: string) {
|
||||
$and: [{ tenantId: tenantId }, { pid: notifId }],
|
||||
});
|
||||
}
|
||||
|
||||
export async function getUniqueValuesNotification(
|
||||
field: string,
|
||||
tenenatId: string
|
||||
) {
|
||||
let values = await notificationModel.distinct(field, { tenantId: tenenatId });
|
||||
|
||||
let matchedValues = [];
|
||||
if (field === "county.name") {
|
||||
matchedValues = await orgModel.find().where("name").in(values).exec();
|
||||
} else if (field === "client") {
|
||||
matchedValues = await orgModel.find().where("_id").in(values).exec();
|
||||
} else if (field === "assignedTo") {
|
||||
matchedValues = await userModel.find().where("_id").in(values).exec();
|
||||
}
|
||||
|
||||
if (matchedValues.length > 0) {
|
||||
const newValues = {};
|
||||
for (const item of matchedValues) {
|
||||
newValues[item.id] = item.name;
|
||||
}
|
||||
return newValues;
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user