unique values route for processed permits

This commit is contained in:
2025-03-13 14:47:25 +05:30
parent bcab406908
commit 9d6bd67383
2 changed files with 61 additions and 1 deletions

View File

@@ -1,6 +1,9 @@
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import { PageQueryParams } from "../pagination";
import { listProcessedPermits } from "./processed.service";
import {
getUniqueValuesProcessed,
listProcessedPermits,
} from "./processed.service";
import { $processed } from "./processed.schema";
export async function processedRoutes(fastify: FastifyInstance) {
@@ -24,4 +27,33 @@ export async function processedRoutes(fastify: FastifyInstance) {
}
}
);
fastify.get(
"/fields/:field",
{
schema: {
params: {
type: "object",
properties: {
field: { type: "string" },
},
},
},
config: { requiredClaims: ["permit:read"] },
preHandler: [fastify.authorize],
},
async (req: FastifyRequest, res: FastifyReply) => {
const { field } = req.params as { field: string };
try {
const uniqueValues = await getUniqueValuesProcessed(
field,
req.user.tenantId
);
return res.code(200).send(uniqueValues);
} catch (err) {
return err;
}
}
);
}