From 9782cde91704bb5d9608909249af29b3952dd0ca Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Thu, 26 Feb 2026 12:26:56 +0100 Subject: [PATCH] refactor: comment out unused timeserie queries in stats router --- .../src/server/api/routers/stats.ts | 142 +++++++++--------- 1 file changed, 68 insertions(+), 74 deletions(-) diff --git a/apps/infoalloggi/src/server/api/routers/stats.ts b/apps/infoalloggi/src/server/api/routers/stats.ts index ad95201..11c55b9 100644 --- a/apps/infoalloggi/src/server/api/routers/stats.ts +++ b/apps/infoalloggi/src/server/api/routers/stats.ts @@ -1,81 +1,78 @@ -import { sql } from "kysely"; -import type { StackedTimeserie } from "~/components/timeserieBarChartStacked"; -import TipologiaPosizioneEnum from "~/schemas/public/TipologiaPosizioneEnum"; import { adminProcedure, createTRPCRouter } from "~/server/api/trpc"; import { db } from "~/server/db"; export const statsRouter = createTRPCRouter({ adminDashStats: adminProcedure.query(async () => { - const userTimeserie = ( - await db - .selectFrom("users") - .select((eb) => [ - sql`date_trunc('day', created_at)`.as("date"), - eb.fn.count("id").as("value"), - ]) - .where("isAdmin", "=", false) - .groupBy("date") - .orderBy("date") - .execute() - ).map((item) => ({ - date: item.date, - value: parseInt(String(item.value)), - })); + // const userTimeserie = ( + // await db + // .selectFrom("users") + // .select((eb) => [ + // sql`date_trunc('day', created_at)`.as("date"), + // eb.fn.count("id").as("value"), + // ]) + // .where("isAdmin", "=", false) + // .groupBy("date") + // .orderBy("date") + // .execute() + // ).map((item) => ({ + // date: item.date, + // value: parseInt(String(item.value)), + // })); - const serviziTimeserie = { - data: Object.values( - ( - await db - .selectFrom("servizio") - .select((eb) => [ - sql`date_trunc('day', created_at)`.as("date"), - eb.fn.count("servizio_id").as("value"), - "tipologia", - ]) - .groupBy(["date", "tipologia"]) - .orderBy("date") - .execute() - ).reduce( - (acc, item) => { - const dateStr = item.date.toISOString().slice(0, 10); - if (!acc[dateStr]) { - acc[dateStr] = { - date: item.date, - valueA: 0, - valueB: 0, - }; - } - if (item.tipologia === TipologiaPosizioneEnum.Transitorio) { - acc[dateStr].valueA = parseInt(String(item.value)); - } else if (item.tipologia === TipologiaPosizioneEnum.Stabile) { - acc[dateStr].valueB = parseInt(String(item.value)); - } - return acc; - }, - {} as Record, - ), - ), - valueALabel: "Transitorio", - valueBLabel: "Stabile", - }; + // const serviziTimeserie = { + // data: Object.values( + // ( + // await db + // .selectFrom("servizio") + // .select((eb) => [ + // sql`date_trunc('day', created_at)`.as("date"), + // eb.fn.count("servizio_id").as("value"), + // "tipologia", + // ]) + // .groupBy(["date", "tipologia"]) + // .orderBy("date") + // .execute() + // ).reduce( + // (acc, item) => { + // const dateStr = item.date.toISOString().slice(0, 10); + // if (!acc[dateStr]) { + // acc[dateStr] = { + // date: item.date, + // valueA: 0, + // valueB: 0, + // }; + // } + // if (item.tipologia === TipologiaPosizioneEnum.Transitorio) { + // acc[dateStr].valueA = parseInt(String(item.value)); + // } else if (item.tipologia === TipologiaPosizioneEnum.Stabile) { + // acc[dateStr].valueB = parseInt(String(item.value)); + // } + // return acc; + // }, + // {} as Record, + // ), + // ), + // valueALabel: "Transitorio", + // valueBLabel: "Stabile", + // }; - const contattiTimeserie = ( - await db - .selectFrom("servizio_annunci") - .select((eb) => [ - sql`date_trunc('day', created_at)`.as("date"), - eb.fn - .count(eb.fn("concat", ["servizio_id", "annunci_id"])) - .as("value"), - ]) - .where("open_contatti_at", "is not", null) - .groupBy("date") - .orderBy("date") - .execute() - ).map((item) => ({ - date: item.date, - value: parseInt(String(item.value)), - })); + // const contattiTimeserie = ( + // await db + // .selectFrom("servizio_annunci") + // .select((eb) => [ + // sql`date_trunc('day', created_at)`.as("date"), + // eb.fn + // .count(eb.fn("concat", ["servizio_id", "annunci_id"])) + // .as("value"), + // ]) + // .where("open_contatti_at", "is not", null) + // .groupBy("date") + // .orderBy("date") + // .execute() + // ).map((item) => ({ + // date: item.date, + // value: parseInt(String(item.value)), + // })); const userCount = ( @@ -86,10 +83,7 @@ export const statsRouter = createTRPCRouter({ )?.count || 0; return { - contattiTimeserie, - serviziTimeserie, userCount, - userTimeserie, }; }), });