update role claims, refactor getUniqueValues
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
updateTaskHandler,
|
||||
} from "./task.controller";
|
||||
import { noteRoutes } from "../note/note.route";
|
||||
import { getUniqueValuesTasks } from "./task.service";
|
||||
import { getUniqueFields } from "../unique";
|
||||
|
||||
export async function taskRoutes(fastify: FastifyInstance) {
|
||||
fastify.post(
|
||||
@@ -126,10 +126,7 @@ export async function taskRoutes(fastify: FastifyInstance) {
|
||||
const { field } = req.params as { field: string };
|
||||
|
||||
try {
|
||||
const uniqueValues = await getUniqueValuesTasks(
|
||||
field,
|
||||
req.user.tenantId
|
||||
);
|
||||
const uniqueValues = await getUniqueFields(field, "task", req.user);
|
||||
return res.code(200).send(uniqueValues);
|
||||
} catch (err) {
|
||||
return err;
|
||||
@@ -137,9 +134,5 @@ export async function taskRoutes(fastify: FastifyInstance) {
|
||||
}
|
||||
);
|
||||
|
||||
await noteRoutes(fastify, {
|
||||
read: "task:read",
|
||||
write: "task:write",
|
||||
delete: "task:delete",
|
||||
});
|
||||
await noteRoutes(fastify);
|
||||
}
|
||||
|
||||
@@ -251,28 +251,3 @@ export async function newUpload(
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function getUniqueValuesTasks(field: string, tenenatId: string) {
|
||||
let values = await taskModel.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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user