From 8fe0b6636d2c04f841edc641bf4d127314d90cca Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Tue, 21 Oct 2025 18:42:03 +0200 Subject: [PATCH] Refactor TypeScript schemas and enums for consistency and readability - Updated enum definitions in PaymentStatusEnum and TipologiaPosizioneEnum to use single quotes and consistent formatting. - Refactored Payments, Prezziario, Ratelimiter, Servizio, and other schema files to ensure consistent indentation and formatting. - Added `updated_at` field to various queries in interests and servizio controllers. - Removed unused imageCache utility file. --- apps/backend/queries/annunci.go | 8 +- apps/infoalloggi/next.config.ts | 4 - .../src/components/annunci_grid.tsx | 1 + .../src/components/annunci_map.tsx | 3 +- .../src/components/annuncio_card.tsx | 21 +- .../src/components/servizio/annuncio_card.tsx | 62 ++-- .../src/components/servizio/main.tsx | 284 +----------------- .../components/servizio/servizio_actions.tsx | 29 -- .../src/components/videoPlayer.tsx | 7 +- .../src/forms/FormEditAnnuncio.tsx | 2 + apps/infoalloggi/src/pages/annuncio/[cod].tsx | 10 +- apps/infoalloggi/src/schemas/Database.ts | 2 +- .../infoalloggi/src/schemas/public/Annunci.ts | 128 ++++---- .../infoalloggi/src/schemas/public/BanType.ts | 10 +- .../infoalloggi/src/schemas/public/Banlist.ts | 12 +- .../infoalloggi/src/schemas/public/Banners.ts | 30 +- apps/infoalloggi/src/schemas/public/Chats.ts | 14 +- .../src/schemas/public/ChatsEtichette.ts | 14 +- apps/infoalloggi/src/schemas/public/Emails.ts | 14 +- .../src/schemas/public/Etichette.ts | 14 +- .../src/schemas/public/EventQueue.ts | 16 +- apps/infoalloggi/src/schemas/public/Flags.ts | 8 +- .../src/schemas/public/GenericStatusEnum.ts | 8 +- .../src/schemas/public/Messages.ts | 24 +- .../src/schemas/public/MiogestImagesRef.ts | 14 +- .../src/schemas/public/OrderTypeEnum.ts | 10 +- apps/infoalloggi/src/schemas/public/Ordini.ts | 38 +-- .../src/schemas/public/PaymentStatusEnum.ts | 8 +- .../src/schemas/public/Payments.ts | 42 ++- .../src/schemas/public/Prezziario.ts | 36 +-- .../src/schemas/public/PublicSchema.ts | 96 +++--- .../src/schemas/public/Ratelimiter.ts | 8 +- .../src/schemas/public/Servizio.ts | 74 ++--- .../src/schemas/public/ServizioAnnunci.ts | 86 ++---- .../src/schemas/public/ServizioInteressi.ts | 10 +- .../src/schemas/public/Storageindex.ts | 20 +- .../src/schemas/public/TempTokens.ts | 12 +- .../src/schemas/public/TestiEStringhe.ts | 14 +- .../schemas/public/TipologiaPosizioneEnum.ts | 6 +- apps/infoalloggi/src/schemas/public/Users.ts | 46 ++- .../src/schemas/public/UsersAnagrafica.ts | 60 ++-- .../src/schemas/public/UsersStorage.ts | 10 +- .../src/server/api/routers/interests.ts | 1 + .../server/controllers/annunci.controller.ts | 3 + .../server/controllers/servizio.controller.ts | 21 +- apps/infoalloggi/src/utils/imageCache.ts | 1 - 46 files changed, 451 insertions(+), 890 deletions(-) delete mode 100644 apps/infoalloggi/src/utils/imageCache.ts diff --git a/apps/backend/queries/annunci.go b/apps/backend/queries/annunci.go index ef11760..84ff619 100644 --- a/apps/backend/queries/annunci.go +++ b/apps/backend/queries/annunci.go @@ -89,7 +89,8 @@ func AnnunciInsert(annunci typesdefs.AnnunciParsed, resetAllBeforeUpdate bool) e og_url = $48, disponibile_da = $49, permanenza = $50, - persone = $51 + persone = $51, + updated_at = NOW() WHERE codice = $47 `, annuncio.Locatore, annuncio.Numero, annuncio.Idlocatore, annuncio.Email, annuncio.Creato_il, annuncio.Modificato_il, @@ -157,9 +158,10 @@ func AnnunciInsert(annunci typesdefs.AnnunciParsed, resetAllBeforeUpdate bool) e og_url, disponibile_da, permanenza, - persone + persone, + updated_at ) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $50, $51) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $50, $51, NOW()) `, annuncio.Locatore, annuncio.Numero, annuncio.Idlocatore, annuncio.Email, annuncio.Creato_il, annuncio.Modificato_il, annuncio.Indirizzo, annuncio.Civico, annuncio.Comune, annuncio.Cap, diff --git a/apps/infoalloggi/next.config.ts b/apps/infoalloggi/next.config.ts index 6af8d10..8f3e88b 100644 --- a/apps/infoalloggi/next.config.ts +++ b/apps/infoalloggi/next.config.ts @@ -21,10 +21,6 @@ async function createNextConfig(): Promise { // esmExternals: "loose", // This if react-pdf gives compilation issues }, - env: { - NEXT_PUBLIC_BUILD_ID: Math.random().toString(36).slice(2, 8), - }, - devIndicators: false, headers: async () => { return [ diff --git a/apps/infoalloggi/src/components/annunci_grid.tsx b/apps/infoalloggi/src/components/annunci_grid.tsx index 65914aa..91fdda8 100644 --- a/apps/infoalloggi/src/components/annunci_grid.tsx +++ b/apps/infoalloggi/src/components/annunci_grid.tsx @@ -27,6 +27,7 @@ export const AnnunciGrid = ({ pagedata }: { pagedata: AnnuncioRicerca[] }) => { titolo_en: annuncio.titolo_en, titolo_it: annuncio.titolo_it, })} + updated_at={annuncio.updated_at} videos={annuncio.url_video || undefined} /> ))} diff --git a/apps/infoalloggi/src/components/annunci_map.tsx b/apps/infoalloggi/src/components/annunci_map.tsx index e3ea7c6..74f10b8 100644 --- a/apps/infoalloggi/src/components/annunci_map.tsx +++ b/apps/infoalloggi/src/components/annunci_map.tsx @@ -16,7 +16,6 @@ import { useTranslation } from "~/providers/I18nProvider"; import { useRicerca } from "~/providers/RicercaProvider"; import type { AnnuncioRicercaWPosition } from "~/server/controllers/annunci.controller"; import { api } from "~/utils/api"; -import { CacheKey } from "~/utils/imageCache"; const MapComp = dynamic(() => import("~/components/map/Map"), { ssr: false, @@ -124,7 +123,7 @@ const SelectedComp = memo( alt="a" className="size-24 rounded-md object-cover sm:size-40" height={500} - src={`${selected.url_immagini[0]}?${CacheKey}`} + src={`${selected.url_immagini[0]}?${selected.updated_at?.toString() || new Date().toString()}`} width={500} /> ) : ( diff --git a/apps/infoalloggi/src/components/annuncio_card.tsx b/apps/infoalloggi/src/components/annuncio_card.tsx index cb2e93b..8f1d323 100644 --- a/apps/infoalloggi/src/components/annuncio_card.tsx +++ b/apps/infoalloggi/src/components/annuncio_card.tsx @@ -20,7 +20,7 @@ import { import { camereTesti, handleConsegna } from "~/lib/annuncio_details"; import { cn, formatCurrency } from "~/lib/utils"; import { useTranslation } from "~/providers/I18nProvider"; -import { CacheKey } from "~/utils/imageCache"; + import { VideoPlayer } from "./videoPlayer"; type CardAnnuncioProps = { @@ -38,6 +38,7 @@ type CardAnnuncioProps = { stato: string | null; className?: string; videos?: string[] | undefined; + updated_at: Date | null; }; export const CardAnnuncio = ({ @@ -55,6 +56,7 @@ export const CardAnnuncio = ({ stato, className, videos, + updated_at, }: CardAnnuncioProps) => { const { t } = useTranslation(); @@ -93,7 +95,7 @@ export const CardAnnuncio = ({ } height={400} priority={idx === 0} - src={`${img}?${CacheKey}`} + src={`${img}?${updated_at?.toString() || new Date().toString()}`} width={800} /> @@ -113,10 +115,11 @@ export const CardAnnuncio = ({ }} > ); @@ -233,10 +236,12 @@ export const CarouselAnnuncio = ({ single, immagini, videos, + updated_at, }: { single?: boolean; immagini: string[] | null; videos: string[] | null; + updated_at: Date | null; }) => { const [openModal, setOpenModal] = useState(false); const [idxModal, setIdxModal] = useState(0); @@ -269,7 +274,7 @@ export const CarouselAnnuncio = ({ height={400} onClick={() => handleOpenModal(idx)} priority={idx === 0} - src={`${img}?${CacheKey}`} + src={`${img}?${updated_at?.toString() || new Date().toString()}`} width={800} /> @@ -354,9 +360,10 @@ export const CarouselAnnuncio = ({ key={`carousel-videoplayer-${video}`} > ); diff --git a/apps/infoalloggi/src/components/servizio/annuncio_card.tsx b/apps/infoalloggi/src/components/servizio/annuncio_card.tsx index 615393d..a4bbdea 100644 --- a/apps/infoalloggi/src/components/servizio/annuncio_card.tsx +++ b/apps/infoalloggi/src/components/servizio/annuncio_card.tsx @@ -29,8 +29,23 @@ import { cn, formatCurrency } from "~/lib/utils"; import { useTranslation } from "~/providers/I18nProvider"; import { useServizioAnnuncio } from "~/providers/ServizioProvider"; import type { Annunci } from "~/schemas/public/Annunci"; -import { CacheKey } from "~/utils/imageCache"; +type AnnuncioData = Pick< + Annunci, + | "id" + | "codice" + | "prezzo" + | "desc_en" + | "desc_it" + | "url_immagini" + | "titolo_en" + | "titolo_it" + | "tipo" + | "consegna" + | "stato" + | "web" + | "updated_at" +>; export const AnnuncioCard = ({ className }: { className?: string }) => { const { data } = useServizioAnnuncio(); @@ -38,7 +53,10 @@ export const AnnuncioCard = ({ className }: { className?: string }) => { } className={className} - data={data} + data={{ + ...data, + updated_at: data.updated_at ? new Date(data.updated_at) : null, + }} interactions={} /> ); @@ -52,21 +70,7 @@ export const BasicAnnuncioCard = ({ actions?: React.ReactNode; interactions?: React.ReactNode; className?: string; - data: Pick< - Annunci, - | "id" - | "codice" - | "prezzo" - | "desc_en" - | "desc_it" - | "url_immagini" - | "titolo_en" - | "titolo_it" - | "tipo" - | "consegna" - | "stato" - | "web" - >; + data: AnnuncioData; }) => { const { t } = useTranslation(); @@ -85,7 +89,7 @@ export const BasicAnnuncioCard = ({ priority src={ (data.url_immagini && - `/go-api/images/get/${data.url_immagini[0]}?${CacheKey}`) || + `/go-api/images/get/${data.url_immagini[0]}?${data.updated_at?.toString() || new Date().toString()}`) || "/fallback-image.png" } width={1920} @@ -148,25 +152,7 @@ const TipoBadge = ({ tipo }: { tipo: Annunci["tipo"] }) => { ); }; -const AnnuncioDettaglio = ({ - data, -}: { - data: Pick< - Annunci, - | "id" - | "codice" - | "prezzo" - | "desc_en" - | "desc_it" - | "url_immagini" - | "titolo_en" - | "titolo_it" - | "tipo" - | "consegna" - | "stato" - | "web" - >; -}) => { +const AnnuncioDettaglio = ({ data }: { data: AnnuncioData }) => { const { locale, t } = useTranslation(); return ( @@ -200,7 +186,7 @@ const AnnuncioDettaglio = ({ className={"h-80 w-full object-contain sm:h-[35rem]"} height={200} priority={idx === 0} - src={`/go-api/images/get/${img}?${CacheKey}`} + src={`/go-api/images/get/${img}?${data.updated_at?.toString() || new Date().toString()}`} width={400} /> diff --git a/apps/infoalloggi/src/components/servizio/main.tsx b/apps/infoalloggi/src/components/servizio/main.tsx index ae9eb5c..10a72db 100644 --- a/apps/infoalloggi/src/components/servizio/main.tsx +++ b/apps/infoalloggi/src/components/servizio/main.tsx @@ -3,14 +3,10 @@ import Link from "next/link"; import { useRouter } from "next/router"; import { useEffect } from "react"; import toast from "react-hot-toast"; - import { AnnuncioCard } from "~/components/servizio/annuncio_card"; import { SaldoButton } from "~/components/servizio/interactions"; import { ServizioDuration } from "~/components/servizio/service-duration-display"; -import { - ServizioActions, - ServizioActions2, -} from "~/components/servizio/servizio_actions"; +import { ServizioActions2 } from "~/components/servizio/servizio_actions"; import { Button } from "~/components/ui/button"; import { Card, @@ -23,11 +19,8 @@ import { Progress } from "~/components/ui/progress"; import { cn } from "~/lib/utils"; import { ServizioAnnuncioProvider, - ServizioProvider, useServizio, } from "~/providers/ServizioProvider"; -import type { UsersId } from "~/schemas/public/Users"; -import type { ServizioData } from "~/server/controllers/servizio.controller"; import { api } from "~/utils/api"; import { AnnunciCompatibili, @@ -35,27 +28,6 @@ import { AnnunciSelezionati, } from "./servizio_annunci_accordions"; -export const ServizioContainer = ({ - servizio, - userId, - isAdmin, -}: { - servizio: ServizioData; - userId: UsersId; - isAdmin: boolean; -}) => { - return ( - - - - ); -}; - const ServizioCard = ({ cardClassName, header, @@ -299,257 +271,3 @@ export const ServizioContent = () => { /> ); }; - -const ServizioMain = () => { - const { servizio, isAdmin, userId } = useServizio(); - const utils = api.useUtils(); - const { mutate: updateServizio } = api.servizio.updateServizio.useMutation({ - onError: (error) => { - toast.error(error.message); - }, - onSuccess: async () => { - toast.success("Servizio modificato con successo"); - await utils.servizio.getAllServizioAnnunci.invalidate({ userId }); - }, - }); - - const router = useRouter(); - useEffect(() => { - const id = router.asPath.split("#")[1]; - if (id) { - document.getElementById(id)?.scrollIntoView({ - behavior: "smooth", - }); - } - }, []); - - if (servizio.isInterrotto) { - return ( - -

Servizio interrotto

-

- Non è possibile riutilizzare questo servizio, poichè è stato - interrotto. -

- - } - header={ - <> -
- - - Cerco Affitto {servizio.tipologia} - - - -

- aggiunto il{" "} - {servizio.created_at.toLocaleDateString("it", { - day: "2-digit", - month: "2-digit", - year: "numeric", - })} -

-
-
- - } - /> - ); - } - - if (!servizio.isOkAcconto || servizio.decorrenza === null) { - return ( - -
- - - - {isAdmin && ( - - )} -
- {isAdmin && } - - } - header={ - <> -
- - - Cerco Affitto {servizio.tipologia} - - -

Servizio non attivo

-
-
- - - } - /> - ); - } - const annuncioConfermato = servizio.annunci.filter( - (a) => a.accettato_conferma_at !== null, - ); - - if (servizio.isOkSaldo) { - return ( - - {annuncioConfermato.map((data) => { - return ( - - - - ); - })} - - } - header={ - <> -
- - - Cerco Affitto {servizio.tipologia} - - - -

- aggiunto il{" "} - {servizio.created_at.toLocaleDateString("it", { - day: "2-digit", - month: "2-digit", - year: "numeric", - })} -

-
-
- - - - } - /> - ); - } - - const openContattiCount = servizio.annunci.filter( - (a) => a.open_contatti_at !== null, - ).length; - - const annunciInConferma = servizio.annunci.filter( - (a) => a.user_confirmed_at !== null, - ); - const annunciNotInConferma = servizio.annunci.filter( - (a) => a.user_confirmed_at === null, - ); - - return ( - -
-
-
- - Contatti sbloccati -
- {openContattiCount} / 10 -
- -
- - - - {annuncioConfermato.length > 0 && ( -
-
- - Saldi in attesa: -
- {servizio.annunci - .filter((a) => a.accettato_conferma_at !== null) - .map((a) => ( -
-

- {a.codice} - confermato il:{" "} - {/** biome-ignore lint/style/noNonNullAssertion: */} - {new Date(a.accettato_conferma_at!).toLocaleDateString( - "it", - { - day: "2-digit", - hour: "2-digit", - minute: "2-digit", - month: "2-digit", - year: "numeric", - }, - )} -

- -
- ))} -
- )} - -
- - - -
- - } - header={ - <> -
- - - Cerco Affitto {servizio.tipologia} - - - -

- aggiunto il{" "} - {servizio.created_at.toLocaleDateString("it", { - day: "2-digit", - month: "2-digit", - year: "numeric", - })} -

-
-
- - - - } - /> - ); -}; diff --git a/apps/infoalloggi/src/components/servizio/servizio_actions.tsx b/apps/infoalloggi/src/components/servizio/servizio_actions.tsx index 9168a03..e0c7826 100644 --- a/apps/infoalloggi/src/components/servizio/servizio_actions.tsx +++ b/apps/infoalloggi/src/components/servizio/servizio_actions.tsx @@ -50,35 +50,6 @@ import type { ServizioServizioId } from "~/schemas/public/Servizio"; import type { UsersId } from "~/schemas/public/Users"; import { api } from "~/utils/api"; -export const ServizioActions = () => { - const { servizio, isAdmin, userId } = useServizio(); - - const canUserEdit = - servizio.isOkAcconto && - servizio.decorrenza !== null && - !servizio.annunci.some((a) => a.user_confirmed_at !== null); - - if (!isAdmin && !canUserEdit) { - return null; // If the user is not an admin and cannot edit, do not render the actions - } - return ( -
- {(isAdmin || canUserEdit) && ( - <> - - - - )} - {isAdmin && ( - <> - - - - )} -
- ); -}; - export const ServizioActions2 = () => { const { servizio, isAdmin, userId } = useServizio(); diff --git a/apps/infoalloggi/src/components/videoPlayer.tsx b/apps/infoalloggi/src/components/videoPlayer.tsx index ba0f45d..3de4f2f 100644 --- a/apps/infoalloggi/src/components/videoPlayer.tsx +++ b/apps/infoalloggi/src/components/videoPlayer.tsx @@ -5,7 +5,6 @@ import { Play } from "lucide-react"; import Image from "next/image"; import { useEffect, useRef, useState } from "react"; import { cn } from "~/lib/utils"; -import { CacheKey } from "~/utils/imageCache"; interface VideoPlayerProps { coverImage: string; @@ -13,6 +12,7 @@ interface VideoPlayerProps { title?: string; aspectRatio?: "square" | "video" | "vertical"; className?: string; + cacheKey: string; } export function VideoPlayer({ @@ -21,6 +21,7 @@ export function VideoPlayer({ title, aspectRatio = "video", className, + cacheKey, }: VideoPlayerProps) { const [isPlaying, setIsPlaying] = useState(false); const videoRef = useRef(null); @@ -63,7 +64,7 @@ export function VideoPlayer({ className="object-cover" fill priority - src={`${coverImage}?${CacheKey}` || "/fallback-video.png"} + src={`${coverImage}?${cacheKey}` || "/fallback-video.png"} />
setIsPlaying(false)} - src={`${videoSrc}?${CacheKey}`} + src={`${videoSrc}?${cacheKey}`} > Your browser does not support the video tag. diff --git a/apps/infoalloggi/src/forms/FormEditAnnuncio.tsx b/apps/infoalloggi/src/forms/FormEditAnnuncio.tsx index b5db18c..3502d53 100644 --- a/apps/infoalloggi/src/forms/FormEditAnnuncio.tsx +++ b/apps/infoalloggi/src/forms/FormEditAnnuncio.tsx @@ -236,6 +236,7 @@ export const AnnuncioEditForm = ({ data }: { data: Annunci }) => { Annuncio {data.codice} + {data.updated_at?.toLocaleString("it-IT")}