diff --git a/src/file/file.service.ts b/src/file/file.service.ts index c746eee..f629c8e 100644 --- a/src/file/file.service.ts +++ b/src/file/file.service.ts @@ -107,7 +107,6 @@ async function getAllDescendents(folderId: string, tenantId: string) { await traverseFolder(folderId); - console.log(idArr); return idArr; } diff --git a/src/notification/notification.route.ts b/src/notification/notification.route.ts index b32b578..a180a88 100644 --- a/src/notification/notification.route.ts +++ b/src/notification/notification.route.ts @@ -57,13 +57,25 @@ export async function notificationRoutes(fastify: FastifyInstance) { }, }, }, - config: { requiredClaims: ["notification:delete"] }, preHandler: [fastify.authorize], }, deleteNotificationHandler ); + fastify.get( + "/search", + { + schema: { + querystring: $notification("pageQueryParams"), + }, + + config: { requiredClaims: ["notification:delete"] }, + preHandler: [fastify.authorize], + }, + listNotificationsHandler + ); + fastify.get( "/fields/:field", { diff --git a/src/processed/processed.route.ts b/src/processed/processed.route.ts index 35de4af..7ec4763 100644 --- a/src/processed/processed.route.ts +++ b/src/processed/processed.route.ts @@ -29,6 +29,27 @@ export async function processedRoutes(fastify: FastifyInstance) { } ); + fastify.get( + "/search", + { + schema: { + querystring: $processed("pageQueryParams"), + }, + config: { requiredClaims: ["permit:read"] }, + preHandler: [fastify.authorize], + }, + async (req: FastifyRequest, res: FastifyReply) => { + const params = req.query as PageQueryParams; + + try { + const permits = await listProcessedPermits(params, req.user.tenantId); + return res.code(200).send(permits); + } catch (err) { + return err; + } + } + ); + fastify.get( "/:permitId", { diff --git a/src/rts/rts.route.ts b/src/rts/rts.route.ts index 0fc9bbd..aec6359 100644 --- a/src/rts/rts.route.ts +++ b/src/rts/rts.route.ts @@ -10,6 +10,7 @@ import { } from "./rts.controller"; import { hideFields } from "../auth"; import { noteRoutes } from "../note/note.route"; +import { getUniqueValuesRTS } from "./rts.service"; export async function rtsRoutes(fastify: FastifyInstance) { fastify.post( @@ -95,6 +96,32 @@ export async function rtsRoutes(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 getUniqueValuesRTS(field, req.user.tenantId); + return res.code(200).send(uniqueValues); + } catch (err) { + return err; + } + } + ); + await noteRoutes(fastify, { read: "rts:read", write: "rts:write", diff --git a/src/rts/rts.service.ts b/src/rts/rts.service.ts index de44bed..7d0674a 100644 --- a/src/rts/rts.service.ts +++ b/src/rts/rts.service.ts @@ -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; +}