2025-08-07 14:50:40 +02:00
|
|
|
import { z } from "zod/v4";
|
2025-08-04 17:45:44 +02:00
|
|
|
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
|
|
|
|
|
import { NewMail } from "~/server/services/mailer";
|
|
|
|
|
// Create a new ratelimiter, that allows 10 requests per 10 seconds
|
|
|
|
|
/*
|
|
|
|
|
const ratelimit = new RateLimiterHandler({
|
|
|
|
|
windowSize: 10,
|
|
|
|
|
maxRequests: 10,
|
|
|
|
|
analytics: true,
|
|
|
|
|
});
|
|
|
|
|
*/
|
|
|
|
|
export const contactRouter = createTRPCRouter({
|
2025-08-28 18:27:07 +02:00
|
|
|
postContact: publicProcedure
|
|
|
|
|
.input(
|
|
|
|
|
z.object({
|
|
|
|
|
cognome: z.string(),
|
|
|
|
|
email: z.email(),
|
|
|
|
|
messaggio: z.string(),
|
2025-08-29 16:18:32 +02:00
|
|
|
nome: z.string(),
|
|
|
|
|
telefono: z.string(),
|
2025-08-28 18:27:07 +02:00
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
.mutation(async ({ input }) => {
|
|
|
|
|
await NewMail({
|
2025-11-19 17:18:28 +01:00
|
|
|
template: {
|
|
|
|
|
mailType: "contattoAdminEmail",
|
|
|
|
|
props: {
|
|
|
|
|
cognome: input.cognome,
|
|
|
|
|
email: input.email,
|
|
|
|
|
messaggio: input.messaggio,
|
|
|
|
|
nome: input.nome,
|
|
|
|
|
telefono: input.telefono,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
mail: {
|
|
|
|
|
subject: `Richiesta di contatto da ${input.nome}`,
|
|
|
|
|
to: "web@infoalloggi.it",
|
2025-08-28 18:27:07 +02:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return { success: true };
|
|
|
|
|
}),
|
2025-08-04 17:45:44 +02:00
|
|
|
});
|