From 4408295f56af0a3b3fe3c36d4ba4523e090fcede Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Tue, 11 Nov 2025 15:41:07 +0100 Subject: [PATCH] feat: add admin override switch for ignoring service preferences in AnnunciCompatibili dialog --- .../servizio/compatibili_dialog.tsx | 29 +++++++++++++++---- .../src/server/api/routers/servizio.ts | 3 +- .../server/controllers/servizio.controller.ts | 22 +++++++++----- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/apps/infoalloggi/src/components/servizio/compatibili_dialog.tsx b/apps/infoalloggi/src/components/servizio/compatibili_dialog.tsx index 6caa703..96584a9 100644 --- a/apps/infoalloggi/src/components/servizio/compatibili_dialog.tsx +++ b/apps/infoalloggi/src/components/servizio/compatibili_dialog.tsx @@ -1,5 +1,6 @@ import { ExternalLink, UnfoldVertical } from "lucide-react"; import Link from "next/link"; +import { useState } from "react"; import { replaceWithBr } from "~/lib/newlineToBr"; import { cn, formatCurrency } from "~/lib/utils"; import { useTranslation } from "~/providers/I18nProvider"; @@ -22,11 +23,15 @@ import { DialogTitle, DialogTrigger, } from "../ui/dialog"; +import { Label } from "../ui/label"; +import { Switch } from "../ui/switch"; export const AnnunciCompatibili = () => { - const { servizioId } = useServizio(); + const { servizioId, isAdmin } = useServizio(); + const [adminOverride, setAdminOverride] = useState(false); const { data, isLoading } = api.servizio.getCompatibileAnnunci.useQuery({ servizioId, + adminOverride, }); return ( @@ -35,11 +40,25 @@ export const AnnunciCompatibili = () => { Esplora Annunci Compatibili - - - + + + Annunci compatibili con le preferenze del servizio + {isAdmin && ( +
+ + + +
+ )}
@@ -55,7 +74,7 @@ export const AnnunciCompatibili = () => {
) : ( -
+
{data.map((annuncio) => (
{ - return await getCompatibileAnnunci(input.servizioId); + return await getCompatibileAnnunci({ ...input }); }), getOrdineById: protectedProcedure .input( diff --git a/apps/infoalloggi/src/server/controllers/servizio.controller.ts b/apps/infoalloggi/src/server/controllers/servizio.controller.ts index 2f92364..9600918 100644 --- a/apps/infoalloggi/src/server/controllers/servizio.controller.ts +++ b/apps/infoalloggi/src/server/controllers/servizio.controller.ts @@ -1577,9 +1577,13 @@ export const SendContactEmail = async ({ } }; -export const getCompatibileAnnunci = async ( - servizioId: ServizioServizioId, -): Promise => { +export const getCompatibileAnnunci = async ({ + servizioId, + adminOverride = false, +}: { + servizioId: ServizioServizioId; + adminOverride?: boolean; +}): Promise => { try { const servizio = await getServizioById(servizioId); if (!servizio) { @@ -1628,8 +1632,12 @@ export const getCompatibileAnnunci = async ( .selectFrom("servizio_annunci") .select("annunci_id") .where("servizio_id", "=", servizioId), - ) - .where("prezzo", "<=", servizio.budget * 1e2 * 1.2); // Allow 20% margin + ); + if (adminOverride) { + return await qry.execute(); + } + + qry = qry.where("prezzo", "<=", servizio.budget * 1e2 * 1.2); // Allow 20% margin const month = new Date().getMonth() + 1; // Months are 0-indexed in JS if (servizio.entromese === month) { @@ -1647,9 +1655,7 @@ export const getCompatibileAnnunci = async ( qry = qry.where("consegna", "=", servizio.entromese); } - const annunci = await qry.execute(); - - return annunci; + return await qry.execute(); } catch (e) { throw new TRPCError({ code: "INTERNAL_SERVER_ERROR",