2025-08-28 18:27:07 +02:00
|
|
|
import { TRPCError } from "@trpc/server";
|
2025-10-27 17:58:42 +01:00
|
|
|
import { jsonArrayFrom } from "kysely/helpers/postgres";
|
2025-10-20 16:22:20 +02:00
|
|
|
import { env } from "~/env";
|
2025-08-28 12:37:32 +02:00
|
|
|
import type {
|
2025-08-28 18:27:07 +02:00
|
|
|
Annunci,
|
|
|
|
|
AnnunciId,
|
|
|
|
|
AnnunciUpdate,
|
2025-08-28 12:37:32 +02:00
|
|
|
} from "~/schemas/public/Annunci";
|
2025-10-27 17:58:42 +01:00
|
|
|
import type { ImagesRefs } from "~/schemas/public/ImagesRefs";
|
2025-08-04 17:45:44 +02:00
|
|
|
import type { ServizioServizioId } from "~/schemas/public/Servizio";
|
2025-08-28 18:27:07 +02:00
|
|
|
import { db } from "~/server/db";
|
2025-10-17 19:14:27 +02:00
|
|
|
import { revalidate } from "../utils/revalidationHelper";
|
2025-08-04 17:45:44 +02:00
|
|
|
|
|
|
|
|
// const ratelimit = new RateLimiterHandler({
|
|
|
|
|
// windowSize: 10,
|
|
|
|
|
// maxRequests: 10,
|
|
|
|
|
// analytics: true,
|
|
|
|
|
// });
|
2025-10-27 17:58:42 +01:00
|
|
|
export type AnnunciWithImages = Annunci & {
|
|
|
|
|
images: Pick<ImagesRefs, "img" | "thumb">[];
|
|
|
|
|
};
|
2025-08-04 17:45:44 +02:00
|
|
|
|
|
|
|
|
export const getAnnunciListHandler = async (): Promise<
|
2025-08-28 18:27:07 +02:00
|
|
|
Pick<
|
|
|
|
|
Annunci,
|
|
|
|
|
"id" | "codice" | "titolo_it" | "comune" | "tipo" | "locatore" | "stato"
|
|
|
|
|
>[]
|
2025-08-04 17:45:44 +02:00
|
|
|
> => {
|
2025-08-28 18:27:07 +02:00
|
|
|
try {
|
|
|
|
|
return await db
|
|
|
|
|
.selectFrom("annunci")
|
|
|
|
|
.select([
|
|
|
|
|
"id",
|
|
|
|
|
"codice",
|
|
|
|
|
"titolo_it",
|
|
|
|
|
"comune",
|
|
|
|
|
"tipo",
|
|
|
|
|
"locatore",
|
|
|
|
|
"stato",
|
|
|
|
|
])
|
|
|
|
|
.execute();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw new TRPCError({
|
|
|
|
|
code: "INTERNAL_SERVER_ERROR",
|
|
|
|
|
message: `Errore query getAllRaw: ${(e as Error).message}`,
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getCodici_AnnunciHandler = async (): Promise<string[]> => {
|
2025-08-28 18:27:07 +02:00
|
|
|
try {
|
|
|
|
|
const codici = await db
|
|
|
|
|
.selectFrom("annunci")
|
|
|
|
|
.select("codice")
|
|
|
|
|
.where("annunci.web", "=", true)
|
|
|
|
|
.where("stato", "!=", "Sospeso")
|
|
|
|
|
.execute();
|
|
|
|
|
if (!codici) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
return codici.map((c) => c.codice);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw new TRPCError({
|
|
|
|
|
code: "INTERNAL_SERVER_ERROR",
|
|
|
|
|
message: `Errore query getCodici: ${(e as Error).message}`,
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getAnnunciByCod = async ({
|
2025-08-28 18:27:07 +02:00
|
|
|
cod,
|
2025-08-04 17:45:44 +02:00
|
|
|
}: {
|
2025-08-28 18:27:07 +02:00
|
|
|
cod: string;
|
2025-10-27 17:58:42 +01:00
|
|
|
}): Promise<AnnunciWithImages | null> => {
|
2025-08-28 18:27:07 +02:00
|
|
|
try {
|
|
|
|
|
const annuncio = await db
|
|
|
|
|
.selectFrom("annunci")
|
|
|
|
|
.selectAll()
|
2025-10-27 17:58:42 +01:00
|
|
|
.select((eb) =>
|
|
|
|
|
jsonArrayFrom(
|
|
|
|
|
eb
|
|
|
|
|
.selectFrom("images_refs")
|
|
|
|
|
.whereRef("images_refs.codice", "=", "annunci.codice")
|
|
|
|
|
.select(["img", "thumb"])
|
|
|
|
|
.orderBy("images_refs.ordine", "asc"),
|
|
|
|
|
).as("images"),
|
|
|
|
|
)
|
2025-08-28 18:27:07 +02:00
|
|
|
.where("annunci.web", "=", true)
|
|
|
|
|
.where("codice", "=", cod)
|
|
|
|
|
.executeTakeFirst();
|
2025-08-27 10:56:13 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
if (!annuncio) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-10-27 17:58:42 +01:00
|
|
|
return annuncio;
|
2025-08-28 18:27:07 +02:00
|
|
|
} catch (e) {
|
|
|
|
|
throw new TRPCError({
|
2025-08-29 16:18:32 +02:00
|
|
|
cause: (e as Error).cause,
|
2025-08-28 18:27:07 +02:00
|
|
|
code: "INTERNAL_SERVER_ERROR",
|
|
|
|
|
message: `Errore query getAnnunciByCod: ${(e as Error).message}`,
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-08-08 13:30:21 +02:00
|
|
|
};
|
|
|
|
|
export const getAnnunciMetaByCod = async ({ cod }: { cod: string }) => {
|
2025-08-28 18:27:07 +02:00
|
|
|
try {
|
|
|
|
|
const annuncio = await db
|
|
|
|
|
.selectFrom("annunci")
|
2025-10-27 17:58:42 +01:00
|
|
|
.select((eb) => [
|
|
|
|
|
"titolo_it",
|
|
|
|
|
"desc_it",
|
|
|
|
|
jsonArrayFrom(
|
|
|
|
|
eb
|
|
|
|
|
.selectFrom("images_refs")
|
|
|
|
|
.whereRef("images_refs.codice", "=", "annunci.codice")
|
|
|
|
|
.select(["img", "thumb"])
|
|
|
|
|
.orderBy("images_refs.ordine", "asc"),
|
|
|
|
|
).as("images"),
|
|
|
|
|
])
|
2025-08-28 18:27:07 +02:00
|
|
|
.where("annunci.web", "=", true)
|
|
|
|
|
.where("codice", "=", cod)
|
|
|
|
|
.executeTakeFirst();
|
|
|
|
|
if (!annuncio) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2025-10-07 18:07:57 +02:00
|
|
|
const ogImage =
|
2025-10-27 17:58:42 +01:00
|
|
|
annuncio.images && annuncio.images.length > 0 && annuncio.images[0]
|
|
|
|
|
? `${env.BASE_URL}/storage-api/get/${annuncio.images[0]}?image=true`
|
|
|
|
|
: `${env.BASE_URL}/og.jpg`;
|
2025-08-08 13:30:21 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
return {
|
|
|
|
|
description: annuncio.desc_it || "",
|
2025-10-07 18:07:57 +02:00
|
|
|
ogImage,
|
2025-10-20 16:39:59 +02:00
|
|
|
ogUrl: `${env.BASE_URL}/annuncio/${cod}`,
|
2025-08-29 16:18:32 +02:00
|
|
|
title: annuncio.titolo_it || "",
|
2025-08-28 18:27:07 +02:00
|
|
|
};
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw new TRPCError({
|
|
|
|
|
code: "INTERNAL_SERVER_ERROR",
|
|
|
|
|
message: `Errore query getAnnunciMetaByCod: ${(e as Error).message}`,
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|
|
|
|
|
|
2025-08-29 18:18:37 +02:00
|
|
|
export const getAnnunciById_rawImgUrls = async ({
|
2025-08-28 18:27:07 +02:00
|
|
|
id,
|
2025-08-04 17:45:44 +02:00
|
|
|
}: {
|
2025-08-28 18:27:07 +02:00
|
|
|
id: AnnunciId;
|
2025-10-27 17:58:42 +01:00
|
|
|
}): Promise<AnnunciWithImages | null> => {
|
2025-08-28 18:27:07 +02:00
|
|
|
try {
|
|
|
|
|
const annuncio = await db
|
|
|
|
|
.selectFrom("annunci")
|
|
|
|
|
.selectAll()
|
2025-10-27 17:58:42 +01:00
|
|
|
.select((eb) => [
|
|
|
|
|
jsonArrayFrom(
|
|
|
|
|
eb
|
|
|
|
|
.selectFrom("images_refs")
|
|
|
|
|
.select(["images_refs.img", "images_refs.thumb"])
|
|
|
|
|
.whereRef("images_refs.codice", "=", "annunci.codice")
|
|
|
|
|
.orderBy("images_refs.ordine", "asc"),
|
|
|
|
|
).as("images"),
|
|
|
|
|
])
|
2025-08-28 18:27:07 +02:00
|
|
|
.where("id", "=", id)
|
|
|
|
|
.executeTakeFirst();
|
|
|
|
|
if (!annuncio) {
|
|
|
|
|
throw new TRPCError({
|
|
|
|
|
code: "NOT_FOUND",
|
|
|
|
|
message: "Annuncio non trovato",
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
return annuncio;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw new TRPCError({
|
|
|
|
|
code: "INTERNAL_SERVER_ERROR",
|
|
|
|
|
message: `Errore query getAnnuncioById : ${(e as Error).message}`,
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type AnnuncioRicercaWPosition = AnnuncioRicerca & {
|
2025-08-28 18:27:07 +02:00
|
|
|
lat_secondario: string | null;
|
|
|
|
|
lon_secondario: string | null;
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const get_AnnunciPositionsHandler = async ({
|
2025-08-28 18:27:07 +02:00
|
|
|
tipologia,
|
|
|
|
|
comune,
|
|
|
|
|
consegna,
|
2025-08-04 17:45:44 +02:00
|
|
|
}: {
|
2025-08-28 18:27:07 +02:00
|
|
|
tipologia?: string;
|
|
|
|
|
comune?: string;
|
|
|
|
|
consegna?: number;
|
2025-08-04 17:45:44 +02:00
|
|
|
}): Promise<AnnuncioRicercaWPosition[]> => {
|
2025-08-28 18:27:07 +02:00
|
|
|
try {
|
|
|
|
|
let query = db
|
|
|
|
|
.selectFrom("annunci")
|
2025-10-27 17:58:42 +01:00
|
|
|
.select((eb) => [
|
2025-08-28 18:27:07 +02:00
|
|
|
"id",
|
|
|
|
|
"codice",
|
|
|
|
|
"comune",
|
|
|
|
|
"provincia",
|
|
|
|
|
"prezzo",
|
|
|
|
|
"consegna",
|
|
|
|
|
"numero_camere",
|
|
|
|
|
"mq",
|
|
|
|
|
"tipo",
|
|
|
|
|
"titolo_it",
|
|
|
|
|
"titolo_en",
|
|
|
|
|
"modificato_il",
|
|
|
|
|
"stato",
|
2025-09-01 17:31:19 +02:00
|
|
|
"url_video",
|
2025-08-28 18:27:07 +02:00
|
|
|
"lon_secondario",
|
|
|
|
|
"lat_secondario",
|
2025-10-21 18:42:03 +02:00
|
|
|
"updated_at",
|
2025-11-03 18:49:27 +01:00
|
|
|
"homepage",
|
2025-10-27 17:58:42 +01:00
|
|
|
jsonArrayFrom(
|
|
|
|
|
eb
|
|
|
|
|
.selectFrom("images_refs")
|
|
|
|
|
.whereRef("images_refs.codice", "=", "annunci.codice")
|
|
|
|
|
.select(["img", "thumb"])
|
|
|
|
|
.orderBy("images_refs.ordine", "asc"),
|
|
|
|
|
).as("images"),
|
2025-08-28 18:27:07 +02:00
|
|
|
])
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
.where("web", "=", true)
|
|
|
|
|
.where("stato", "!=", "Sospeso")
|
|
|
|
|
.orderBy("id", "asc");
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
if (tipologia && tipologia !== "") {
|
|
|
|
|
query = query.where("tipo", "=", tipologia);
|
|
|
|
|
}
|
|
|
|
|
if (comune && comune !== "") {
|
|
|
|
|
query = query.where("comune", "like", comune);
|
|
|
|
|
}
|
|
|
|
|
if (consegna) {
|
|
|
|
|
query = query.where("consegna", "=", consegna);
|
|
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
const annunci = await query.execute();
|
|
|
|
|
if (!annunci) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
return annunci;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw new TRPCError({
|
|
|
|
|
code: "INTERNAL_SERVER_ERROR",
|
|
|
|
|
message: `Errore query getAnnunciPositions: ${(e as Error).message}`,
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type AnnuncioRicerca = Pick<
|
2025-08-28 18:27:07 +02:00
|
|
|
Annunci,
|
|
|
|
|
| "id"
|
|
|
|
|
| "codice"
|
|
|
|
|
| "comune"
|
|
|
|
|
| "provincia"
|
|
|
|
|
| "prezzo"
|
|
|
|
|
| "consegna"
|
|
|
|
|
| "numero_camere"
|
|
|
|
|
| "mq"
|
|
|
|
|
| "tipo"
|
|
|
|
|
| "titolo_it"
|
|
|
|
|
| "titolo_en"
|
|
|
|
|
| "modificato_il"
|
|
|
|
|
| "stato"
|
2025-09-01 17:31:19 +02:00
|
|
|
| "url_video"
|
2025-10-21 18:42:03 +02:00
|
|
|
| "updated_at"
|
2025-11-03 18:49:27 +01:00
|
|
|
| "homepage"
|
2025-10-27 17:58:42 +01:00
|
|
|
> & {
|
|
|
|
|
images: Pick<ImagesRefs, "img" | "thumb">[];
|
|
|
|
|
};
|
2025-08-04 17:45:44 +02:00
|
|
|
|
|
|
|
|
export const getCursor_AnnunciHandler = async ({
|
2025-08-28 18:27:07 +02:00
|
|
|
page = 0,
|
|
|
|
|
pageSize,
|
|
|
|
|
tipologia,
|
|
|
|
|
comune,
|
|
|
|
|
consegna,
|
|
|
|
|
sort,
|
2025-08-04 17:45:44 +02:00
|
|
|
}: {
|
2025-08-28 18:27:07 +02:00
|
|
|
page?: number;
|
|
|
|
|
pageSize: number;
|
|
|
|
|
tipologia?: string;
|
|
|
|
|
comune?: string;
|
|
|
|
|
consegna?: number;
|
|
|
|
|
sort?: "Recenti" | "Prezzo" | "Consegna" | "Mq";
|
2025-11-03 18:49:27 +01:00
|
|
|
}): Promise<{
|
|
|
|
|
annunci: AnnuncioRicerca[];
|
|
|
|
|
hasMore: boolean;
|
|
|
|
|
}> => {
|
2025-08-28 18:27:07 +02:00
|
|
|
try {
|
|
|
|
|
let query = db
|
|
|
|
|
.selectFrom("annunci")
|
2025-10-27 17:58:42 +01:00
|
|
|
.select((eb) => [
|
2025-08-28 18:27:07 +02:00
|
|
|
"id",
|
|
|
|
|
"codice",
|
|
|
|
|
"comune",
|
|
|
|
|
"provincia",
|
|
|
|
|
"prezzo",
|
|
|
|
|
"consegna",
|
|
|
|
|
"numero_camere",
|
|
|
|
|
"mq",
|
|
|
|
|
"tipo",
|
|
|
|
|
"titolo_it",
|
|
|
|
|
"titolo_en",
|
|
|
|
|
"modificato_il",
|
|
|
|
|
"stato",
|
2025-09-01 17:31:19 +02:00
|
|
|
"url_video",
|
2025-10-21 18:42:03 +02:00
|
|
|
"updated_at",
|
2025-11-03 18:49:27 +01:00
|
|
|
"homepage",
|
2025-10-27 17:58:42 +01:00
|
|
|
jsonArrayFrom(
|
|
|
|
|
eb
|
|
|
|
|
.selectFrom("images_refs")
|
|
|
|
|
.whereRef("images_refs.codice", "=", "annunci.codice")
|
|
|
|
|
.select(["img", "thumb"])
|
|
|
|
|
.orderBy("images_refs.ordine", "asc"),
|
|
|
|
|
).as("images"),
|
2025-08-28 18:27:07 +02:00
|
|
|
])
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
.where("web", "=", true)
|
|
|
|
|
.where("stato", "!=", "Sospeso");
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
if (tipologia && tipologia !== "") {
|
|
|
|
|
query = query.where("tipo", "=", tipologia);
|
|
|
|
|
}
|
|
|
|
|
if (comune && comune !== "") {
|
|
|
|
|
query = query.where("comune", "like", comune);
|
|
|
|
|
}
|
|
|
|
|
if (consegna) {
|
|
|
|
|
query = query.where("consegna", "=", consegna);
|
|
|
|
|
}
|
2025-09-01 16:48:03 +02:00
|
|
|
|
|
|
|
|
switch (sort) {
|
|
|
|
|
case "Recenti":
|
|
|
|
|
query = query.orderBy("modificato_il", "desc");
|
|
|
|
|
break;
|
|
|
|
|
case "Prezzo":
|
|
|
|
|
query = query.orderBy("prezzo", "asc");
|
|
|
|
|
break;
|
|
|
|
|
case "Consegna":
|
|
|
|
|
query = query.orderBy("consegna", "asc");
|
|
|
|
|
break;
|
|
|
|
|
case "Mq":
|
|
|
|
|
query = query.orderBy("mq", "asc");
|
|
|
|
|
break;
|
|
|
|
|
case undefined:
|
|
|
|
|
break;
|
2025-08-28 18:27:07 +02:00
|
|
|
}
|
2025-09-01 16:48:03 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
query = query.orderBy("id", "asc");
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
const annunci = await query
|
|
|
|
|
.limit(pageSize + 1)
|
|
|
|
|
.offset(page * pageSize)
|
|
|
|
|
.execute();
|
|
|
|
|
const hasMore = annunci.length > pageSize;
|
|
|
|
|
if (annunci.length > pageSize) {
|
|
|
|
|
annunci.pop(); // Remove the last item if it exceeds the page size
|
|
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
return {
|
|
|
|
|
annunci,
|
|
|
|
|
hasMore,
|
|
|
|
|
};
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw new TRPCError({
|
|
|
|
|
code: "INTERNAL_SERVER_ERROR",
|
|
|
|
|
message: `Errore query getWithCursor: ${(e as Error).message}`,
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getOptions_AnnunciHandler = async () => {
|
2025-08-28 18:27:07 +02:00
|
|
|
try {
|
|
|
|
|
const comuni = await db
|
|
|
|
|
.selectFrom("annunci")
|
|
|
|
|
.select(["comune", "tipo", "consegna"])
|
|
|
|
|
.where("web", "=", true)
|
|
|
|
|
.where("stato", "!=", "Sospeso")
|
|
|
|
|
.distinct()
|
|
|
|
|
.execute();
|
|
|
|
|
const results: { comune: string; tipo: string; consegna: number }[] = [];
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
for (const comune of comuni) {
|
|
|
|
|
if (comune.comune && comune.tipo && comune.consegna) {
|
|
|
|
|
results.push({
|
|
|
|
|
comune: comune.comune,
|
|
|
|
|
consegna: comune.consegna,
|
2025-08-29 16:18:32 +02:00
|
|
|
tipo: comune.tipo,
|
2025-08-28 18:27:07 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
return results;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw new TRPCError({
|
|
|
|
|
code: "INTERNAL_SERVER_ERROR",
|
|
|
|
|
message: `Errore query getComuni: ${(e as Error).message}`,
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const editAnnuncioHandler = async ({
|
2025-08-28 18:27:07 +02:00
|
|
|
annuncioId,
|
|
|
|
|
data,
|
2025-08-28 12:37:32 +02:00
|
|
|
}: {
|
2025-08-28 18:27:07 +02:00
|
|
|
annuncioId: AnnunciId;
|
|
|
|
|
data: AnnunciUpdate;
|
2025-08-28 12:37:32 +02:00
|
|
|
}) => {
|
2025-08-28 18:27:07 +02:00
|
|
|
try {
|
2025-10-17 19:14:27 +02:00
|
|
|
const annuncio = await db
|
2025-08-28 18:27:07 +02:00
|
|
|
.updateTable("annunci")
|
|
|
|
|
.set({
|
|
|
|
|
...data,
|
|
|
|
|
})
|
|
|
|
|
.where("id", "=", annuncioId)
|
2025-10-17 19:14:27 +02:00
|
|
|
.returning("codice")
|
|
|
|
|
.executeTakeFirstOrThrow();
|
|
|
|
|
await revalidate(`/annuncio/${annuncio.codice}`);
|
2025-08-28 18:27:07 +02:00
|
|
|
return true;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw new TRPCError({
|
|
|
|
|
code: "INTERNAL_SERVER_ERROR",
|
|
|
|
|
message: `Errore interno: ${(e as Error).message}`,
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getProprietarioDataHandler = async ({
|
2025-08-28 18:27:07 +02:00
|
|
|
annuncioId,
|
|
|
|
|
servizioId,
|
2025-08-04 17:45:44 +02:00
|
|
|
}: {
|
2025-08-28 18:27:07 +02:00
|
|
|
annuncioId: AnnunciId;
|
|
|
|
|
servizioId: ServizioServizioId;
|
2025-08-04 17:45:44 +02:00
|
|
|
}) => {
|
2025-08-28 18:27:07 +02:00
|
|
|
try {
|
|
|
|
|
const opened_at = await db
|
|
|
|
|
.selectFrom("servizio_annunci")
|
|
|
|
|
.select("open_contatti_at")
|
|
|
|
|
.where("servizio_id", "=", servizioId)
|
|
|
|
|
.where("annunci_id", "=", annuncioId)
|
|
|
|
|
.executeTakeFirst();
|
|
|
|
|
if (!opened_at || !opened_at.open_contatti_at) {
|
2025-08-29 16:18:32 +02:00
|
|
|
return { opened_at: null, propData: null };
|
2025-08-28 18:27:07 +02:00
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
const propData = await db
|
|
|
|
|
.selectFrom("annunci")
|
|
|
|
|
.select([
|
|
|
|
|
"codice",
|
|
|
|
|
"comune",
|
|
|
|
|
"indirizzo",
|
|
|
|
|
"civico",
|
|
|
|
|
"provincia",
|
|
|
|
|
"regione",
|
|
|
|
|
"cap",
|
|
|
|
|
"lat",
|
|
|
|
|
"lon",
|
|
|
|
|
"numero",
|
|
|
|
|
"locatore",
|
|
|
|
|
])
|
|
|
|
|
.where("id", "=", annuncioId)
|
|
|
|
|
.executeTakeFirstOrThrow();
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-29 16:18:32 +02:00
|
|
|
return { opened_at: opened_at.open_contatti_at, propData };
|
2025-08-28 18:27:07 +02:00
|
|
|
} catch (e) {
|
|
|
|
|
throw new TRPCError({
|
|
|
|
|
code: "INTERNAL_SERVER_ERROR",
|
|
|
|
|
message: `Errore recupero dati proprietario: ${(e as Error).message}`,
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|