update role claims, refactor getUniqueValues

This commit is contained in:
2025-05-16 17:25:39 +05:30
parent 4028c05d5f
commit c73d57410a
15 changed files with 114 additions and 191 deletions

View File

@@ -10,7 +10,7 @@ import {
} from "./rts.controller";
import { hideFields } from "../auth";
import { noteRoutes } from "../note/note.route";
import { getUniqueValuesRTS } from "./rts.service";
import { getUniqueFields } from "../unique";
export async function rtsRoutes(fastify: FastifyInstance) {
fastify.post(
@@ -114,7 +114,7 @@ export async function rtsRoutes(fastify: FastifyInstance) {
const { field } = req.params as { field: string };
try {
const uniqueValues = await getUniqueValuesRTS(field, req.user.tenantId);
const uniqueValues = await getUniqueFields(field, "rts", req.user);
return res.code(200).send(uniqueValues);
} catch (err) {
return err;
@@ -122,11 +122,7 @@ export async function rtsRoutes(fastify: FastifyInstance) {
}
);
await noteRoutes(fastify, {
read: "rts:read",
write: "rts:write",
delete: "rts:delete",
});
await noteRoutes(fastify);
fastify.addHook("onSend", hideFields("rts"));
}

View File

@@ -209,28 +209,3 @@ export async function newUpload(
}
);
}
export async function getUniqueValuesRTS(field: string, tenenatId: string) {
let values = await rtsModel.distinct(field, { tenantId: tenenatId });
let matchedValues = [];
if (field === "county") {
matchedValues = await orgModel.find().where("_id").in(values).exec();
} else if (field === "client") {
matchedValues = await orgModel.find().where("_id").in(values).exec();
} else if (field === "createdBy") {
matchedValues = await userModel.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;
}