From 8c490b513bd6170c5d6ad27f12b67caead0bee60 Mon Sep 17 00:00:00 2001 From: Akhil Meka Date: Thu, 12 Jun 2025 18:34:45 +0530 Subject: [PATCH] add notes to payments, unique values route --- src/payments/payment.route.ts | 28 ++++++++++++++++++++++++++++ src/unique.ts | 5 ++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/payments/payment.route.ts b/src/payments/payment.route.ts index f4e5be6..d1d639a 100644 --- a/src/payments/payment.route.ts +++ b/src/payments/payment.route.ts @@ -1,6 +1,8 @@ import { FastifyInstance } from "fastify"; import { getPaymentHandler, listPaymentHandler } from "./payment.controller"; import { $payment } from "./payment.schema"; +import { getUniqueFields } from "../unique"; +import { noteRoutes } from "../note/note.route"; export async function paymentRoutes(fastify: FastifyInstance) { fastify.get( @@ -43,4 +45,30 @@ export async function paymentRoutes(fastify: FastifyInstance) { }, listPaymentHandler ); + + fastify.get( + "/fields/:field", + { + schema: { + params: { + type: "object", + properties: { field: { type: "string" } }, + }, + }, + config: { requiredClaims: ["payment:read"] }, + preHandler: [fastify.authorize], + }, + async (req, res) => { + const { field } = req.params as { field: string }; + + try { + const uniqueValues = await getUniqueFields(field, "payment", req.user); + return res.code(200).send(uniqueValues); + } catch (err) { + return err; + } + } + ); + + await noteRoutes(fastify); } diff --git a/src/unique.ts b/src/unique.ts index c5f5a8d..a06bd11 100644 --- a/src/unique.ts +++ b/src/unique.ts @@ -6,6 +6,7 @@ import { notificationModel } from "./notification/notification.schema"; import { rtsModel } from "./rts/rts.schema"; import { taskModel } from "./task/task.schema"; import { AuthenticatedUser } from "./auth"; +import { paymentModel } from "./payments/payment.schema"; type Collection = | "users" @@ -14,7 +15,8 @@ type Collection = | "processed" | "notifications" | "rts" - | "task"; + | "task" + | "payment"; const modelMap = { users: userModel, @@ -24,6 +26,7 @@ const modelMap = { notifications: notificationModel, rts: rtsModel, task: taskModel, + payment: paymentModel, }; export async function getUniqueFields(