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

108 lines
2.6 KiB
TypeScript

import { z } from "zod/v4";
import type { AnnunciUpdate } from "~/schemas/public/Annunci";
import {
adminProcedure,
createTRPCRouter,
protectedProcedure,
publicProcedure,
} from "~/server/api/trpc";
import {
editAnnuncioHandler,
get_AnnunciPositionsHandler,
getAnnunciByCod,
getAnnunciById,
getAnnunciListHandler,
getAnnunciMetaByCod,
getCodici_AnnunciHandler,
getCursor_AnnunciHandler,
getOptions_AnnunciHandler,
getProprietarioDataHandler,
} from "~/server/controllers/annunci.controller";
import { zAnnuncioId, zServizioId } from "~/server/utils/zod_types";
export const annunciRouter = createTRPCRouter({
getAnnunciList: publicProcedure.query(async () => {
return await getAnnunciListHandler();
}),
getCodici: publicProcedure.query(async () => {
return await getCodici_AnnunciHandler();
}),
getAnnuncio: publicProcedure
.input(
z.object({
cod: z.string(),
}),
)
.query(async ({ input }) => {
return await getAnnunciByCod({ ...input });
}),
getAnnuncioMeta: publicProcedure
.input(
z.object({
cod: z.string(),
}),
)
.query(async ({ input }) => {
return await getAnnunciMetaByCod({ ...input });
}),
getAnnuncioByIdForEdit: publicProcedure
.input(
z.object({
id: zAnnuncioId,
}),
)
.query(async ({ input }) => {
return await getAnnunciById({ ...input });
}),
getWithCursor: publicProcedure
.input(
z.object({
page: z.number().optional(),
pageSize: z.number(),
tipologia: z.string().optional(),
comune: z.string().optional(),
consegna: z.number().optional(),
sort: z.enum(["Recenti", "Prezzo", "Consegna", "Mq"]).optional(),
}),
)
.query(async ({ input }) => {
return await getCursor_AnnunciHandler({
...input,
});
}),
getMapping: publicProcedure
.input(
z.object({
tipologia: z.string().optional(),
comune: z.string().optional(),
consegna: z.number().optional(),
}),
)
.query(async ({ input }) => {
return await get_AnnunciPositionsHandler({
...input,
});
}),
getAnnunciOptions: publicProcedure.query(async () => {
return await getOptions_AnnunciHandler();
}),
editAnnuncio: adminProcedure
.input(
z.object({ annuncioId: zAnnuncioId, data: z.custom<AnnunciUpdate>() }),
)
.mutation(async ({ input }) => {
return await editAnnuncioHandler({
...input,
});
}),
getProprietarioData: protectedProcedure
.input(z.object({ annuncioId: zAnnuncioId, servizioId: zServizioId }))
.query(async ({ input }) => {
return await getProprietarioDataHandler({
annuncioId: input.annuncioId,
servizioId: input.servizioId,
});
}),
});