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