diff --git a/apps/infoalloggi/src/components/servizio/main.tsx b/apps/infoalloggi/src/components/servizio/main.tsx
index 5600352..8de73c3 100644
--- a/apps/infoalloggi/src/components/servizio/main.tsx
+++ b/apps/infoalloggi/src/components/servizio/main.tsx
@@ -163,7 +163,7 @@ const ServizioMain = () => {
>
}
content={
- <>
+
{
Attiva Manualmente (Azione Admin)
)}
- >
+
}
/>
);
diff --git a/apps/infoalloggi/src/components/servizio/servizio_annunci_accordions.tsx b/apps/infoalloggi/src/components/servizio/servizio_annunci_accordions.tsx
index fd1964d..a7d327b 100644
--- a/apps/infoalloggi/src/components/servizio/servizio_annunci_accordions.tsx
+++ b/apps/infoalloggi/src/components/servizio/servizio_annunci_accordions.tsx
@@ -17,9 +17,10 @@ import {
ServizioAnnuncioProvider,
useServizio,
} from "~/providers/ServizioProvider";
-import { ExternalLink } from "lucide-react";
+import { ExternalLink, Trash2 } from "lucide-react";
import Link from "next/link";
import type { ServizioData } from "~/server/controllers/servizio.controller";
+import toast from "react-hot-toast";
export const AnnunciInConferma = ({
annunci,
@@ -163,6 +164,14 @@ export const AnnunciRichiesti = ({ userId }: { userId: UsersId }) => {
const { data, isLoading } = api.intrests.getUserInterestsAnnunci.useQuery({
userId,
});
+
+ const utils = api.useUtils();
+ const { mutate: deleteAnnuncio } = api.intrests.removeIntrest.useMutation({
+ onSuccess: async () => {
+ await utils.intrests.getUserInterestsAnnunci.invalidate({ userId });
+ toast.success("Annuncio rimosso con successo");
+ },
+ });
if (isLoading) return Loading...
;
if (!data || data.length === 0) return null;
@@ -190,7 +199,16 @@ export const AnnunciRichiesti = ({ userId }: { userId: UsersId }) => {
data={a}
key={a.id}
>
-
+
);
})
diff --git a/apps/infoalloggi/src/server/api/routers/interests.ts b/apps/infoalloggi/src/server/api/routers/interests.ts
index e6d47c4..93f2d49 100644
--- a/apps/infoalloggi/src/server/api/routers/interests.ts
+++ b/apps/infoalloggi/src/server/api/routers/interests.ts
@@ -107,27 +107,39 @@ export const intrestsRouter = createTRPCRouter({
}),
)
.query(async ({ input, ctx }) => {
- const interests = await GetUserInterests(input.userId || ctx.session.id);
-
- return await db
- .selectFrom("annunci")
- .select([
- "annunci.id",
- "annunci.codice",
- "annunci.prezzo",
- "annunci.desc_en",
- "annunci.desc_it",
- "annunci.url_immagini",
- "annunci.titolo_en",
- "annunci.titolo_it",
- "annunci.tipo",
- "annunci.consegna",
- "annunci.stato",
- "annunci.web",
- ])
- .where("web", "=", true)
- .where("stato", "!=", "Sospeso")
- .where("annunci.id", "in", interests)
- .execute();
+ try {
+ const interests = await GetUserInterests(
+ input.userId || ctx.session.id,
+ );
+ if (!interests || interests.length === 0) {
+ return [];
+ }
+ const annunci = await db
+ .selectFrom("annunci")
+ .select([
+ "annunci.id",
+ "annunci.codice",
+ "annunci.prezzo",
+ "annunci.desc_en",
+ "annunci.desc_it",
+ "annunci.url_immagini",
+ "annunci.titolo_en",
+ "annunci.titolo_it",
+ "annunci.tipo",
+ "annunci.consegna",
+ "annunci.stato",
+ "annunci.web",
+ ])
+ .where("web", "=", true)
+ .where("stato", "!=", "Sospeso")
+ .where("annunci.id", "in", interests)
+ .execute();
+ return annunci;
+ } catch (e) {
+ throw new TRPCError({
+ code: "INTERNAL_SERVER_ERROR",
+ message: `Errore durante il recupero degli annunci: ${(e as Error).message}`,
+ });
+ }
}),
});
diff --git a/apps/infoalloggi/src/server/db.ts b/apps/infoalloggi/src/server/db.ts
index be3ead6..47ad67d 100644
--- a/apps/infoalloggi/src/server/db.ts
+++ b/apps/infoalloggi/src/server/db.ts
@@ -1,8 +1,10 @@
import { Pool } from "pg";
import {
DeduplicateJoinsPlugin,
+ HandleEmptyInListsPlugin,
Kysely,
PostgresDialect,
+ replaceWithNoncontingentExpression,
type LogEvent,
type Transaction,
} from "kysely";
@@ -42,7 +44,12 @@ export const db = new Kysely({
//plugins: [new SerializePlugin()]
//plugins: [new CamelCasePlugin()],
- plugins: [new DeduplicateJoinsPlugin()],
+ plugins: [
+ new DeduplicateJoinsPlugin(),
+ new HandleEmptyInListsPlugin({
+ strategy: replaceWithNoncontingentExpression,
+ }),
+ ],
});
// eslint-disable-next-line @typescript-eslint/no-unused-vars