add assignedTo field to unique fields endpoint
This commit is contained in:
@@ -152,7 +152,7 @@ export async function getUniqueValuesNotification(
|
||||
} else if (field === "client") {
|
||||
matchedValues = await orgModel.find().where("_id").in(values).exec();
|
||||
} else if (field === "assignedTo") {
|
||||
matchedValues = await userModel.find().where("name").in(values).exec();
|
||||
matchedValues = await userModel.find().where("_id").in(values).exec();
|
||||
}
|
||||
|
||||
if (matchedValues.length > 0) {
|
||||
|
||||
@@ -334,7 +334,7 @@ export async function getUniqueValuesPermit(field: string, tenenatId: string) {
|
||||
} else if (field === "client") {
|
||||
matchedValues = await orgModel.find().where("_id").in(values).exec();
|
||||
} else if (field === "assignedTo") {
|
||||
matchedValues = await userModel.find().where("name").in(values).exec();
|
||||
matchedValues = await userModel.find().where("_id").in(values).exec();
|
||||
}
|
||||
|
||||
if (matchedValues.length > 0) {
|
||||
|
||||
@@ -168,7 +168,7 @@ export async function getUniqueValuesProcessed(
|
||||
} else if (field === "client") {
|
||||
matchedValues = await orgModel.find().where("_id").in(values).exec();
|
||||
} else if (field === "assignedTo") {
|
||||
matchedValues = await userModel.find().where("name").in(values).exec();
|
||||
matchedValues = await userModel.find().where("_id").in(values).exec();
|
||||
}
|
||||
|
||||
if (matchedValues.length > 0) {
|
||||
|
||||
@@ -181,7 +181,8 @@ export async function updateRts(
|
||||
.findOneAndUpdate({ pid: id, tenantId: tenantId }, input, { new: true })
|
||||
.populate({ path: "createdBy", select: "pid name avatar" })
|
||||
.populate({ path: "county", select: "pid name avatar" })
|
||||
.populate({ path: "client", select: "pid name avatar" });
|
||||
.populate({ path: "client", select: "pid name avatar" })
|
||||
.populate({ path: "assignedTo", select: "pid name avatar" });
|
||||
|
||||
return updatedRts;
|
||||
}
|
||||
@@ -219,6 +220,8 @@ export async function getUniqueValuesRTS(field: string, tenenatId: string) {
|
||||
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) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
updateTaskHandler,
|
||||
} from "./task.controller";
|
||||
import { noteRoutes } from "../note/note.route";
|
||||
import { getUniqueValuesTasks } from "./task.service";
|
||||
|
||||
export async function taskRoutes(fastify: FastifyInstance) {
|
||||
fastify.post(
|
||||
@@ -107,6 +108,35 @@ export async function taskRoutes(fastify: FastifyInstance) {
|
||||
newFilesHandler
|
||||
);
|
||||
|
||||
fastify.get(
|
||||
"/fields/:field",
|
||||
{
|
||||
schema: {
|
||||
params: {
|
||||
type: "object",
|
||||
properties: {
|
||||
field: { type: "string" },
|
||||
},
|
||||
},
|
||||
},
|
||||
config: { requiredClaims: ["rts:read"] },
|
||||
preHandler: [fastify.authorize],
|
||||
},
|
||||
async (req, res) => {
|
||||
const { field } = req.params as { field: string };
|
||||
|
||||
try {
|
||||
const uniqueValues = await getUniqueValuesTasks(
|
||||
field,
|
||||
req.user.tenantId
|
||||
);
|
||||
return res.code(200).send(uniqueValues);
|
||||
} catch (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
await noteRoutes(fastify, {
|
||||
read: "task:read",
|
||||
write: "task:write",
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { userInfo } from "os";
|
||||
import { AuthenticatedUser } from "../auth";
|
||||
import { orgModel } from "../organization/organization.schema";
|
||||
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
|
||||
import { generateId } from "../utils/id";
|
||||
import { taskPipeline } from "../utils/pipeline";
|
||||
@@ -9,6 +11,7 @@ import {
|
||||
UpdateTaskInput,
|
||||
UploadTaskInput,
|
||||
} from "./task.schema";
|
||||
import { userModel } from "../user/user.schema";
|
||||
|
||||
export async function createTask(
|
||||
input: CreateTaskInput,
|
||||
@@ -248,3 +251,28 @@ 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