infoalloggi-monorepo/apps/infoalloggi/src/server/api/routers/pagamenti.ts

34 lines
898 B
TypeScript
Raw Normal View History

2025-08-04 17:45:44 +02:00
import { TRPCError } from "@trpc/server";
import { z } from "zod/v4";
2025-08-04 17:45:44 +02:00
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({
2025-08-28 18:27:07 +02:00
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}`,
});
}
}),
2025-08-04 17:45:44 +02:00
});