diff --git a/apps/infoalloggi/src/forms/FormContattoAnnuncio.tsx b/apps/infoalloggi/src/forms/FormContattoAnnuncio.tsx index 4d9cb33..df6fb4a 100644 --- a/apps/infoalloggi/src/forms/FormContattoAnnuncio.tsx +++ b/apps/infoalloggi/src/forms/FormContattoAnnuncio.tsx @@ -54,7 +54,7 @@ export const FormContattoAnnucio = ({ codice }: { codice: string }) => { }, }); - const { mutate } = api.servizio.sendContattoEmail.useMutation({ + const { mutate } = api.comunicazioni.sendContattoAnnuncioEmail.useMutation({ onError: (error) => { console.error(error); toast.error("Errore durante l'invio dell'email", { diff --git a/apps/infoalloggi/src/pages/auth/password-reset/[token].tsx b/apps/infoalloggi/src/pages/auth/password-reset/[token].tsx index 1449947..855e870 100644 --- a/apps/infoalloggi/src/pages/auth/password-reset/[token].tsx +++ b/apps/infoalloggi/src/pages/auth/password-reset/[token].tsx @@ -21,7 +21,7 @@ const ResetWToken: NextPageWithLayout = ({
-
+

{t.pwReset.titolo} diff --git a/apps/infoalloggi/src/pages/contatti.tsx b/apps/infoalloggi/src/pages/contatti.tsx index 27e14cf..d7fe027 100644 --- a/apps/infoalloggi/src/pages/contatti.tsx +++ b/apps/infoalloggi/src/pages/contatti.tsx @@ -46,12 +46,13 @@ const Contatto: NextPage = () => { }, }); - const { mutate: contactMutation } = api.contact.postContact.useMutation({ - onSuccess: () => { - setHasSent(true); - form.reset(); - }, - }); + const { mutate: contactMutation } = + api.comunicazioni.sendEmailContatto.useMutation({ + onSuccess: () => { + setHasSent(true); + form.reset(); + }, + }); const onSubmit = (data: z.infer) => { contactMutation({ cognome: data.cognome, diff --git a/apps/infoalloggi/src/server/api/root.ts b/apps/infoalloggi/src/server/api/root.ts index 447295e..1b32003 100644 --- a/apps/infoalloggi/src/server/api/root.ts +++ b/apps/infoalloggi/src/server/api/root.ts @@ -4,7 +4,6 @@ import { banlistRouter } from "~/server/api/routers/banlist"; import { chatRouter } from "~/server/api/routers/chat"; import { chatSSERouter } from "~/server/api/routers/chat_sse"; import { comunicazioniRouter } from "~/server/api/routers/comunicazioni"; -import { contactRouter } from "~/server/api/routers/contact"; import { eventQueueRouter } from "~/server/api/routers/event_queue"; import { fattureRouter } from "~/server/api/routers/fatture"; import { intrestsRouter } from "~/server/api/routers/interests"; @@ -27,7 +26,6 @@ import { inviteRouter } from "./routers/invite"; import { potenzialiRouter } from "./routers/potenziali"; import { revalidationRouter } from "./routers/revalidation"; import { stringsRouter } from "./routers/strings"; -import { syncRouter } from "./routers/sync"; //import { lazy } from '@trpc/server'; @@ -38,7 +36,6 @@ export const appRouter = createTRPCRouter({ chat: chatRouter, chatSSE: chatSSERouter, comunicazioni: comunicazioniRouter, - contact: contactRouter, eventQueue: eventQueueRouter, fatture: fattureRouter, intrests: intrestsRouter, @@ -51,7 +48,7 @@ export const appRouter = createTRPCRouter({ stripe: stripeRouter, test: testRouter, users: usersRouter, - sync: syncRouter, + //sync: syncRouter, catasto: catastoRouter, banners: bannersRouter, flags: flagsRouter, diff --git a/apps/infoalloggi/src/server/api/routers/annunci.ts b/apps/infoalloggi/src/server/api/routers/annunci.ts index 4139e39..a0897e0 100644 --- a/apps/infoalloggi/src/server/api/routers/annunci.ts +++ b/apps/infoalloggi/src/server/api/routers/annunci.ts @@ -17,7 +17,6 @@ import { getAnnunciMetaByCod, getAnnunciRicerca, getCodici_AnnunciHandler, - getOnline_AnnuncioIdCodice_AnnunciHandler, getOptions_AnnunciHandler, getProprietarioDataHandler, type ImgToRemove, @@ -53,9 +52,7 @@ export const annunciRouter = createTRPCRouter({ getAnnunciOptions: publicProcedure.query(async () => { return await getOptions_AnnunciHandler(); }), - getOnline_AnnuncioIdCodice: publicProcedure.query(async () => { - return await getOnline_AnnuncioIdCodice_AnnunciHandler(); - }), + getAnnuncio: publicProcedure .input( z.object({ @@ -128,6 +125,7 @@ export const annunciRouter = createTRPCRouter({ ...input, }); }), + /**Used for cron job */ checkAnnunci: apiProcedure.query(async () => { const hasAnnunci = await db .selectFrom("annunci") diff --git a/apps/infoalloggi/src/server/api/routers/auth.ts b/apps/infoalloggi/src/server/api/routers/auth.ts index e111b61..cfc8938 100644 --- a/apps/infoalloggi/src/server/api/routers/auth.ts +++ b/apps/infoalloggi/src/server/api/routers/auth.ts @@ -18,7 +18,6 @@ import { isTokenValid, passwordOverrideHandler, pwResetSendLinkHandler, - pwResetTokenFromMailHandler, resetPasswordFromTokenHandler, } from "~/server/services/auth.service"; import { zUserId } from "~/server/utils/zod_types"; @@ -105,13 +104,7 @@ export const authRouter = createTRPCRouter({ .mutation(async ({ input }) => { return await passwordOverrideHandler({ ...input }); }), - pwResetGenTokenMail: publicProcedure - .input(z.object({ email: z.string() })) - .mutation(async ({ input }) => { - return await pwResetTokenFromMailHandler({ - email: input.email, - }); - }), + resetPasswordFromToken: publicProcedure .input( z.object({ diff --git a/apps/infoalloggi/src/server/api/routers/catasto.ts b/apps/infoalloggi/src/server/api/routers/catasto.ts index 60c294c..e7b0c1e 100644 --- a/apps/infoalloggi/src/server/api/routers/catasto.ts +++ b/apps/infoalloggi/src/server/api/routers/catasto.ts @@ -1,16 +1,12 @@ import z from "zod"; import { createTRPCRouter, publicProcedure } from "~/server/api/trpc"; import { - getComuneById, getComuni, - getNazioneById, getNazioni, getProvincie, searchComuniByCatasto, } from "~/server/controllers/catasto.controller"; -import { zComuneId, zNazioneId } from "~/server/utils/zod_types"; - export const catastoRouter = createTRPCRouter({ getComuni: publicProcedure.query(async () => { return await getComuni(); @@ -24,28 +20,11 @@ export const catastoRouter = createTRPCRouter({ .query(async ({ input }) => { return await searchComuniByCatasto(input.catasto); }), - getComuneById: publicProcedure - .input( - z.object({ - id: zComuneId, - }), - ) - .query(async ({ input }) => { - return await getComuneById(input.id); - }), + getProvincie: publicProcedure.query(async () => { return await getProvincie(); }), getNazioni: publicProcedure.query(async () => { return await getNazioni(); }), - getNazioneById: publicProcedure - .input( - z.object({ - id: zNazioneId, - }), - ) - .query(async ({ input }) => { - return await getNazioneById(input.id); - }), }); diff --git a/apps/infoalloggi/src/server/api/routers/chat_sse.ts b/apps/infoalloggi/src/server/api/routers/chat_sse.ts index 726032c..715e715 100644 --- a/apps/infoalloggi/src/server/api/routers/chat_sse.ts +++ b/apps/infoalloggi/src/server/api/routers/chat_sse.ts @@ -1,10 +1,6 @@ import { TRPCError, tracked } from "@trpc/server"; import { z } from "zod/v4"; -import { - createTRPCRouter, - protectedProcedure, - publicProcedure, -} from "~/server/api/trpc"; +import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc"; import { addTyping, getCurrentlyTyping, @@ -16,7 +12,6 @@ import { add } from "~/server/services/chat.service"; import { ee, type OnlineStatus } from "~/server/sse"; import { zChatId, zUserId } from "~/server/utils/zod_types"; import { getKeydbClient } from "~/utils/keydb"; -import { getMessagesArray } from "~/utils/kysely-helper"; //IDEA forse cambiare in semplice interval polling invece di sse export const chatSSERouter = createTRPCRouter({ create: protectedProcedure @@ -94,20 +89,20 @@ export const chatSSERouter = createTRPCRouter({ }); return parsedUsers; }), - list: publicProcedure.query(async () => { - return await db - .selectFrom("chats") - .select([ - "chats.chatid", - "chats.created_at", - "chats.user_ref", - getMessagesArray(), - ]) - .innerJoin("users", "users.id", "chats.user_ref") - .select(["users.username", "users.email", "users.nome"]) - .orderBy("chats.created_at", "desc") - .execute(); - }), + // list: publicProcedure.query(async () => { + // return await db + // .selectFrom("chats") + // .select([ + // "chats.chatid", + // "chats.created_at", + // "chats.user_ref", + // getMessagesArray(), + // ]) + // .innerJoin("users", "users.id", "chats.user_ref") + // .select(["users.username", "users.email", "users.nome"]) + // .orderBy("chats.created_at", "desc") + // .execute(); + // }), onChatEvent: protectedProcedure .input( diff --git a/apps/infoalloggi/src/server/api/routers/comunicazioni.ts b/apps/infoalloggi/src/server/api/routers/comunicazioni.ts index 17a0c0d..78ec7e1 100644 --- a/apps/infoalloggi/src/server/api/routers/comunicazioni.ts +++ b/apps/infoalloggi/src/server/api/routers/comunicazioni.ts @@ -4,7 +4,9 @@ import { adminProcedure, createTRPCRouter, protectedProcedure, + publicProcedure, } from "~/server/api/trpc"; +import { SendContattoAnnuncioEmail } from "~/server/controllers/servizio.controller"; import { db } from "~/server/db"; import { deleteAllUserEmails, @@ -16,17 +18,6 @@ import { genPdfSchedaAnnuncioBase64 } from "~/server/services/puppeteer.service" import { zAnnuncioId, zUserId } from "~/server/utils/zod_types"; export const comunicazioniRouter = createTRPCRouter({ - // genEmail: publicProcedure - // .input( - // z.object({ - // mail: z.custom(), - // }), - // ) - // .query(async ({ input }) => { - // return await genMail({ - // ...input.mail, - // }); - // }), getEmails: protectedProcedure .input(z.object({ userId: zUserId })) .query(async ({ input }) => { @@ -52,6 +43,35 @@ export const comunicazioniRouter = createTRPCRouter({ userId: input.userId, }); }), + sendEmailContatto: publicProcedure + .input( + z.object({ + cognome: z.string(), + email: z.email(), + messaggio: z.string(), + nome: z.string(), + telefono: z.string(), + }), + ) + .mutation(async ({ input }) => { + await NewMail({ + 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", + }, + }); + return { success: true }; + }), sendSchedaAnnuncioEmail: adminProcedure .input( z.object({ @@ -172,45 +192,20 @@ export const comunicazioniRouter = createTRPCRouter({ ); } }), - sendAnnunciEmail: adminProcedure + + sendContattoAnnuncioEmail: publicProcedure .input( z.object({ - annunci: zAnnuncioId.array(), - to: z.email(), + codice: z.string(), + email: z.string(), + messaggio: z.string(), + nome: z.string(), + telefono: z.string(), }), ) .mutation(async ({ input }) => { - try { - const annunci = await db - .selectFrom("annunci") - .select([ - "annunci.titolo_it as titolo", - "annunci.codice", - "annunci.prezzo", - ]) - .innerJoin("images_refs", "images_refs.codice", "annunci.codice") - .select("images_refs.img as immagine") - .where("images_refs.ordine", "=", 0) - .where("annunci.id", "in", input.annunci) - .execute(); - - await NewMail({ - template: { - mailType: "shareAnnunci", - props: { - nome: "Admin", - annunci, - }, - }, - mail: { - subject: `Scheda Annuncio - Infoalloggi.it`, - to: input.to, - }, - }); - } catch (e) { - throw new Error( - `Errore nell'invio dell'email: ${(e as Error).message}`, - ); - } + return await SendContattoAnnuncioEmail({ + ...input, + }); }), }); diff --git a/apps/infoalloggi/src/server/api/routers/contact.ts b/apps/infoalloggi/src/server/api/routers/contact.ts deleted file mode 100644 index cd175af..0000000 --- a/apps/infoalloggi/src/server/api/routers/contact.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { z } from "zod/v4"; -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({ - postContact: publicProcedure - .input( - z.object({ - cognome: z.string(), - email: z.email(), - messaggio: z.string(), - nome: z.string(), - telefono: z.string(), - }), - ) - .mutation(async ({ input }) => { - await NewMail({ - 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", - }, - }); - return { success: true }; - }), -}); diff --git a/apps/infoalloggi/src/server/api/routers/event_queue.ts b/apps/infoalloggi/src/server/api/routers/event_queue.ts index 99fe462..3d13efd 100644 --- a/apps/infoalloggi/src/server/api/routers/event_queue.ts +++ b/apps/infoalloggi/src/server/api/routers/event_queue.ts @@ -1,26 +1,7 @@ -import { z } from "zod/v4"; -import { - apiProcedure, - createTRPCRouter, - publicProcedure, -} from "~/server/api/trpc"; -import { - addEventToQueue, - processEvents, -} from "~/server/controllers/event_queue.controller"; -import { zEventDataTypes } from "~/server/utils/zod_types"; +import { apiProcedure, createTRPCRouter } from "~/server/api/trpc"; +import { processEvents } from "~/server/controllers/event_queue.controller"; export const eventQueueRouter = createTRPCRouter({ - addEvent: publicProcedure - .input( - z.object({ - data: zEventDataTypes, - lock_expires: z.date(), - }), - ) - .mutation(async ({ input }) => { - return await addEventToQueue(input); - }), processEvents: apiProcedure.query(async () => { return await processEvents(); }), diff --git a/apps/infoalloggi/src/server/api/routers/fatture.ts b/apps/infoalloggi/src/server/api/routers/fatture.ts index 59e6cf3..cd96df4 100644 --- a/apps/infoalloggi/src/server/api/routers/fatture.ts +++ b/apps/infoalloggi/src/server/api/routers/fatture.ts @@ -1,30 +1,10 @@ import { z } from "zod/v4"; -import { - adminProcedure, - createTRPCRouter, - protectedProcedure, - publicProcedure, -} from "~/server/api/trpc"; -import { - addClient, - getClientFromCF, - getClientList, - searchClient, -} from "~/server/controllers/fic.controller"; -import { ClientSchema } from "~/server/services/fic.service"; +import { adminProcedure, createTRPCRouter } from "~/server/api/trpc"; +import { getClientFromCF } from "~/server/controllers/fic.controller"; export const fattureRouter = createTRPCRouter({ - createClient: protectedProcedure - .input( - z.object({ - client: ClientSchema, - }), - ) - .mutation(async ({ input }) => { - return await addClient(input.client); - }), - getClientFromCF: publicProcedure + getClientFromCF: adminProcedure .input( z.object({ cf: z.string(), @@ -33,16 +13,4 @@ export const fattureRouter = createTRPCRouter({ .query(async ({ input }) => { return await getClientFromCF(input.cf); }), - getListClienti: adminProcedure.query(async () => { - return await getClientList(); - }), - searchClient: adminProcedure - .input( - z.object({ - cognome: z.string(), - }), - ) - .query(async ({ input }) => { - return await searchClient(input.cognome); - }), }); diff --git a/apps/infoalloggi/src/server/api/routers/prezziario.ts b/apps/infoalloggi/src/server/api/routers/prezziario.ts index 37c2351..763038c 100644 --- a/apps/infoalloggi/src/server/api/routers/prezziario.ts +++ b/apps/infoalloggi/src/server/api/routers/prezziario.ts @@ -13,7 +13,6 @@ import { import { db } from "~/server/db"; import { addPrezziario, - deletePrezziario, getPrezziario, getPrezziarioByIdHandler, getPrezziarioByTipologia, @@ -39,18 +38,18 @@ export const prezziarioRouter = createTRPCRouter({ .mutation(async ({ input }) => { return await addPrezziario({ db, input: input.data }); }), - deletePrezziario: adminProcedure - .input( - z.object({ - idprezziario: zPrezziarioId, - }), - ) - .mutation(async ({ input }) => { - return await deletePrezziario({ - db, - prezziarioId: input.idprezziario, - }); - }), + // deletePrezziario: adminProcedure + // .input( + // z.object({ + // idprezziario: zPrezziarioId, + // }), + // ) + // .mutation(async ({ input }) => { + // return await deletePrezziario({ + // db, + // prezziarioId: input.idprezziario, + // }); + // }), getPrezziario: publicProcedure.query(async () => { return await getPrezziario(); }), diff --git a/apps/infoalloggi/src/server/api/routers/servizio.ts b/apps/infoalloggi/src/server/api/routers/servizio.ts index 1b6c6f2..5f07c97 100644 --- a/apps/infoalloggi/src/server/api/routers/servizio.ts +++ b/apps/infoalloggi/src/server/api/routers/servizio.ts @@ -10,7 +10,6 @@ import { createTRPCRouter, overridableProcedure, protectedProcedure, - publicProcedure, } from "~/server/api/trpc"; import { createOrdine, @@ -32,12 +31,10 @@ import { getDataPerAcquisto, getOrdineRicevutaData, getPacksPerServizio, - getPreOnboardData, getServiziByUserId, getServizioAnnuncio, getServizioById, getServizioDataById, - getServizioOrdini, getServizioPagamentoData, getUserPagamenti, InteractionLogicTipologia, @@ -46,7 +43,6 @@ import { postAcquistoDataHandler, removePagamento, SbloccaContatti, - SendContactEmail, setupSaldoConsulenzaServizio, setupSaldoServizio, updatePagamento, @@ -179,15 +175,6 @@ export const servizioRouter = createTRPCRouter({ .query(async ({ input }) => { return await getOrdineRicevutaData({ ordineId: input.ordineId }); }), - getServizioOrdini: protectedProcedure - .input( - z.object({ - servizioId: zServizioId, - }), - ) - .query(async ({ input }) => { - return await getServizioOrdini(input.servizioId); - }), getOrdini: protectedProcedure .input( @@ -198,15 +185,7 @@ export const servizioRouter = createTRPCRouter({ .query(async ({ input }) => { return await getOrdini(input.userId); }), - getPreOnboardData: publicProcedure - .input( - z.object({ - servizioId: zServizioId, - }), - ) - .query(async ({ input }) => { - return await getPreOnboardData(input.servizioId); - }), + getServizio: protectedProcedure .input( z.object({ @@ -322,22 +301,6 @@ export const servizioRouter = createTRPCRouter({ return await removePagamento(input.pagamentoId); }), - sendContattoEmail: publicProcedure - .input( - z.object({ - codice: z.string(), - email: z.string(), - messaggio: z.string(), - nome: z.string(), - telefono: z.string(), - }), - ) - .mutation(async ({ input }) => { - return await SendContactEmail({ - ...input, - }); - }), - setupSaldoConsulenzaServizio: protectedProcedure .input( z.object({ diff --git a/apps/infoalloggi/src/server/api/routers/stats.ts b/apps/infoalloggi/src/server/api/routers/stats.ts index 11c55b9..ddb6abc 100644 --- a/apps/infoalloggi/src/server/api/routers/stats.ts +++ b/apps/infoalloggi/src/server/api/routers/stats.ts @@ -3,77 +3,6 @@ import { db } from "~/server/db"; export const statsRouter = createTRPCRouter({ adminDashStats: adminProcedure.query(async () => { - // const userTimeserie = ( - // await db - // .selectFrom("users") - // .select((eb) => [ - // sql`date_trunc('day', created_at)`.as("date"), - // eb.fn.count("id").as("value"), - // ]) - // .where("isAdmin", "=", false) - // .groupBy("date") - // .orderBy("date") - // .execute() - // ).map((item) => ({ - // date: item.date, - // value: parseInt(String(item.value)), - // })); - - // const serviziTimeserie = { - // data: Object.values( - // ( - // await db - // .selectFrom("servizio") - // .select((eb) => [ - // sql`date_trunc('day', created_at)`.as("date"), - // eb.fn.count("servizio_id").as("value"), - // "tipologia", - // ]) - // .groupBy(["date", "tipologia"]) - // .orderBy("date") - // .execute() - // ).reduce( - // (acc, item) => { - // const dateStr = item.date.toISOString().slice(0, 10); - // if (!acc[dateStr]) { - // acc[dateStr] = { - // date: item.date, - // valueA: 0, - // valueB: 0, - // }; - // } - // if (item.tipologia === TipologiaPosizioneEnum.Transitorio) { - // acc[dateStr].valueA = parseInt(String(item.value)); - // } else if (item.tipologia === TipologiaPosizioneEnum.Stabile) { - // acc[dateStr].valueB = parseInt(String(item.value)); - // } - // return acc; - // }, - // {} as Record, - // ), - // ), - // valueALabel: "Transitorio", - // valueBLabel: "Stabile", - // }; - - // const contattiTimeserie = ( - // await db - // .selectFrom("servizio_annunci") - // .select((eb) => [ - // sql`date_trunc('day', created_at)`.as("date"), - // eb.fn - // .count(eb.fn("concat", ["servizio_id", "annunci_id"])) - // .as("value"), - // ]) - // .where("open_contatti_at", "is not", null) - // .groupBy("date") - // .orderBy("date") - // .execute() - // ).map((item) => ({ - // date: item.date, - // value: parseInt(String(item.value)), - // })); - const userCount = ( await db diff --git a/apps/infoalloggi/src/server/api/routers/stripe.ts b/apps/infoalloggi/src/server/api/routers/stripe.ts index ba4a345..b5bed9f 100644 --- a/apps/infoalloggi/src/server/api/routers/stripe.ts +++ b/apps/infoalloggi/src/server/api/routers/stripe.ts @@ -1,8 +1,9 @@ import { z } from "zod/v4"; import { + adminProcedure, createTRPCRouter, + protectedApiProcedure, protectedProcedure, - publicProcedure, } from "~/server/api/trpc"; import { createIntentHandler, @@ -14,7 +15,7 @@ import { import { zPagamentoId } from "~/server/utils/zod_types"; export const stripeRouter = createTRPCRouter({ - health: publicProcedure.query(async () => { + health: adminProcedure.query(async () => { return await stripeHealthCheck(); }), createIntent: protectedProcedure @@ -28,28 +29,28 @@ export const stripeRouter = createTRPCRouter({ paymentId: input.paymentId, }); }), - whIntentCreated: publicProcedure + whIntentCreated: protectedApiProcedure .input( z.object({ paymentId: zPagamentoId, pIntentId: z.string(), }), ) - .query(async ({ input }) => { + .mutation(async ({ input }) => { return await whIntentCreatedHandler({ paymentId: input.paymentId, pIntentId: input.pIntentId, }); }), - whIntentFailed: publicProcedure + whIntentFailed: protectedApiProcedure .input(z.object({ pIntentId: z.string() })) - .query(async ({ input }) => { + .mutation(async ({ input }) => { return await whIntentFailedHandler({ pIntentId: input.pIntentId, }); }), - whIntentSucceeded: publicProcedure + whIntentSucceeded: protectedApiProcedure .input( z.object({ paymentId: zPagamentoId, @@ -57,7 +58,7 @@ export const stripeRouter = createTRPCRouter({ pm_id: z.string(), }), ) - .query(async ({ input }) => { + .mutation(async ({ input }) => { return await whIntentSucceededHandler({ paymentId: input.paymentId, pIntentId: input.pIntentId, diff --git a/apps/infoalloggi/src/server/api/routers/sync.ts b/apps/infoalloggi/src/server/api/routers/sync.ts index f43c780..8c35604 100644 --- a/apps/infoalloggi/src/server/api/routers/sync.ts +++ b/apps/infoalloggi/src/server/api/routers/sync.ts @@ -1,96 +1,96 @@ -import z from "zod"; -import { createTRPCRouter, protectedApiProcedure } from "~/server/api/trpc"; -import { db } from "~/server/db"; +// import z from "zod"; +// import { createTRPCRouter, protectedApiProcedure } from "~/server/api/trpc"; +// import { db } from "~/server/db"; -type ClienteData = { - cognome?: string | undefined; - nome?: string | undefined; - cf?: string | undefined; - telefono?: string | undefined; - email?: string | undefined; - data_nascita?: string | undefined; - luogo_nascita?: string | undefined; - naz_residenza?: string | undefined; - provincia_residenza?: string | undefined; - cap_residenza?: string | undefined; - comune_residenza?: string | undefined; - indirizzo_residenza?: string | undefined; - civico_residenza?: string | undefined; -}; +// type ClienteData = { +// cognome?: string | undefined; +// nome?: string | undefined; +// cf?: string | undefined; +// telefono?: string | undefined; +// email?: string | undefined; +// data_nascita?: string | undefined; +// luogo_nascita?: string | undefined; +// naz_residenza?: string | undefined; +// provincia_residenza?: string | undefined; +// cap_residenza?: string | undefined; +// comune_residenza?: string | undefined; +// indirizzo_residenza?: string | undefined; +// civico_residenza?: string | undefined; +// }; -const clienteDataSchema = z.object({ - cap_residenza: z.string().optional(), - cf: z.string().optional(), - civico_residenza: z.string().optional(), - cognome: z.string().optional(), - comune_residenza: z.string().optional(), - data_nascita: z.string().optional(), - email: z.string().optional(), - indirizzo_residenza: z.string().optional(), - luogo_nascita: z.string().optional(), - naz_residenza: z.string().optional(), - nome: z.string().optional(), - provincia_residenza: z.string().optional(), - telefono: z.string().optional(), -}); +// const clienteDataSchema = z.object({ +// cap_residenza: z.string().optional(), +// cf: z.string().optional(), +// civico_residenza: z.string().optional(), +// cognome: z.string().optional(), +// comune_residenza: z.string().optional(), +// data_nascita: z.string().optional(), +// email: z.string().optional(), +// indirizzo_residenza: z.string().optional(), +// luogo_nascita: z.string().optional(), +// naz_residenza: z.string().optional(), +// nome: z.string().optional(), +// provincia_residenza: z.string().optional(), +// telefono: z.string().optional(), +// }); -export const syncRouter = createTRPCRouter({ - syncGet: protectedApiProcedure - .input(z.object({ cf: z.string() })) - .query(async ({ input }) => { - const user = await db - .selectFrom("users_anagrafica") - .select([ - "users_anagrafica.codice_fiscale", - "users_anagrafica.userid", - "users_anagrafica.data_nascita", - "users_anagrafica.luogo_nascita", - "users_anagrafica.nazione_residenza", - "users_anagrafica.provincia_residenza", - "users_anagrafica.cap_residenza", - "users_anagrafica.comune_residenza", - "users_anagrafica.via_residenza", - "users_anagrafica.civico_residenza", - ]) - .innerJoin("users", "users.id", "users_anagrafica.userid") - .select([ - "users.nome", - "users.cognome", - "users.email", - "users.telefono", - ]) - .where("users_anagrafica.codice_fiscale", "=", input.cf) - .executeTakeFirst(); +// export const syncRouter = createTRPCRouter({ +// syncGet: protectedApiProcedure +// .input(z.object({ cf: z.string() })) +// .query(async ({ input }) => { +// const user = await db +// .selectFrom("users_anagrafica") +// .select([ +// "users_anagrafica.codice_fiscale", +// "users_anagrafica.userid", +// "users_anagrafica.data_nascita", +// "users_anagrafica.luogo_nascita", +// "users_anagrafica.nazione_residenza", +// "users_anagrafica.provincia_residenza", +// "users_anagrafica.cap_residenza", +// "users_anagrafica.comune_residenza", +// "users_anagrafica.via_residenza", +// "users_anagrafica.civico_residenza", +// ]) +// .innerJoin("users", "users.id", "users_anagrafica.userid") +// .select([ +// "users.nome", +// "users.cognome", +// "users.email", +// "users.telefono", +// ]) +// .where("users_anagrafica.codice_fiscale", "=", input.cf) +// .executeTakeFirst(); - const result: ClienteData = { - cognome: user?.cognome, - nome: user?.nome, - cf: user?.codice_fiscale || undefined, - telefono: user?.telefono, - email: user?.email, - data_nascita: user?.data_nascita?.toLocaleDateString("it-IT", { - year: "numeric", - month: "2-digit", - day: "2-digit", - }), - luogo_nascita: user?.luogo_nascita || undefined, - naz_residenza: user?.nazione_residenza || undefined, - provincia_residenza: user?.provincia_residenza || undefined, - cap_residenza: user?.cap_residenza || undefined, - comune_residenza: user?.comune_residenza || undefined, - indirizzo_residenza: user?.via_residenza || undefined, - civico_residenza: user?.civico_residenza || undefined, - }; +// const result: ClienteData = { +// cognome: user?.cognome, +// nome: user?.nome, +// cf: user?.codice_fiscale || undefined, +// telefono: user?.telefono, +// email: user?.email, +// data_nascita: user?.data_nascita?.toLocaleDateString("it-IT", { +// year: "numeric", +// month: "2-digit", +// day: "2-digit", +// }), +// luogo_nascita: user?.luogo_nascita || undefined, +// naz_residenza: user?.nazione_residenza || undefined, +// provincia_residenza: user?.provincia_residenza || undefined, +// cap_residenza: user?.cap_residenza || undefined, +// comune_residenza: user?.comune_residenza || undefined, +// indirizzo_residenza: user?.via_residenza || undefined, +// civico_residenza: user?.civico_residenza || undefined, +// }; - return result; - }), +// return result; +// }), - syncPost: protectedApiProcedure - .input(z.object({ data: clienteDataSchema })) - .mutation(async ({ input }) => { - console.log("input", input); - // const parsed = clienteDataSchema.safeParse(JSON.parse(input.data)); - // console.log("parsed", parsed); - return { message: "Data received" }; - }), -}); +// syncPost: protectedApiProcedure +// .input(z.object({ data: clienteDataSchema })) +// .mutation(async ({ input }) => { +// console.log("input", input); +// // const parsed = clienteDataSchema.safeParse(JSON.parse(input.data)); +// // console.log("parsed", parsed); +// return { message: "Data received" }; +// }), +// }); diff --git a/apps/infoalloggi/src/server/api/routers/users.ts b/apps/infoalloggi/src/server/api/routers/users.ts index 056879b..fecfd2f 100644 --- a/apps/infoalloggi/src/server/api/routers/users.ts +++ b/apps/infoalloggi/src/server/api/routers/users.ts @@ -20,6 +20,43 @@ import { getClientProfilo } from "~/server/services/user.service"; import { zUserId } from "~/server/utils/zod_types"; export const usersRouter = createTRPCRouter({ + getUser: protectedProcedure + .input( + z.object({ + id: zUserId, + }), + ) + .query(async ({ input }) => { + return await getUserHandler({ db, id: input.id }); + }), + + getUsers: adminProcedure.query(async () => { + return await db + .selectFrom("users") + .selectAll() + .orderBy("id", "desc") + .execute(); + }), + getAdmins: adminProcedure.query(async () => { + return await db + .selectFrom("users") + .selectAll() + .where("isAdmin", "=", true) + .orderBy("id", "desc") + .execute(); + }), + getClientProfilo: protectedProcedure + .input( + z.object({ + userId: zUserId, + }), + ) + .query(async ({ input }) => { + return getClientProfilo({ + db, + userId: input.userId, + }); + }), blockUser: adminProcedure .input( z.object({ @@ -61,46 +98,8 @@ export const usersRouter = createTRPCRouter({ getActiveUsersWithoutChat: adminProcedure.query(async () => { return await getActiveUserWithoutChatHandler({ db }); }), - getClientProfilo: protectedProcedure - .input( - z.object({ - userId: zUserId, - }), - ) - .query(async ({ input }) => { - return getClientProfilo({ - db, - userId: input.userId, - }); - }), - getUser: protectedProcedure - .input( - z.object({ - id: zUserId, - }), - ) - .query(async ({ input }) => { - return await getUserHandler({ db, id: input.id }); - }), - getUsers: adminProcedure.query(async () => { - const query = await db - .selectFrom("users") - .selectAll() - .orderBy("id", "desc") - .execute(); - - return query; - }), getUsersWChatInfo: adminProcedure.query(async () => { return await getUsersWithChatInfoHandler({ db }); }), - getAdmins: adminProcedure.query(async () => { - return await db - .selectFrom("users") - .selectAll() - .where("isAdmin", "=", true) - .orderBy("id", "desc") - .execute(); - }), }); diff --git a/apps/infoalloggi/src/server/controllers/annunci.controller.ts b/apps/infoalloggi/src/server/controllers/annunci.controller.ts index ce2b689..d8511f5 100644 --- a/apps/infoalloggi/src/server/controllers/annunci.controller.ts +++ b/apps/infoalloggi/src/server/controllers/annunci.controller.ts @@ -51,27 +51,6 @@ export const getAnnunciListHandler = async (): Promise< } }; -export const getOnline_AnnuncioIdCodice_AnnunciHandler = async () => { - try { - const data = await db - .selectFrom("annunci") - .select(["codice", "id"]) - .where("annunci.web", "=", true) - .where("stato", "!=", "Sospeso") - .execute(); - if (!data) { - return []; - } - - return data.filter((c) => c.id && c.codice); - } catch (e) { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: `Errore query getOnline_AnnuncioIdCodice_AnnunciHandler: ${(e as Error).message}`, - }); - } -}; - export const getCodici_AnnunciHandler = async (): Promise => { try { const codici = await db diff --git a/apps/infoalloggi/src/server/controllers/catasto.controller.ts b/apps/infoalloggi/src/server/controllers/catasto.controller.ts index 883bdf7..ba3bb4c 100644 --- a/apps/infoalloggi/src/server/controllers/catasto.controller.ts +++ b/apps/infoalloggi/src/server/controllers/catasto.controller.ts @@ -1,6 +1,4 @@ import { TRPCError } from "@trpc/server"; -import type { ComuniId } from "~/schemas/public/Comuni"; -import type { NazioniId } from "~/schemas/public/Nazioni"; import { db } from "../db"; export const getComuni = async () => { @@ -28,20 +26,6 @@ export const searchComuniByCatasto = async (catasto: string[]) => { }); } }; -export const getComuneById = async (id: ComuniId) => { - try { - return await db - .selectFrom("comuni") - .selectAll() - .where("id", "=", id) - .executeTakeFirst(); - } catch (e) { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: `Error while getting ComuneById: ${(e as Error).message}`, - }); - } -}; export const getProvincie = async () => { try { @@ -64,17 +48,3 @@ export const getNazioni = async () => { }); } }; -export const getNazioneById = async (id: NazioniId) => { - try { - return await db - .selectFrom("nazioni") - .selectAll() - .where("id", "=", id) - .executeTakeFirst(); - } catch (e) { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: `Error while getting NazioneById: ${(e as Error).message}`, - }); - } -}; diff --git a/apps/infoalloggi/src/server/controllers/event_queue.controller.ts b/apps/infoalloggi/src/server/controllers/event_queue.controller.ts index 148ce35..ea9c445 100644 --- a/apps/infoalloggi/src/server/controllers/event_queue.controller.ts +++ b/apps/infoalloggi/src/server/controllers/event_queue.controller.ts @@ -67,7 +67,7 @@ export const nextTimeForNotification = () => { return lock_expires; }; -export type EventDataTypes = Email_EventData | SMS_EventData; +type EventDataTypes = Email_EventData | SMS_EventData; type NewEventQueueProps = Override; diff --git a/apps/infoalloggi/src/server/controllers/fic.controller.ts b/apps/infoalloggi/src/server/controllers/fic.controller.ts index 2cd4b25..0be93bc 100644 --- a/apps/infoalloggi/src/server/controllers/fic.controller.ts +++ b/apps/infoalloggi/src/server/controllers/fic.controller.ts @@ -1,30 +1,29 @@ -import type { Client } from "@fattureincloud/fattureincloud-ts-sdk"; import { clientsApi, companyId } from "~/server/FattureInCloud"; -export const getClientList = async () => { - const clients = await clientsApi.listClients( - companyId, - undefined, - "detailed", - undefined, - undefined, - 100, - ); - return clients.data; -}; +// export const getClientList = async () => { +// const clients = await clientsApi.listClients( +// companyId, +// undefined, +// "detailed", +// undefined, +// undefined, +// 100, +// ); +// return clients.data; +// }; -export const searchClient = async (cognome: string) => { - const clients = await clientsApi.listClients( - companyId, - undefined, - "detailed", - undefined, - undefined, - 100, - `name contains '${cognome}'`, - ); - return clients.data; -}; +// export const searchClient = async (cognome: string) => { +// const clients = await clientsApi.listClients( +// companyId, +// undefined, +// "detailed", +// undefined, +// undefined, +// 100, +// `name contains '${cognome}'`, +// ); +// return clients.data; +// }; export const getClientFromCF = async (cf: string) => { if (cf.length < 11) { return null; @@ -41,7 +40,7 @@ export const getClientFromCF = async (cf: string) => { return clients.data; }; -export const addClient = async (client: Client) => { - const newClient = await clientsApi.createClient(companyId, { data: client }); - return newClient.data; -}; +// export const addClient = async (client: Client) => { +// const newClient = await clientsApi.createClient(companyId, { data: client }); +// return newClient.data; +// }; diff --git a/apps/infoalloggi/src/server/controllers/servizio.controller.ts b/apps/infoalloggi/src/server/controllers/servizio.controller.ts index 6d51229..369ad94 100644 --- a/apps/infoalloggi/src/server/controllers/servizio.controller.ts +++ b/apps/infoalloggi/src/server/controllers/servizio.controller.ts @@ -158,53 +158,7 @@ export const getServiziByUserId = async (userId: UsersId) => { }); } }; -export const getPreOnboardData = async (servizioId: ServizioServizioId) => { - try { - const servizio = await getServizioById(servizioId); - if (!servizio) { - throw new TRPCError({ - code: "NOT_FOUND", - message: "Servizio not found", - }); - } - - const userData = await db - .selectFrom("users") - .select([ - "users.id", - "users.nome", - "users.cognome", - "users.email", - "users.telefono", - ]) - .where("id", "=", servizio.user_id) - .executeTakeFirstOrThrow( - () => new Error(`User not found - userId: ${servizio.user_id}`), - ); - - if (!userData) { - throw new TRPCError({ - code: "NOT_FOUND", - message: "User not found", - }); - } - const hasPrevious = await db - .selectFrom("servizio") - .select("servizio_id") - .where("user_id", "=", servizio.user_id) - .where("servizio_id", "!=", servizioId) - .where("isOkAcconto", "=", true) - .executeTakeFirst(); - - return { hasPrevious: !!hasPrevious, servizio, userData }; - } catch (e) { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: `Error fetching pre-onboard data: ${(e as Error).message}`, - }); - } -}; export const getDataPerAcquisto = async (servizioId: ServizioServizioId) => { try { const servizio = await getServizioById(servizioId); @@ -1946,7 +1900,7 @@ export const getUserPagamenti = async ( } }; -export const SendContactEmail = async ({ +export const SendContattoAnnuncioEmail = async ({ codice, nome, email, @@ -2154,37 +2108,3 @@ export const getOrdineRicevutaData = async ({ }); } }; - -export const getServizioOrdini = async (servizioId: ServizioServizioId) => { - try { - const data = await db - .selectFrom("ordini") - .selectAll("ordini") - .select((eb) => [ - jsonArrayFrom( - eb - .selectFrom("payments") - .whereRef("payments.ordine_id", "=", "ordini.ordine_id") - .selectAll("payments") - .orderBy("created_at", "desc"), - ).as("pagamenti"), - ]) - .where("servizio_id", "=", servizioId) - .orderBy("created_at", "desc") - .execute(); - - return data.map((ordine) => ({ - ...ordine, - pagamenti: ordine.pagamenti.map((payment) => ({ - ...payment, - created_at: new Date(payment.created_at), - paid_at: payment.paid_at ? new Date(payment.paid_at) : null, - })), - })); - } catch (e) { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: `Error fetching servizio ordini: ${(e as Error).message}`, - }); - } -}; diff --git a/apps/infoalloggi/src/server/services/auth.service.ts b/apps/infoalloggi/src/server/services/auth.service.ts index b31dfc8..dae2dbc 100644 --- a/apps/infoalloggi/src/server/services/auth.service.ts +++ b/apps/infoalloggi/src/server/services/auth.service.ts @@ -53,22 +53,6 @@ export const isTokenValid = async ({ token }: { token: string }) => { }); } }; -export const pwResetTokenFromMailHandler = async ({ - email, -}: { - email: string; -}) => { - const user = await findUser_byEmail({ email }); - if (!user) { - throw new TRPCError({ - code: "NOT_FOUND", - message: "Utente non trovato", - }); - } - - const token = await genPasswordResetToken({ id: user.id }); - return { token, userId: user.id }; -}; export const resetPasswordFromTokenHandler = async ({ token, @@ -113,7 +97,16 @@ export const resetPasswordFromTokenHandler = async ({ }; export const pwResetSendLinkHandler = async ({ email }: { email: string }) => { - const { token, userId } = await pwResetTokenFromMailHandler({ email }); + const user = await findUser_byEmail({ email }); + if (!user) { + throw new TRPCError({ + code: "NOT_FOUND", + message: "Utente non trovato", + }); + } + + const token = await genPasswordResetToken({ id: user.id }); + await NewMail({ template: { mailType: "pwResetLink", @@ -125,7 +118,7 @@ export const pwResetSendLinkHandler = async ({ email }: { email: string }) => { subject: `Richiesta di reset password Infoalloggi.it`, to: email, }, - userId, + userId: user.id, }); }; diff --git a/apps/infoalloggi/src/server/services/prezziario.service.ts b/apps/infoalloggi/src/server/services/prezziario.service.ts index 7f11ec4..57d3096 100644 --- a/apps/infoalloggi/src/server/services/prezziario.service.ts +++ b/apps/infoalloggi/src/server/services/prezziario.service.ts @@ -92,26 +92,26 @@ export const updatePrezziario = async ({ } }; -export const deletePrezziario = async ({ - db, - prezziarioId, -}: { - db: Querier; +// export const deletePrezziario = async ({ +// db, +// prezziarioId, +// }: { +// db: Querier; - prezziarioId: PrezziarioIdprezziario; -}): Promise => { - try { - await db - .deleteFrom("prezziario") - .where("prezziario.idprezziario", "=", prezziarioId) - .execute(); - } catch (error) { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: `Error deleting prezziario: ${(error as Error).message}`, - }); - } -}; +// prezziarioId: PrezziarioIdprezziario; +// }): Promise => { +// try { +// await db +// .deleteFrom("prezziario") +// .where("prezziario.idprezziario", "=", prezziarioId) +// .execute(); +// } catch (error) { +// throw new TRPCError({ +// code: "INTERNAL_SERVER_ERROR", +// message: `Error deleting prezziario: ${(error as Error).message}`, +// }); +// } +// }; type MinimalPrezziario = Pick< Prezziario, diff --git a/apps/infoalloggi/src/server/utils/zod_types.ts b/apps/infoalloggi/src/server/utils/zod_types.ts index 2e06a61..25ff28a 100644 --- a/apps/infoalloggi/src/server/utils/zod_types.ts +++ b/apps/infoalloggi/src/server/utils/zod_types.ts @@ -3,18 +3,15 @@ import type { AnnunciId } from "~/schemas/public/Annunci"; import type { BanlistId } from "~/schemas/public/Banlist"; import BanType from "~/schemas/public/BanType"; import type { ChatsChatid } from "~/schemas/public/Chats"; -import type { ComuniId } from "~/schemas/public/Comuni"; import type { EtichetteIdEtichetta } from "~/schemas/public/Etichette"; import type { FlagsId } from "~/schemas/public/Flags"; import type { MessagesMessageid } from "~/schemas/public/Messages"; -import type { NazioniId } from "~/schemas/public/Nazioni"; import type { OrdiniOrdineId } from "~/schemas/public/Ordini"; import type { PaymentsId } from "~/schemas/public/Payments"; import type { PrezziarioIdprezziario } from "~/schemas/public/Prezziario"; import type { ServizioServizioId } from "~/schemas/public/Servizio"; import type { TestiEStringheStingaId } from "~/schemas/public/TestiEStringhe"; import type { UsersId } from "~/schemas/public/Users"; -import type { EventDataTypes } from "~/server/controllers/event_queue.controller"; export const zUserId = z.custom( (val) => typeof val === "string", @@ -61,10 +58,10 @@ export const zTestiEStringheStingaId = z.custom( "falied to validate TestiEStringheStingaId", ); -export const zEventDataTypes = z.custom( - (val) => typeof val === "object", - "falied to validate EventDataTypes", -); +// export const zEventDataTypes = z.custom( +// (val) => typeof val === "object", +// "falied to validate EventDataTypes", +// ); export const zBanlistId = z.custom( (val) => typeof val === "number", @@ -85,12 +82,12 @@ export const zPagamentoId = z.custom( "falied to validate PagamentoId", ); -export const zComuneId = z.custom( - (val) => typeof val === "number", - "falied to validate ComuneId", -); +// export const zComuneId = z.custom( +// (val) => typeof val === "number", +// "falied to validate ComuneId", +// ); -export const zNazioneId = z.custom( - (val) => typeof val === "number", - "falied to validate NazioneId", -); +// export const zNazioneId = z.custom( +// (val) => typeof val === "number", +// "falied to validate NazioneId", +// ); diff --git a/apps/infoalloggi/src/utils/kysely-helper.ts b/apps/infoalloggi/src/utils/kysely-helper.ts index 588746f..00bb780 100644 --- a/apps/infoalloggi/src/utils/kysely-helper.ts +++ b/apps/infoalloggi/src/utils/kysely-helper.ts @@ -3,18 +3,18 @@ import { expressionBuilder } from "kysely"; import { jsonArrayFrom, jsonObjectFrom } from "kysely/helpers/postgres"; import type Database from "~/schemas/Database"; import type { UsersId } from "~/schemas/public/Users"; -export function getMessagesArray() { - const eb = expressionBuilder(); - return jsonArrayFrom( - eb - .selectFrom("messages") - .selectAll("messages") - .whereRef("messages.chatid", "=", "chats.chatid") - .leftJoin("users", "users.id", "messages.sender") - .select(["users.nome as sender_nome", "users.isAdmin as sender_isAdmin"]) - .orderBy("messages.time", "asc"), - ).as("messagesArray"); -} +// export function getMessagesArray() { +// const eb = expressionBuilder(); +// return jsonArrayFrom( +// eb +// .selectFrom("messages") +// .selectAll("messages") +// .whereRef("messages.chatid", "=", "chats.chatid") +// .leftJoin("users", "users.id", "messages.sender") +// .select(["users.nome as sender_nome", "users.isAdmin as sender_isAdmin"]) +// .orderBy("messages.time", "asc"), +// ).as("messagesArray"); +// } export type UserInfoQueryType = { id: UsersId; username: string;