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

112 lines
2.7 KiB
TypeScript
Raw Normal View History

import { z } from "zod/v4";
2025-08-28 18:27:07 +02:00
import type { AnnunciUpdate } from "~/schemas/public/Annunci";
2025-08-04 17:45:44 +02:00
import {
2025-08-28 18:27:07 +02:00
adminProcedure,
createTRPCRouter,
protectedProcedure,
publicProcedure,
2025-08-04 17:45:44 +02:00
} from "~/server/api/trpc";
import {
2025-08-28 18:27:07 +02:00
editAnnuncioHandler,
get_AnnunciPositionsHandler,
getAnnunciByCod,
getAnnunciById_rawImgUrls,
2025-08-28 18:27:07 +02:00
getAnnunciListHandler,
getAnnunciMetaByCod,
getAnnunciRicerca,
2025-08-28 18:27:07 +02:00
getCodici_AnnunciHandler,
getOptions_AnnunciHandler,
getProprietarioDataHandler,
2025-08-04 17:45:44 +02:00
} from "~/server/controllers/annunci.controller";
import { zAnnuncioId, zServizioId } from "~/server/utils/zod_types";
export const annunciRouter = createTRPCRouter({
2025-08-29 16:18:32 +02:00
editAnnuncio: adminProcedure
.input(
z.object({ annuncioId: zAnnuncioId, data: z.custom<AnnunciUpdate>() }),
)
.mutation(async ({ input }) => {
return await editAnnuncioHandler({
...input,
});
}),
2025-08-28 18:27:07 +02:00
getAnnunciList: publicProcedure.query(async () => {
return await getAnnunciListHandler();
}),
2025-08-29 16:18:32 +02:00
getAnnunciOptions: publicProcedure.query(async () => {
return await getOptions_AnnunciHandler();
2025-08-28 18:27:07 +02:00
}),
getAnnuncio: publicProcedure
.input(
z.object({
cod: z.string(),
}),
)
.query(async ({ input }) => {
return await getAnnunciByCod({ ...input });
}),
getAnnuncioById_rawImgUrls: publicProcedure
2025-08-28 18:27:07 +02:00
.input(
z.object({
id: zAnnuncioId,
}),
)
.query(async ({ input }) => {
return await getAnnunciById_rawImgUrls({ ...input });
2025-08-28 18:27:07 +02:00
}),
2025-08-29 16:18:32 +02:00
getAnnuncioMeta: publicProcedure
2025-08-28 18:27:07 +02:00
.input(
z.object({
2025-08-29 16:18:32 +02:00
cod: z.string(),
2025-08-28 18:27:07 +02:00
}),
)
.query(async ({ input }) => {
2025-08-29 16:18:32 +02:00
return await getAnnunciMetaByCod({ ...input });
2025-08-28 18:27:07 +02:00
}),
2025-08-29 16:18:32 +02:00
getCodici: publicProcedure.query(async () => {
return await getCodici_AnnunciHandler();
}),
2025-08-28 18:27:07 +02:00
getMapping: publicProcedure
.input(
z.object({
comune: z.string().optional(),
consegna: z.number().array().optional(),
2025-08-29 16:18:32 +02:00
tipologia: z.string().optional(),
minBudget: z.number().optional(),
maxBudget: z.number().optional(),
2025-08-28 18:27:07 +02:00
}),
)
.query(async ({ input }) => {
return await get_AnnunciPositionsHandler({
...input,
});
}),
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
getProprietarioData: protectedProcedure
.input(z.object({ annuncioId: zAnnuncioId, servizioId: zServizioId }))
.query(async ({ input }) => {
return await getProprietarioDataHandler({
annuncioId: input.annuncioId,
servizioId: input.servizioId,
});
}),
annunciRicerca: publicProcedure
2025-08-29 16:18:32 +02:00
.input(
z.object({
comune: z.string().optional(),
consegna: z.number().array().optional(),
2025-08-29 16:18:32 +02:00
sort: z.enum(["Recenti", "Prezzo", "Consegna", "Mq"]).optional(),
tipologia: z.string().optional(),
minBudget: z.number().optional(),
maxBudget: z.number().optional(),
2025-08-29 16:18:32 +02:00
}),
)
.query(async ({ input }) => {
return await getAnnunciRicerca({
2025-08-29 16:18:32 +02:00
...input,
});
}),
2025-08-04 17:45:44 +02:00
});