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

@@ -2,12 +2,12 @@ import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import { PageQueryParams } from "../pagination";
import {
getProcessedPermit,
getUniqueValuesProcessed,
listProcessedPermits,
updateProcessed,
} from "./processed.service";
import { $processed, UpdateProcessedInput } from "./processed.schema";
import { noteRoutes } from "../note/note.route";
import { getUniqueFields } from "../unique";
export async function processedRoutes(fastify: FastifyInstance) {
fastify.get(
@@ -120,9 +120,10 @@ export async function processedRoutes(fastify: FastifyInstance) {
const { field } = req.params as { field: string };
try {
const uniqueValues = await getUniqueValuesProcessed(
const uniqueValues = await getUniqueFields(
field,
req.user.tenantId
"processed",
req.user
);
return res.code(200).send(uniqueValues);
} catch (err) {
@@ -131,9 +132,5 @@ export async function processedRoutes(fastify: FastifyInstance) {
}
);
await noteRoutes(fastify, {
read: "permit:read",
write: "permit:write",
delete: "permit:delete",
});
await noteRoutes(fastify);
}

View File

@@ -155,29 +155,3 @@ export async function listProcessedPermits(
},
};
}
export async function getUniqueValuesProcessed(
field: string,
tenenatId: string
) {
let values = await processedModel.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;
}