From 41d743c97fd6bff237c21beb1cad2367c32c9c4e Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Thu, 12 Mar 2026 16:27:24 +0100 Subject: [PATCH] refactor: update TypeScript SDK path and improve error handling in servizio service --- apps/infoalloggi/.vscode/settings.json | 3 +- .../src/components/servizio/servizio.tsx | 5 +- .../components/servizio/servizio_actions.tsx | 4 +- .../src/server/services/servizio.service.ts | 285 +++++++++--------- 4 files changed, 146 insertions(+), 151 deletions(-) diff --git a/apps/infoalloggi/.vscode/settings.json b/apps/infoalloggi/.vscode/settings.json index 4c3e587..97bdc0f 100644 --- a/apps/infoalloggi/.vscode/settings.json +++ b/apps/infoalloggi/.vscode/settings.json @@ -17,5 +17,6 @@ "username": "postgres" } ], - "typescript.tsdk": "node_modules\\typescript\\lib" + "js/ts.tsdk.path": "node_modules\\typescript\\lib", + "biome.lsp.trace.server": "verbose", } \ No newline at end of file diff --git a/apps/infoalloggi/src/components/servizio/servizio.tsx b/apps/infoalloggi/src/components/servizio/servizio.tsx index 5975535..ecc921d 100644 --- a/apps/infoalloggi/src/components/servizio/servizio.tsx +++ b/apps/infoalloggi/src/components/servizio/servizio.tsx @@ -121,9 +121,7 @@ const RinnovoLinkCard = ({ key={data.id} > @@ -134,7 +132,6 @@ const RinnovoLinkCard = ({ -
Vai al rinnovo diff --git a/apps/infoalloggi/src/components/servizio/servizio_actions.tsx b/apps/infoalloggi/src/components/servizio/servizio_actions.tsx index 7705063..f776b8e 100644 --- a/apps/infoalloggi/src/components/servizio/servizio_actions.tsx +++ b/apps/infoalloggi/src/components/servizio/servizio_actions.tsx @@ -58,7 +58,7 @@ import { FormEditServizio, } from "~/forms/FormEditServizioAdmin"; import { FormNewOrder } from "~/forms/FormNewOrdine"; -import { FormNewServizio, type FormValues } from "~/forms/FormNewServizio"; +import { FormServizio, type FormValues } from "~/forms/FormServizio"; import { cn, formatCurrency } from "~/lib/utils"; import { useTranslation } from "~/providers/I18nProvider"; import { useServizio } from "~/providers/ServizioProvider"; @@ -696,7 +696,7 @@ const EditParametri = () => { - { - try { - return await db.transaction().execute(async (tx) => { - const servizio = await tx - .insertInto("servizio") - .values(data) - .returningAll() - .executeTakeFirstOrThrow( - () => new Error("Failed to insert new servizio into database"), - ); + try { + return await db.transaction().execute(async (tx) => { + const servizio = await tx + .insertInto("servizio") + .values(data) + .returningAll() + .executeTakeFirstOrThrow( + () => new Error("Failed to insert new servizio into database"), + ); const acconto = await db .selectFrom("prezziario") @@ -29,160 +29,157 @@ export const addServizio = async (data: NewServizio) => { .limit(1) .executeTakeFirst(); - if (!acconto) { - throw new Error("Acconto not found for new servizio"); - } - await tx - .insertInto("ordini") - .values({ - servizio_id: servizio.servizio_id, - userid: servizio.user_id, - type: OrderTypeEnum.Acconto, - amount_cent: acconto.prezzo_cent, - packid: acconto.idprezziario, - isActive: data.skipPayment || false, - }) - .execute(); - return servizio; - }); - } catch (e) { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: `Error adding new servizio: ${(e as Error).message}`, - }); - } + if (!acconto) { + throw new Error("Acconto not found for new servizio"); + } + await tx + .insertInto("ordini") + .values({ + servizio_id: servizio.servizio_id, + userid: servizio.user_id, + type: OrderTypeEnum.Acconto, + amount_cent: acconto.prezzo_cent, + packid: acconto.idprezziario, + isActive: data.skipPayment || false, + }) + .execute(); + return servizio; + }); + } catch (e) { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: `Error adding new servizio: ${(e as Error).message}`, + }); + } }; export const getServizioById = async (servizioId: ServizioServizioId) => { - try { - return await db - .selectFrom("servizio") - .selectAll() - .where("servizio_id", "=", servizioId) - .executeTakeFirstOrThrow( - () => new Error(`Servizio not found - servizioId: ${servizioId}`), - ); - } catch (e) { - throw new TRPCError({ - code: "NOT_FOUND", - message: `Servizio not found: ${(e as Error).message}`, - }); - } + try { + return await db + .selectFrom("servizio") + .selectAll() + .where("servizio_id", "=", servizioId) + .executeTakeFirstOrThrow( + () => new Error(`Servizio not found - servizioId: ${servizioId}`), + ); + } catch (e) { + throw new TRPCError({ + code: "NOT_FOUND", + message: `Servizio not found: ${(e as Error).message}`, + }); + } }; export const updateServizio = async ({ - servizioId, - data, + servizioId, + data, }: { - servizioId: ServizioServizioId; - data: ServizioUpdate; + servizioId: ServizioServizioId; + data: ServizioUpdate; }) => { - try { - return await db - .updateTable("servizio") - .set(data) - .where("servizio_id", "=", servizioId) - .returningAll() - .executeTakeFirstOrThrow( - () => - new Error(`Failed to update servizio - servizioId: ${servizioId}`), - ); - } catch (e) { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: `Error updating servizio: ${(e as Error).message}`, - }); - } + try { + return await db + .updateTable("servizio") + .set(data) + .where("servizio_id", "=", servizioId) + .returningAll() + .executeTakeFirstOrThrow( + () => + new Error(`Failed to update servizio - servizioId: ${servizioId}`), + ); + } catch (e) { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: `Error updating servizio: ${(e as Error).message}`, + }); + } }; export const deleteServizio = async (servizioId: ServizioServizioId) => { - try { - await db - .deleteFrom("servizio") - .where("servizio_id", "=", servizioId) - .execute(); - return true; - } catch (e) { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: `Error deleting servizio: ${(e as Error).message}`, - }); - } + try { + await db + .deleteFrom("servizio") + .where("servizio_id", "=", servizioId) + .execute(); + return true; + } catch (e) { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: `Error deleting servizio: ${(e as Error).message}`, + }); + } }; - - - ////// SERVIZIO ANNUNCI export const getServizioAnnuncio = async ({ - servizioId, - annuncioId, + servizioId, + annuncioId, }: { - servizioId: ServizioServizioId; - annuncioId: AnnunciId; + servizioId: ServizioServizioId; + annuncioId: AnnunciId; }) => { - try { - return await db - .selectFrom("servizio_annunci") - .selectAll() - .where("servizio_id", "=", servizioId) - .where("annunci_id", "=", annuncioId) - .executeTakeFirstOrThrow( - () => - new Error( - `Servizio not found - servizioId: ${servizioId}, annunciId: ${annuncioId}`, - ), - ); - } catch (e) { - throw new TRPCError({ - code: "NOT_FOUND", - message: `Servizio not found: ${(e as Error).message}`, - }); - } + try { + return await db + .selectFrom("servizio_annunci") + .selectAll() + .where("servizio_id", "=", servizioId) + .where("annunci_id", "=", annuncioId) + .executeTakeFirstOrThrow( + () => + new Error( + `Servizio not found - servizioId: ${servizioId}, annunciId: ${annuncioId}`, + ), + ); + } catch (e) { + throw new TRPCError({ + code: "NOT_FOUND", + message: `Servizio not found: ${(e as Error).message}`, + }); + } }; export const updateServizioAnnuncio = async ({ - servizioId, - annuncioId, - data, + servizioId, + annuncioId, + data, }: { - servizioId: ServizioServizioId; - annuncioId: AnnunciId; - data: ServizioAnnunciUpdate; + servizioId: ServizioServizioId; + annuncioId: AnnunciId; + data: ServizioAnnunciUpdate; }) => { - try { - await db - .updateTable("servizio_annunci") - .set(data) - .where("servizio_id", "=", servizioId) - .where("annunci_id", "=", annuncioId) - .execute(); + try { + await db + .updateTable("servizio_annunci") + .set(data) + .where("servizio_id", "=", servizioId) + .where("annunci_id", "=", annuncioId) + .execute(); - return true; - } catch (e) { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: `Error updating servizio from annuncio: ${(e as Error).message}`, - }); - } + return true; + } catch (e) { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: `Error updating servizio from annuncio: ${(e as Error).message}`, + }); + } }; export const deleteServizioAnnuncio = async ( - servizioId: ServizioServizioId, - annuncioId: AnnunciId, + servizioId: ServizioServizioId, + annuncioId: AnnunciId, ) => { - try { - await db - .deleteFrom("servizio_annunci") - .where("servizio_id", "=", servizioId) - .where("annunci_id", "=", annuncioId) - .execute(); - return true; - } catch (e) { - throw new TRPCError({ - code: "INTERNAL_SERVER_ERROR", - message: `Error deleting servizio from annuncio: ${(e as Error).message}`, - }); - } -}; \ No newline at end of file + try { + await db + .deleteFrom("servizio_annunci") + .where("servizio_id", "=", servizioId) + .where("annunci_id", "=", annuncioId) + .execute(); + return true; + } catch (e) { + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: `Error deleting servizio from annuncio: ${(e as Error).message}`, + }); + } +};