add /search endpoints

This commit is contained in:
2025-04-26 09:55:47 +05:30
parent e93c2cde96
commit cf569edfe6
5 changed files with 86 additions and 2 deletions

View File

@@ -9,6 +9,8 @@ import { AuthenticatedUser } from "../auth";
import { generateId } from "../utils/id";
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
import { getUser } from "../user/user.service";
import { orgModel } from "../organization/organization.schema";
import { userModel } from "../user/user.schema";
export async function createRts(
input: CreateRtsInput,
@@ -195,3 +197,26 @@ export async function newUpload(
}
);
}
export async function getUniqueValuesRTS(field: string, tenenatId: string) {
let values = await rtsModel.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("name").in(values).exec();
}
if (matchedValues.length > 0) {
const newValues = {};
for (const item of matchedValues) {
newValues[item.id] = item.name;
}
return newValues;
}
return values;
}