add notes to payments, unique values route

This commit is contained in:
2025-06-12 18:34:45 +05:30
parent 7c60ef5ca0
commit 8c490b513b
2 changed files with 32 additions and 1 deletions

View File

@@ -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);
}

View File

@@ -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(