infoalloggi-monorepo/apps/infoalloggi/src/server/api/routers/pagamenti.ts
2025-08-04 17:45:44 +02:00

33 lines
966 B
TypeScript

import { TRPCError } from "@trpc/server";
import { z } from "zod";
import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc";
import { db } from "~/server/db";
// Create a new ratelimiter, that allows 10 requests per 10 seconds
/*
const ratelimit = new RateLimiterHandler({
maxRequests: 10,
windowSize: 60,
analytics: false,
});
*/
export const pagamentiRouter = createTRPCRouter({
getPaymentFromIntent: protectedProcedure
.input(z.object({ pIntentId: z.string() }))
.query(async ({ input }) => {
try {
return (
(await db
.selectFrom("payments")
.selectAll("payments")
.where("payments.intent_id", "=", input.pIntentId)
.executeTakeFirst()) || null
);
} catch (error) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Error retriving payment: " + (error as Error).message,
});
}
}),
});