Refactor getAnnunciMetaByCod to remove unused url_immagini and simplify ogImage handling

This commit is contained in:
Marco Pedone 2025-08-08 13:44:52 +02:00
parent 7bfef22f80
commit 0744d032a3

View file

@ -1,6 +1,6 @@
import type { Annunci, AnnunciId } from "~/schemas/public/Annunci"; import type { Annunci, AnnunciId } from "~/schemas/public/Annunci";
import { TRPCError } from "@trpc/server"; import { TRPCError } from "@trpc/server";
import { createSrc, createSrcset } from "~/server/services/imageServer"; import { createSrcset } from "~/server/services/imageServer";
import { AnnuncioObjectWithImages } from "~/server/services/annunci.service"; import { AnnuncioObjectWithImages } from "~/server/services/annunci.service";
import { zAnnuncioId } from "~/server/utils/zod_types"; import { zAnnuncioId } from "~/server/utils/zod_types";
import { z } from "zod/v4"; import { z } from "zod/v4";
@ -93,7 +93,7 @@ export const getAnnunciMetaByCod = async ({ cod }: { cod: string }) => {
try { try {
const annuncio = await db const annuncio = await db
.selectFrom("annunci") .selectFrom("annunci")
.select(["titolo_it", "desc_it", "url_immagini", "og_url"]) .select(["titolo_it", "desc_it", "og_url"])
.where("annunci.web", "=", true) .where("annunci.web", "=", true)
.where("codice", "=", cod) .where("codice", "=", cod)
.executeTakeFirst(); .executeTakeFirst();
@ -105,10 +105,7 @@ export const getAnnunciMetaByCod = async ({ cod }: { cod: string }) => {
} }
return { return {
ogImage: ogImage: annuncio.og_url || "",
annuncio.url_immagini && annuncio.url_immagini[0]
? createSrc(annuncio.url_immagini[0])
: annuncio.og_url || "",
title: annuncio.titolo_it || "", title: annuncio.titolo_it || "",
description: annuncio.desc_it || "", description: annuncio.desc_it || "",
ogUrl: env.NEXT_PUBLIC_BASE_URL + "/annuncio/" + cod, ogUrl: env.NEXT_PUBLIC_BASE_URL + "/annuncio/" + cod,