infoalloggi-monorepo/apps/infoalloggi/src/server/api/routers/etichette.ts
Marco Pedone 9c18ca37ab Refactor API structure and update flag handling
- Replaced references to `api.settings` with `api.etichette`, `api.flags`, and `api.strings` in various admin pages to align with new API structure.
- Removed the deprecated `settingsRouter` and introduced `flagsRouter`, `etichetteRouter`, and `stringsRouter` to handle respective functionalities.
- Updated the `Flags` schema to change the `value` field from string to boolean.
- Modified flag handling logic in the `SendMessage` and `NewMail` functions to check for boolean flags instead of string values.
- Added migration script to convert the `value` column in the `flags` table from string to boolean.
- Implemented new routers for banners, etichette, flags, revalidation, and strings to encapsulate related functionalities.
2025-11-20 12:38:42 +01:00

54 lines
1.3 KiB
TypeScript

import { z } from "zod/v4";
import { adminProcedure, createTRPCRouter } from "~/server/api/trpc";
import {
addEtichetta,
getAllEtichette,
removeEtichetta,
updateEtichetta,
} from "~/server/controllers/etichette.controller";
import { db } from "~/server/db";
import { zEtichettaId } from "~/server/utils/zod_types";
export const etichetteRouter = createTRPCRouter({
addEtichetta: adminProcedure
.input(
z.object({
color_hex: z.string().max(7),
title: z.string(),
}),
)
.mutation(async ({ input }) => {
return await addEtichetta({
color_hex: input.color_hex,
db,
title: input.title,
});
}),
getAllEtichette: adminProcedure.query(async () => {
return await getAllEtichette({ db });
}),
removeEtichetta: adminProcedure
.input(z.object({ id_etichetta: zEtichettaId }))
.mutation(async ({ input }) => {
return await removeEtichetta({
db,
etichettaid: input.id_etichetta,
});
}),
updateEtichetta: adminProcedure
.input(
z.object({
color_hex: z.string().max(7),
id_etichetta: zEtichettaId,
title: z.string(),
}),
)
.mutation(async ({ input }) => {
return await updateEtichetta({
color_hex: input.color_hex,
db,
etichettaid: input.id_etichetta,
title: input.title,
});
}),
});