refactor: update TypeScript SDK path and improve error handling in servizio service
This commit is contained in:
parent
985a302a05
commit
41d743c97f
4 changed files with 146 additions and 151 deletions
3
apps/infoalloggi/.vscode/settings.json
vendored
3
apps/infoalloggi/.vscode/settings.json
vendored
|
|
@ -17,5 +17,6 @@
|
||||||
"username": "postgres"
|
"username": "postgres"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"typescript.tsdk": "node_modules\\typescript\\lib"
|
"js/ts.tsdk.path": "node_modules\\typescript\\lib",
|
||||||
|
"biome.lsp.trace.server": "verbose",
|
||||||
}
|
}
|
||||||
|
|
@ -121,9 +121,7 @@ const RinnovoLinkCard = ({
|
||||||
key={data.id}
|
key={data.id}
|
||||||
>
|
>
|
||||||
<Card
|
<Card
|
||||||
className={cn(
|
className={cn("transition-shadow hover:bg-muted/15 hover:shadow-md")}
|
||||||
"transition-shadow hover:bg-muted/15 hover:shadow-md",
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="group-hover:underline">
|
<CardTitle className="group-hover:underline">
|
||||||
|
|
@ -134,7 +132,6 @@ const RinnovoLinkCard = ({
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex flex-col flex-wrap gap-4 sm:flex-row sm:justify-between">
|
<CardContent className="flex flex-col flex-wrap gap-4 sm:flex-row sm:justify-between">
|
||||||
|
|
||||||
<div className="flex items-center gap-2 rounded-md text-muted-foreground group-hover:text-foreground">
|
<div className="flex items-center gap-2 rounded-md text-muted-foreground group-hover:text-foreground">
|
||||||
<span>Vai al rinnovo</span>
|
<span>Vai al rinnovo</span>
|
||||||
<ArrowRight />
|
<ArrowRight />
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ import {
|
||||||
FormEditServizio,
|
FormEditServizio,
|
||||||
} from "~/forms/FormEditServizioAdmin";
|
} from "~/forms/FormEditServizioAdmin";
|
||||||
import { FormNewOrder } from "~/forms/FormNewOrdine";
|
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 { cn, formatCurrency } from "~/lib/utils";
|
||||||
import { useTranslation } from "~/providers/I18nProvider";
|
import { useTranslation } from "~/providers/I18nProvider";
|
||||||
import { useServizio } from "~/providers/ServizioProvider";
|
import { useServizio } from "~/providers/ServizioProvider";
|
||||||
|
|
@ -696,7 +696,7 @@ const EditParametri = () => {
|
||||||
</CredenzaDescription>
|
</CredenzaDescription>
|
||||||
</CredenzaHeader>
|
</CredenzaHeader>
|
||||||
<CredenzaBody className="max-h-[80vh] w-full max-w-3xl overflow-y-auto pb-5 sm:max-w-5xl">
|
<CredenzaBody className="max-h-[80vh] w-full max-w-3xl overflow-y-auto pb-5 sm:max-w-5xl">
|
||||||
<FormNewServizio
|
<FormServizio
|
||||||
initialData={servizio}
|
initialData={servizio}
|
||||||
isLimited={!isAdmin}
|
isLimited={!isAdmin}
|
||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,24 @@
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { db } from "../db";
|
|
||||||
import type { NewServizio, ServizioServizioId, ServizioUpdate } from "~/schemas/public/Servizio";
|
|
||||||
import OrderTypeEnum from "~/schemas/public/OrderTypeEnum";
|
|
||||||
import { ACCONTO_STABILE, ACCONTO_TRANSITORIO } from "../controllers/pagamenti.controller";
|
|
||||||
import TipologiaPosizioneEnum from "~/schemas/public/TipologiaPosizioneEnum";
|
|
||||||
import { getPrezziarioByIdHandler } from "./prezziario.service";
|
|
||||||
import type { AnnunciId } from "~/schemas/public/Annunci";
|
import type { AnnunciId } from "~/schemas/public/Annunci";
|
||||||
|
import OrderTypeEnum from "~/schemas/public/OrderTypeEnum";
|
||||||
|
import type {
|
||||||
|
NewServizio,
|
||||||
|
ServizioServizioId,
|
||||||
|
ServizioUpdate,
|
||||||
|
} from "~/schemas/public/Servizio";
|
||||||
import type { ServizioAnnunciUpdate } from "~/schemas/public/ServizioAnnunci";
|
import type { ServizioAnnunciUpdate } from "~/schemas/public/ServizioAnnunci";
|
||||||
import { db } from "../db";
|
import { db } from "../db";
|
||||||
|
|
||||||
export const addServizio = async (data: NewServizio) => {
|
export const addServizio = async (data: NewServizio) => {
|
||||||
try {
|
try {
|
||||||
return await db.transaction().execute(async (tx) => {
|
return await db.transaction().execute(async (tx) => {
|
||||||
const servizio = await tx
|
const servizio = await tx
|
||||||
.insertInto("servizio")
|
.insertInto("servizio")
|
||||||
.values(data)
|
.values(data)
|
||||||
.returningAll()
|
.returningAll()
|
||||||
.executeTakeFirstOrThrow(
|
.executeTakeFirstOrThrow(
|
||||||
() => new Error("Failed to insert new servizio into database"),
|
() => new Error("Failed to insert new servizio into database"),
|
||||||
);
|
);
|
||||||
|
|
||||||
const acconto = await db
|
const acconto = await db
|
||||||
.selectFrom("prezziario")
|
.selectFrom("prezziario")
|
||||||
|
|
@ -29,160 +29,157 @@ export const addServizio = async (data: NewServizio) => {
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|
||||||
if (!acconto) {
|
if (!acconto) {
|
||||||
throw new Error("Acconto not found for new servizio");
|
throw new Error("Acconto not found for new servizio");
|
||||||
}
|
}
|
||||||
await tx
|
await tx
|
||||||
.insertInto("ordini")
|
.insertInto("ordini")
|
||||||
.values({
|
.values({
|
||||||
servizio_id: servizio.servizio_id,
|
servizio_id: servizio.servizio_id,
|
||||||
userid: servizio.user_id,
|
userid: servizio.user_id,
|
||||||
type: OrderTypeEnum.Acconto,
|
type: OrderTypeEnum.Acconto,
|
||||||
amount_cent: acconto.prezzo_cent,
|
amount_cent: acconto.prezzo_cent,
|
||||||
packid: acconto.idprezziario,
|
packid: acconto.idprezziario,
|
||||||
isActive: data.skipPayment || false,
|
isActive: data.skipPayment || false,
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
return servizio;
|
return servizio;
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "INTERNAL_SERVER_ERROR",
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
message: `Error adding new servizio: ${(e as Error).message}`,
|
message: `Error adding new servizio: ${(e as Error).message}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getServizioById = async (servizioId: ServizioServizioId) => {
|
export const getServizioById = async (servizioId: ServizioServizioId) => {
|
||||||
try {
|
try {
|
||||||
return await db
|
return await db
|
||||||
.selectFrom("servizio")
|
.selectFrom("servizio")
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.where("servizio_id", "=", servizioId)
|
.where("servizio_id", "=", servizioId)
|
||||||
.executeTakeFirstOrThrow(
|
.executeTakeFirstOrThrow(
|
||||||
() => new Error(`Servizio not found - servizioId: ${servizioId}`),
|
() => new Error(`Servizio not found - servizioId: ${servizioId}`),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "NOT_FOUND",
|
code: "NOT_FOUND",
|
||||||
message: `Servizio not found: ${(e as Error).message}`,
|
message: `Servizio not found: ${(e as Error).message}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateServizio = async ({
|
export const updateServizio = async ({
|
||||||
servizioId,
|
servizioId,
|
||||||
data,
|
data,
|
||||||
}: {
|
}: {
|
||||||
servizioId: ServizioServizioId;
|
servizioId: ServizioServizioId;
|
||||||
data: ServizioUpdate;
|
data: ServizioUpdate;
|
||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
return await db
|
return await db
|
||||||
.updateTable("servizio")
|
.updateTable("servizio")
|
||||||
.set(data)
|
.set(data)
|
||||||
.where("servizio_id", "=", servizioId)
|
.where("servizio_id", "=", servizioId)
|
||||||
.returningAll()
|
.returningAll()
|
||||||
.executeTakeFirstOrThrow(
|
.executeTakeFirstOrThrow(
|
||||||
() =>
|
() =>
|
||||||
new Error(`Failed to update servizio - servizioId: ${servizioId}`),
|
new Error(`Failed to update servizio - servizioId: ${servizioId}`),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "INTERNAL_SERVER_ERROR",
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
message: `Error updating servizio: ${(e as Error).message}`,
|
message: `Error updating servizio: ${(e as Error).message}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteServizio = async (servizioId: ServizioServizioId) => {
|
export const deleteServizio = async (servizioId: ServizioServizioId) => {
|
||||||
try {
|
try {
|
||||||
await db
|
await db
|
||||||
.deleteFrom("servizio")
|
.deleteFrom("servizio")
|
||||||
.where("servizio_id", "=", servizioId)
|
.where("servizio_id", "=", servizioId)
|
||||||
.execute();
|
.execute();
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "INTERNAL_SERVER_ERROR",
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
message: `Error deleting servizio: ${(e as Error).message}`,
|
message: `Error deleting servizio: ${(e as Error).message}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////// SERVIZIO ANNUNCI
|
////// SERVIZIO ANNUNCI
|
||||||
|
|
||||||
export const getServizioAnnuncio = async ({
|
export const getServizioAnnuncio = async ({
|
||||||
servizioId,
|
servizioId,
|
||||||
annuncioId,
|
annuncioId,
|
||||||
}: {
|
}: {
|
||||||
servizioId: ServizioServizioId;
|
servizioId: ServizioServizioId;
|
||||||
annuncioId: AnnunciId;
|
annuncioId: AnnunciId;
|
||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
return await db
|
return await db
|
||||||
.selectFrom("servizio_annunci")
|
.selectFrom("servizio_annunci")
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.where("servizio_id", "=", servizioId)
|
.where("servizio_id", "=", servizioId)
|
||||||
.where("annunci_id", "=", annuncioId)
|
.where("annunci_id", "=", annuncioId)
|
||||||
.executeTakeFirstOrThrow(
|
.executeTakeFirstOrThrow(
|
||||||
() =>
|
() =>
|
||||||
new Error(
|
new Error(
|
||||||
`Servizio not found - servizioId: ${servizioId}, annunciId: ${annuncioId}`,
|
`Servizio not found - servizioId: ${servizioId}, annunciId: ${annuncioId}`,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "NOT_FOUND",
|
code: "NOT_FOUND",
|
||||||
message: `Servizio not found: ${(e as Error).message}`,
|
message: `Servizio not found: ${(e as Error).message}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateServizioAnnuncio = async ({
|
export const updateServizioAnnuncio = async ({
|
||||||
servizioId,
|
servizioId,
|
||||||
annuncioId,
|
annuncioId,
|
||||||
data,
|
data,
|
||||||
}: {
|
}: {
|
||||||
servizioId: ServizioServizioId;
|
servizioId: ServizioServizioId;
|
||||||
annuncioId: AnnunciId;
|
annuncioId: AnnunciId;
|
||||||
data: ServizioAnnunciUpdate;
|
data: ServizioAnnunciUpdate;
|
||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
await db
|
await db
|
||||||
.updateTable("servizio_annunci")
|
.updateTable("servizio_annunci")
|
||||||
.set(data)
|
.set(data)
|
||||||
.where("servizio_id", "=", servizioId)
|
.where("servizio_id", "=", servizioId)
|
||||||
.where("annunci_id", "=", annuncioId)
|
.where("annunci_id", "=", annuncioId)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "INTERNAL_SERVER_ERROR",
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
message: `Error updating servizio from annuncio: ${(e as Error).message}`,
|
message: `Error updating servizio from annuncio: ${(e as Error).message}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteServizioAnnuncio = async (
|
export const deleteServizioAnnuncio = async (
|
||||||
servizioId: ServizioServizioId,
|
servizioId: ServizioServizioId,
|
||||||
annuncioId: AnnunciId,
|
annuncioId: AnnunciId,
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
await db
|
await db
|
||||||
.deleteFrom("servizio_annunci")
|
.deleteFrom("servizio_annunci")
|
||||||
.where("servizio_id", "=", servizioId)
|
.where("servizio_id", "=", servizioId)
|
||||||
.where("annunci_id", "=", annuncioId)
|
.where("annunci_id", "=", annuncioId)
|
||||||
.execute();
|
.execute();
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "INTERNAL_SERVER_ERROR",
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
message: `Error deleting servizio from annuncio: ${(e as Error).message}`,
|
message: `Error deleting servizio from annuncio: ${(e as Error).message}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Loading…
Add table
Reference in a new issue