add assignedTo field to unique fields endpoint
This commit is contained in:
@@ -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