feat: add Zod schemas for various entities and update API routes

- Introduced Zod schemas for validation in the following entities:
  - Provincie
  - Ratelimiter
  - Rinnovi
  - Servizio
  - ServizioAnnunci
  - ServizioInteressi
  - TestiEStringhe
  - Users
  - UserEtichette
  - UserInvites
  - UsersAnagrafica
  - UsersStorage
  - VideosRefs
  - StatusConfermaEnum
  - TipologiaPosizioneEnum

- Updated API routes in `catasto.ts` to include CRUD operations for Comuni, Nazioni, and Provincie with appropriate input validation.
- Enhanced controller methods in `catasto.controller.ts` to handle create, edit, and delete operations for Comuni and Nazioni.
- Added new utility Zod types for ComuniId, NazioniId, and ProvincieId.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Marco Pedone 2026-04-28 17:46:34 +02:00
parent 8f28b7bba3
commit d17ac87917
47 changed files with 2644 additions and 97 deletions

View file

@ -1,5 +1,6 @@
const { makeKyselyHook } = require("kanel-kysely"); const { makeKyselyHook } = require("kanel-kysely");
const { makePgTsGenerator } = require("kanel"); const { makePgTsGenerator } = require("kanel");
const { generateZodSchemas, makeGenerateZodSchemas } = require("kanel-zod");
const ignoredTables = ["schema_migrations"]; const ignoredTables = ["schema_migrations"];
/** /**
@ -42,6 +43,62 @@ const specificTypes = (mappings) => {
}; };
} }
const kanelZodCastRegex = /as unknown as z.Schema<(.*?)(Mutator|Initializer)>/;
const zodItemInitializer = /^export const \w+ = z\.object/
/**
* @type {import("kanel").PostRenderHook}
*
* Renames the type of the `as unknown as z.Schema` casts from `kanel-zod` to
* to be compatible with `kanel-kysely`, turning
* 1. `as unknown as z.Schema<TableMutator>` into `as unknown as z.Schema<TableUpdate>`
* 2. `as unknown as z.Schema<TableInitializer>` into `as unknown as z.Schema<NewTable>`
*/
function kanelKyselyZodCompatibilityHook(path, lines) {
return lines.map((line) => {
if (zodItemInitializer.test(line)) {
const parts = line.split(" ");
if (parts[2].includes("Initializer")) {
const nome = parts[2].replace("Initializer", "");
parts[2] = "New" + nome[0].toUpperCase() + nome.slice(1) + "Schema";
return parts.join(" ");
}
if (parts[2].includes("Mutator")) {
const nome = parts[2].replace("Mutator", "");
parts[2] = nome[0].toUpperCase() + nome.slice(1) + "UpdateSchema";
return parts.join(" ");
}
const nome = parts[2];
parts[2] = nome[0].toUpperCase() + nome.slice(1) + "Schema";
return parts.join(" ");
}
if (line.includes("as unknown as z.Schema")) {
const replacedLine = line.replace(
kanelZodCastRegex,
(_, typeName, mutatorOrInitializer) => {
if (!mutatorOrInitializer) {
return `as unknown as z.Schema<${typeName}>`;
}
if (mutatorOrInitializer === "Mutator") {
return `as unknown as z.Schema<${typeName}Update>`;
}
return `as unknown as z.Schema<New${typeName}>`;
}
);
return replacedLine;
}
return line;
});
}
/** @type {import('kanel').Config} */ /** @type {import('kanel').Config} */
module.exports = { module.exports = {
connection: { connection: {
@ -53,7 +110,8 @@ module.exports = {
}, },
filter: (pgTable) => !ignoredTables.includes(pgTable.name), filter: (pgTable) => !ignoredTables.includes(pgTable.name),
outputPath: "./src/schemas", outputPath: "./src/schemas",
generators: [makePgTsGenerator({ generators: [
makePgTsGenerator({
customTypeMap: { customTypeMap: {
"pg_catalog.tsvector": "string", "pg_catalog.tsvector": "string",
"pg_catalog.bpchar": "string", "pg_catalog.bpchar": "string",
@ -70,10 +128,14 @@ module.exports = {
}, },
}), }),
makeKyselyHook(), makeKyselyHook(),
makeGenerateZodSchemas({
castToSchema: false
}),
], ],
}), }),
], ],
postRenderHooks: [kanelKyselyZodCompatibilityHook],
preDeleteOutputFolder: true, preDeleteOutputFolder: true,

View file

@ -116,6 +116,7 @@
"jsdom": "^29.0.2", "jsdom": "^29.0.2",
"kanel": "^4.0.1", "kanel": "^4.0.1",
"kanel-kysely": "^4.0.0", "kanel-kysely": "^4.0.0",
"kanel-zod": "^4.0.0",
"knip": "^6.4.1", "knip": "^6.4.1",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"react-email": "^5.2.10", "react-email": "^5.2.10",
@ -9089,6 +9090,16 @@
"@kristiandupont/recase": "^1.2.1" "@kristiandupont/recase": "^1.2.1"
} }
}, },
"node_modules/kanel-zod": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/kanel-zod/-/kanel-zod-4.0.0.tgz",
"integrity": "sha512-F2rLVeNDuoccjRtR5xW3iMJSwjdhyxVcmmoc7H5AXF8QB0uT+syMIrsrrKeN/x4+BLS39myYF0nRpUvOiahs9Q==",
"dev": true,
"license": "MIT",
"dependencies": {
"@kristiandupont/recase": "^1.2.1"
}
},
"node_modules/kleur": { "node_modules/kleur": {
"version": "3.0.3", "version": "3.0.3",
"dev": true, "dev": true,

View file

@ -131,6 +131,7 @@
"jsdom": "^29.0.2", "jsdom": "^29.0.2",
"kanel": "^4.0.1", "kanel": "^4.0.1",
"kanel-kysely": "^4.0.0", "kanel-kysely": "^4.0.0",
"kanel-zod": "^4.0.0",
"knip": "^6.4.1", "knip": "^6.4.1",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"react-email": "^5.2.10", "react-email": "^5.2.10",

View file

@ -675,6 +675,7 @@ export const en: LangDict = {
items: [ items: [
{ href: "/area-riservata/admin/etichette", title: "Labels" }, { href: "/area-riservata/admin/etichette", title: "Labels" },
{ href: "/area-riservata/admin/flags", title: "Flags" }, { href: "/area-riservata/admin/flags", title: "Flags" },
{ href: "/area-riservata/admin/catasto", title: "Catasto" },
{ href: "/area-riservata/admin/banners", title: "Banners" }, { href: "/area-riservata/admin/banners", title: "Banners" },
{ {
href: "/area-riservata/admin/testi-stringhe", href: "/area-riservata/admin/testi-stringhe",

View file

@ -680,6 +680,7 @@ export const it: LangDict = {
items: [ items: [
{ href: "/area-riservata/admin/etichette", title: "Etichette" }, { href: "/area-riservata/admin/etichette", title: "Etichette" },
{ href: "/area-riservata/admin/flags", title: "Flags" }, { href: "/area-riservata/admin/flags", title: "Flags" },
{ href: "/area-riservata/admin/catasto", title: "Catasto" },
{ href: "/area-riservata/admin/banners", title: "Banners" }, { href: "/area-riservata/admin/banners", title: "Banners" },
{ {
href: "/area-riservata/admin/testi-stringhe", href: "/area-riservata/admin/testi-stringhe",

File diff suppressed because it is too large Load diff

View file

@ -50,7 +50,7 @@ const AdminFlags: NextPageWithLayout = () => {
<div className="mx-3 items-start justify-between md:flex"> <div className="mx-3 items-start justify-between md:flex">
<div className="flex max-w-lg items-center gap-3"> <div className="flex max-w-lg items-center gap-3">
<h3 className="font-bold text-accent-foreground text-xl sm:text-2xl"> <h3 className="font-bold text-accent-foreground text-xl sm:text-2xl">
Impostazioni Flags
</h3> </h3>
<button <button
className="cursor-pointer" className="cursor-pointer"

View file

@ -1,5 +1,6 @@
import type { Caratteristiche } from '../../utils/kanel-types.ts'; import type { Caratteristiche } from '../../utils/kanel-types.ts';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.annunci */ /** Identifier type for public.annunci */
export type AnnunciId = number & { __brand: 'public.annunci' }; export type AnnunciId = number & { __brand: 'public.annunci' };
@ -116,3 +117,170 @@ export type Annunci = Selectable<AnnunciTable>;
export type NewAnnunci = Insertable<AnnunciTable>; export type NewAnnunci = Insertable<AnnunciTable>;
export type AnnunciUpdate = Updateable<AnnunciTable>; export type AnnunciUpdate = Updateable<AnnunciTable>;
export const annunciId = z.number().transform(value => value as AnnunciId);
export const AnnunciSchema = z.object({
id: annunciId,
codice: z.string(),
locatore: z.string().nullable(),
numero: z.string().nullable(),
idlocatore: z.string().nullable(),
indirizzo: z.string().nullable(),
civico: z.string().nullable(),
comune: z.string().nullable(),
cap: z.string().nullable(),
provincia: z.string().nullable(),
regione: z.string().nullable(),
lat: z.string().nullable(),
lon: z.string().nullable(),
indirizzo_secondario: z.string().nullable(),
civico_secondario: z.string().nullable(),
lat_secondario: z.string().nullable(),
lon_secondario: z.string().nullable(),
tipo: z.string().nullable(),
categorie: z.string().array().nullable(),
prezzo: z.number(),
anno: z.string().nullable(),
classe: z.string().nullable(),
mq: z.string().nullable(),
piano: z.string().nullable(),
piano_palazzo: z.number().nullable(),
unita_condominio: z.number().nullable(),
numero_vani: z.number().nullable(),
numero_camere: z.number().nullable(),
numero_bagni: z.number().nullable(),
numero_balconi: z.number().nullable(),
numero_terrazzi: z.number().nullable(),
numero_box: z.number().nullable(),
numero_postiauto: z.number().nullable(),
accessori: z.string().array().nullable(),
titolo_it: z.string().nullable(),
desc_it: z.string().nullable(),
titolo_en: z.string().nullable(),
desc_en: z.string().nullable(),
stato: z.string().nullable(),
web: z.boolean().nullable(),
caratteristiche: z.unknown().nullable(),
homepage: z.boolean().nullable(),
external_videos: z.string().array().nullable(),
email: z.string().nullable(),
creato_il: z.date().nullable(),
modificato_il: z.date().nullable(),
consegna: z.number().nullable(),
disponibile_da: z.date().nullable(),
permanenza: z.number().array().nullable(),
persone: z.string().array().nullable(),
media_updated_at: z.date().nullable(),
tipo_locatore: z.string().nullable(),
});
export const NewAnnunciSchema = z.object({
id: annunciId.optional(),
codice: z.string(),
locatore: z.string().optional().nullable(),
numero: z.string().optional().nullable(),
idlocatore: z.string().optional().nullable(),
indirizzo: z.string().optional().nullable(),
civico: z.string().optional().nullable(),
comune: z.string().optional().nullable(),
cap: z.string().optional().nullable(),
provincia: z.string().optional().nullable(),
regione: z.string().optional().nullable(),
lat: z.string().optional().nullable(),
lon: z.string().optional().nullable(),
indirizzo_secondario: z.string().optional().nullable(),
civico_secondario: z.string().optional().nullable(),
lat_secondario: z.string().optional().nullable(),
lon_secondario: z.string().optional().nullable(),
tipo: z.string().optional().nullable(),
categorie: z.string().array().optional().nullable(),
prezzo: z.number().optional(),
anno: z.string().optional().nullable(),
classe: z.string().optional().nullable(),
mq: z.string().optional().nullable(),
piano: z.string().optional().nullable(),
piano_palazzo: z.number().optional().nullable(),
unita_condominio: z.number().optional().nullable(),
numero_vani: z.number().optional().nullable(),
numero_camere: z.number().optional().nullable(),
numero_bagni: z.number().optional().nullable(),
numero_balconi: z.number().optional().nullable(),
numero_terrazzi: z.number().optional().nullable(),
numero_box: z.number().optional().nullable(),
numero_postiauto: z.number().optional().nullable(),
accessori: z.string().array().optional().nullable(),
titolo_it: z.string().optional().nullable(),
desc_it: z.string().optional().nullable(),
titolo_en: z.string().optional().nullable(),
desc_en: z.string().optional().nullable(),
stato: z.string().optional().nullable(),
web: z.boolean().optional().nullable(),
caratteristiche: z.unknown().optional().nullable(),
homepage: z.boolean().optional().nullable(),
external_videos: z.string().array().optional().nullable(),
email: z.string().optional().nullable(),
creato_il: z.date().optional().nullable(),
modificato_il: z.date().optional().nullable(),
consegna: z.number().optional().nullable(),
disponibile_da: z.date().optional().nullable(),
permanenza: z.number().array().optional().nullable(),
persone: z.string().array().optional().nullable(),
media_updated_at: z.date().optional().nullable(),
tipo_locatore: z.string().optional().nullable(),
});
export const AnnunciUpdateSchema = z.object({
id: annunciId.optional(),
codice: z.string().optional(),
locatore: z.string().optional().nullable(),
numero: z.string().optional().nullable(),
idlocatore: z.string().optional().nullable(),
indirizzo: z.string().optional().nullable(),
civico: z.string().optional().nullable(),
comune: z.string().optional().nullable(),
cap: z.string().optional().nullable(),
provincia: z.string().optional().nullable(),
regione: z.string().optional().nullable(),
lat: z.string().optional().nullable(),
lon: z.string().optional().nullable(),
indirizzo_secondario: z.string().optional().nullable(),
civico_secondario: z.string().optional().nullable(),
lat_secondario: z.string().optional().nullable(),
lon_secondario: z.string().optional().nullable(),
tipo: z.string().optional().nullable(),
categorie: z.string().array().optional().nullable(),
prezzo: z.number().optional(),
anno: z.string().optional().nullable(),
classe: z.string().optional().nullable(),
mq: z.string().optional().nullable(),
piano: z.string().optional().nullable(),
piano_palazzo: z.number().optional().nullable(),
unita_condominio: z.number().optional().nullable(),
numero_vani: z.number().optional().nullable(),
numero_camere: z.number().optional().nullable(),
numero_bagni: z.number().optional().nullable(),
numero_balconi: z.number().optional().nullable(),
numero_terrazzi: z.number().optional().nullable(),
numero_box: z.number().optional().nullable(),
numero_postiauto: z.number().optional().nullable(),
accessori: z.string().array().optional().nullable(),
titolo_it: z.string().optional().nullable(),
desc_it: z.string().optional().nullable(),
titolo_en: z.string().optional().nullable(),
desc_en: z.string().optional().nullable(),
stato: z.string().optional().nullable(),
web: z.boolean().optional().nullable(),
caratteristiche: z.unknown().optional().nullable(),
homepage: z.boolean().optional().nullable(),
external_videos: z.string().array().optional().nullable(),
email: z.string().optional().nullable(),
creato_il: z.date().optional().nullable(),
modificato_il: z.date().optional().nullable(),
consegna: z.number().optional().nullable(),
disponibile_da: z.date().optional().nullable(),
permanenza: z.number().array().optional().nullable(),
persone: z.string().array().optional().nullable(),
media_updated_at: z.date().optional().nullable(),
tipo_locatore: z.string().optional().nullable(),
});

View file

@ -1,3 +1,5 @@
import { z } from 'zod';
/** Represents the enum public.BanType */ /** Represents the enum public.BanType */
enum BanType { enum BanType {
ip = 'ip', ip = 'ip',
@ -7,3 +9,11 @@ enum BanType {
}; };
export default BanType; export default BanType;
/** Zod schema for BanType */
export const banType = z.enum([
'ip',
'email',
'phone',
'cf',
]);

View file

@ -1,5 +1,6 @@
import type { default as BanType } from './BanType'; import { banType, type default as BanType } from './BanType';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.banlist */ /** Identifier type for public.banlist */
export type BanlistId = number & { __brand: 'public.banlist' }; export type BanlistId = number & { __brand: 'public.banlist' };
@ -18,3 +19,23 @@ export type Banlist = Selectable<BanlistTable>;
export type NewBanlist = Insertable<BanlistTable>; export type NewBanlist = Insertable<BanlistTable>;
export type BanlistUpdate = Updateable<BanlistTable>; export type BanlistUpdate = Updateable<BanlistTable>;
export const banlistId = z.number().transform(value => value as BanlistId);
export const BanlistSchema = z.object({
id: banlistId,
value: z.string(),
type: banType,
});
export const NewBanlistSchema = z.object({
id: banlistId.optional(),
value: z.string(),
type: banType,
});
export const BanlistUpdateSchema = z.object({
id: banlistId.optional(),
value: z.string().optional(),
type: banType.optional(),
});

View file

@ -1,4 +1,5 @@
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.banners */ /** Identifier type for public.banners */
export type BannersIdbanner = string & { __brand: 'public.banners' }; export type BannersIdbanner = string & { __brand: 'public.banners' };
@ -37,3 +38,53 @@ export type Banners = Selectable<BannersTable>;
export type NewBanners = Insertable<BannersTable>; export type NewBanners = Insertable<BannersTable>;
export type BannersUpdate = Updateable<BannersTable>; export type BannersUpdate = Updateable<BannersTable>;
export const bannersIdbanner = z.string().transform(value => value as BannersIdbanner);
export const BannersSchema = z.object({
idbanner: bannersIdbanner,
titolo: z.string().nullable(),
testo: z.string().nullable(),
is_unskippable: z.boolean(),
has_cta: z.boolean(),
cta_href: z.string().nullable(),
cta_icon: z.string().nullable(),
cta_text: z.string().nullable(),
color: z.string().nullable(),
is_active: z.boolean(),
show_public: z.boolean(),
show_private: z.boolean(),
hide_duration: z.number().nullable(),
});
export const NewBannersSchema = z.object({
idbanner: bannersIdbanner,
titolo: z.string().optional().nullable(),
testo: z.string().optional().nullable(),
is_unskippable: z.boolean(),
has_cta: z.boolean(),
cta_href: z.string().optional().nullable(),
cta_icon: z.string().optional().nullable(),
cta_text: z.string().optional().nullable(),
color: z.string().optional().nullable(),
is_active: z.boolean(),
show_public: z.boolean(),
show_private: z.boolean(),
hide_duration: z.number().optional().nullable(),
});
export const BannersUpdateSchema = z.object({
idbanner: bannersIdbanner.optional(),
titolo: z.string().optional().nullable(),
testo: z.string().optional().nullable(),
is_unskippable: z.boolean().optional(),
has_cta: z.boolean().optional(),
cta_href: z.string().optional().nullable(),
cta_icon: z.string().optional().nullable(),
cta_text: z.string().optional().nullable(),
color: z.string().optional().nullable(),
is_active: z.boolean().optional(),
show_public: z.boolean().optional(),
show_private: z.boolean().optional(),
hide_duration: z.number().optional().nullable(),
});

View file

@ -1,5 +1,6 @@
import type { UsersId } from './Users'; import { usersId, type UsersId } from './Users';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.chats */ /** Identifier type for public.chats */
export type ChatsChatid = string & { __brand: 'public.chats' }; export type ChatsChatid = string & { __brand: 'public.chats' };
@ -20,3 +21,26 @@ export type Chats = Selectable<ChatsTable>;
export type NewChats = Insertable<ChatsTable>; export type NewChats = Insertable<ChatsTable>;
export type ChatsUpdate = Updateable<ChatsTable>; export type ChatsUpdate = Updateable<ChatsTable>;
export const chatsChatid = z.uuid().transform(value => value as ChatsChatid);
export const ChatsSchema = z.object({
chatid: chatsChatid,
created_at: z.date(),
user_ref: usersId,
tags: z.string().array().nullable(),
});
export const NewChatsSchema = z.object({
chatid: chatsChatid.optional(),
created_at: z.date(),
user_ref: usersId,
tags: z.string().array().optional().nullable(),
});
export const ChatsUpdateSchema = z.object({
chatid: chatsChatid.optional(),
created_at: z.date().optional(),
user_ref: usersId.optional(),
tags: z.string().array().optional().nullable(),
});

View file

@ -1,6 +1,7 @@
import type { ChatsChatid } from './Chats'; import { chatsChatid, type ChatsChatid } from './Chats';
import type { EtichetteIdEtichetta } from './Etichette'; import { etichetteIdEtichetta, type EtichetteIdEtichetta } from './Etichette';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Represents the table public.chats_etichette */ /** Represents the table public.chats_etichette */
export default interface ChatsEtichetteTable { export default interface ChatsEtichetteTable {
@ -14,3 +15,18 @@ export type ChatsEtichette = Selectable<ChatsEtichetteTable>;
export type NewChatsEtichette = Insertable<ChatsEtichetteTable>; export type NewChatsEtichette = Insertable<ChatsEtichetteTable>;
export type ChatsEtichetteUpdate = Updateable<ChatsEtichetteTable>; export type ChatsEtichetteUpdate = Updateable<ChatsEtichetteTable>;
export const ChatsEtichetteSchema = z.object({
chatid: chatsChatid,
etichettaid: etichetteIdEtichetta,
});
export const NewChatsEtichetteSchema = z.object({
chatid: chatsChatid,
etichettaid: etichetteIdEtichetta,
});
export const ChatsEtichetteUpdateSchema = z.object({
chatid: chatsChatid.optional(),
etichettaid: etichetteIdEtichetta.optional(),
});

View file

@ -1,4 +1,5 @@
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.comuni */ /** Identifier type for public.comuni */
export type ComuniId = number & { __brand: 'public.comuni' }; export type ComuniId = number & { __brand: 'public.comuni' };
@ -21,3 +22,29 @@ export type Comuni = Selectable<ComuniTable>;
export type NewComuni = Insertable<ComuniTable>; export type NewComuni = Insertable<ComuniTable>;
export type ComuniUpdate = Updateable<ComuniTable>; export type ComuniUpdate = Updateable<ComuniTable>;
export const comuniId = z.number().transform(value => value as ComuniId);
export const ComuniSchema = z.object({
id: comuniId,
nome: z.string(),
sigla: z.string(),
catasto: z.string(),
cap: z.string().nullable(),
});
export const NewComuniSchema = z.object({
id: comuniId.optional(),
nome: z.string(),
sigla: z.string(),
catasto: z.string(),
cap: z.string().optional().nullable(),
});
export const ComuniUpdateSchema = z.object({
id: comuniId.optional(),
nome: z.string().optional(),
sigla: z.string().optional(),
catasto: z.string().optional(),
cap: z.string().optional().nullable(),
});

View file

@ -1,5 +1,6 @@
import type { UsersId } from './Users'; import { usersId, type UsersId } from './Users';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.emails */ /** Identifier type for public.emails */
export type EmailsIdEmail = number & { __brand: 'public.emails' }; export type EmailsIdEmail = number & { __brand: 'public.emails' };
@ -20,3 +21,26 @@ export type Emails = Selectable<EmailsTable>;
export type NewEmails = Insertable<EmailsTable>; export type NewEmails = Insertable<EmailsTable>;
export type EmailsUpdate = Updateable<EmailsTable>; export type EmailsUpdate = Updateable<EmailsTable>;
export const emailsIdEmail = z.number().transform(value => value as EmailsIdEmail);
export const EmailsSchema = z.object({
id_email: emailsIdEmail,
user_id: usersId,
created_at: z.date(),
data: z.unknown(),
});
export const NewEmailsSchema = z.object({
id_email: emailsIdEmail.optional(),
user_id: usersId,
created_at: z.date().optional(),
data: z.unknown(),
});
export const EmailsUpdateSchema = z.object({
id_email: emailsIdEmail.optional(),
user_id: usersId.optional(),
created_at: z.date().optional(),
data: z.unknown().optional(),
});

View file

@ -1,4 +1,5 @@
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.etichette */ /** Identifier type for public.etichette */
export type EtichetteIdEtichetta = number & { __brand: 'public.etichette' }; export type EtichetteIdEtichetta = number & { __brand: 'public.etichette' };
@ -17,3 +18,23 @@ export type Etichette = Selectable<EtichetteTable>;
export type NewEtichette = Insertable<EtichetteTable>; export type NewEtichette = Insertable<EtichetteTable>;
export type EtichetteUpdate = Updateable<EtichetteTable>; export type EtichetteUpdate = Updateable<EtichetteTable>;
export const etichetteIdEtichetta = z.number().transform(value => value as EtichetteIdEtichetta);
export const EtichetteSchema = z.object({
id_etichetta: etichetteIdEtichetta,
title: z.string(),
color_hex: z.string(),
});
export const NewEtichetteSchema = z.object({
id_etichetta: etichetteIdEtichetta.optional(),
title: z.string(),
color_hex: z.string(),
});
export const EtichetteUpdateSchema = z.object({
id_etichetta: etichetteIdEtichetta.optional(),
title: z.string().optional(),
color_hex: z.string().optional(),
});

View file

@ -1,4 +1,5 @@
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.event_queue */ /** Identifier type for public.event_queue */
export type EventQueueEventId = number & { __brand: 'public.event_queue' }; export type EventQueueEventId = number & { __brand: 'public.event_queue' };
@ -19,3 +20,26 @@ export type EventQueue = Selectable<EventQueueTable>;
export type NewEventQueue = Insertable<EventQueueTable>; export type NewEventQueue = Insertable<EventQueueTable>;
export type EventQueueUpdate = Updateable<EventQueueTable>; export type EventQueueUpdate = Updateable<EventQueueTable>;
export const eventQueueEventId = z.number().transform(value => value as EventQueueEventId);
export const EventQueueSchema = z.object({
event_id: eventQueueEventId,
lock_expires: z.date(),
data: z.unknown().nullable(),
status: z.string(),
});
export const NewEventQueueSchema = z.object({
event_id: eventQueueEventId.optional(),
lock_expires: z.date(),
data: z.unknown().optional().nullable(),
status: z.string().optional(),
});
export const EventQueueUpdateSchema = z.object({
event_id: eventQueueEventId.optional(),
lock_expires: z.date().optional(),
data: z.unknown().optional().nullable(),
status: z.string().optional(),
});

View file

@ -1,4 +1,5 @@
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.flags */ /** Identifier type for public.flags */
export type FlagsId = string & { __brand: 'public.flags' }; export type FlagsId = string & { __brand: 'public.flags' };
@ -15,3 +16,20 @@ export type Flags = Selectable<FlagsTable>;
export type NewFlags = Insertable<FlagsTable>; export type NewFlags = Insertable<FlagsTable>;
export type FlagsUpdate = Updateable<FlagsTable>; export type FlagsUpdate = Updateable<FlagsTable>;
export const flagsId = z.string().transform(value => value as FlagsId);
export const FlagsSchema = z.object({
id: flagsId,
value: z.boolean(),
});
export const NewFlagsSchema = z.object({
id: flagsId,
value: z.boolean().optional(),
});
export const FlagsUpdateSchema = z.object({
id: flagsId.optional(),
value: z.boolean().optional(),
});

View file

@ -1,3 +1,5 @@
import { z } from 'zod';
/** Represents the enum public.GenericStatusEnum */ /** Represents the enum public.GenericStatusEnum */
enum GenericStatusEnum { enum GenericStatusEnum {
pending = 'pending', pending = 'pending',
@ -6,3 +8,10 @@ enum GenericStatusEnum {
}; };
export default GenericStatusEnum; export default GenericStatusEnum;
/** Zod schema for GenericStatusEnum */
export const genericStatusEnum = z.enum([
'pending',
'success',
'failed',
]);

View file

@ -1,4 +1,5 @@
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Represents the table public.images_refs */ /** Represents the table public.images_refs */
export default interface ImagesRefsTable { export default interface ImagesRefsTable {
@ -18,3 +19,27 @@ export type ImagesRefs = Selectable<ImagesRefsTable>;
export type NewImagesRefs = Insertable<ImagesRefsTable>; export type NewImagesRefs = Insertable<ImagesRefsTable>;
export type ImagesRefsUpdate = Updateable<ImagesRefsTable>; export type ImagesRefsUpdate = Updateable<ImagesRefsTable>;
export const ImagesRefsSchema = z.object({
codice: z.string(),
ordine: z.number(),
img: z.string(),
thumb: z.string(),
og_url: z.string(),
});
export const NewImagesRefsSchema = z.object({
codice: z.string(),
ordine: z.number(),
img: z.string(),
thumb: z.string(),
og_url: z.string(),
});
export const ImagesRefsUpdateSchema = z.object({
codice: z.string().optional(),
ordine: z.number().optional(),
img: z.string().optional(),
thumb: z.string().optional(),
og_url: z.string().optional(),
});

View file

@ -1,6 +1,7 @@
import type { ChatsChatid } from './Chats'; import { chatsChatid, type ChatsChatid } from './Chats';
import type { UsersId } from './Users'; import { usersId, type UsersId } from './Users';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.messages */ /** Identifier type for public.messages */
export type MessagesMessageid = string & { __brand: 'public.messages' }; export type MessagesMessageid = string & { __brand: 'public.messages' };
@ -29,3 +30,38 @@ export type Messages = Selectable<MessagesTable>;
export type NewMessages = Insertable<MessagesTable>; export type NewMessages = Insertable<MessagesTable>;
export type MessagesUpdate = Updateable<MessagesTable>; export type MessagesUpdate = Updateable<MessagesTable>;
export const messagesMessageid = z.uuid().transform(value => value as MessagesMessageid);
export const MessagesSchema = z.object({
messageid: messagesMessageid,
chatid: chatsChatid,
message: z.string(),
time: z.date(),
isread: z.boolean(),
sender: usersId,
reply_to_id: messagesMessageid.nullable(),
is_forwarded: z.boolean(),
});
export const NewMessagesSchema = z.object({
messageid: messagesMessageid.optional(),
chatid: chatsChatid,
message: z.string(),
time: z.date(),
isread: z.boolean().optional(),
sender: usersId,
reply_to_id: messagesMessageid.optional().nullable(),
is_forwarded: z.boolean().optional(),
});
export const MessagesUpdateSchema = z.object({
messageid: messagesMessageid.optional(),
chatid: chatsChatid.optional(),
message: z.string().optional(),
time: z.date().optional(),
isread: z.boolean().optional(),
sender: usersId.optional(),
reply_to_id: messagesMessageid.optional().nullable(),
is_forwarded: z.boolean().optional(),
});

View file

@ -1,6 +1,7 @@
import type { MessagesMessageid } from './Messages'; import { messagesMessageid, type MessagesMessageid } from './Messages';
import type { UsersStorageUserStorageId } from './UsersStorage'; import { usersStorageUserStorageId, type UsersStorageUserStorageId } from './UsersStorage';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Represents the table public.messages_attachments */ /** Represents the table public.messages_attachments */
export default interface MessagesAttachmentsTable { export default interface MessagesAttachmentsTable {
@ -14,3 +15,18 @@ export type MessagesAttachments = Selectable<MessagesAttachmentsTable>;
export type NewMessagesAttachments = Insertable<MessagesAttachmentsTable>; export type NewMessagesAttachments = Insertable<MessagesAttachmentsTable>;
export type MessagesAttachmentsUpdate = Updateable<MessagesAttachmentsTable>; export type MessagesAttachmentsUpdate = Updateable<MessagesAttachmentsTable>;
export const MessagesAttachmentsSchema = z.object({
messageId: messagesMessageid,
userStorageId: usersStorageUserStorageId,
});
export const NewMessagesAttachmentsSchema = z.object({
messageId: messagesMessageid,
userStorageId: usersStorageUserStorageId,
});
export const MessagesAttachmentsUpdateSchema = z.object({
messageId: messagesMessageid.optional(),
userStorageId: usersStorageUserStorageId.optional(),
});

View file

@ -1,4 +1,5 @@
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.nazioni */ /** Identifier type for public.nazioni */
export type NazioniId = number & { __brand: 'public.nazioni' }; export type NazioniId = number & { __brand: 'public.nazioni' };
@ -19,3 +20,26 @@ export type Nazioni = Selectable<NazioniTable>;
export type NewNazioni = Insertable<NazioniTable>; export type NewNazioni = Insertable<NazioniTable>;
export type NazioniUpdate = Updateable<NazioniTable>; export type NazioniUpdate = Updateable<NazioniTable>;
export const nazioniId = z.number().transform(value => value as NazioniId);
export const NazioniSchema = z.object({
id: nazioniId,
nome: z.string(),
catasto: z.string(),
iso: z.string().nullable(),
});
export const NewNazioniSchema = z.object({
id: nazioniId.optional(),
nome: z.string(),
catasto: z.string(),
iso: z.string().optional().nullable(),
});
export const NazioniUpdateSchema = z.object({
id: nazioniId.optional(),
nome: z.string().optional(),
catasto: z.string().optional(),
iso: z.string().optional().nullable(),
});

View file

@ -1,3 +1,5 @@
import { z } from 'zod';
/** Represents the enum public.OrderTypeEnum */ /** Represents the enum public.OrderTypeEnum */
enum OrderTypeEnum { enum OrderTypeEnum {
Acconto = 'Acconto', Acconto = 'Acconto',
@ -8,3 +10,12 @@ enum OrderTypeEnum {
}; };
export default OrderTypeEnum; export default OrderTypeEnum;
/** Zod schema for OrderTypeEnum */
export const orderTypeEnum = z.enum([
'Acconto',
'Saldo',
'Consulenza',
'Altro',
'Rinnovo',
]);

View file

@ -1,10 +1,11 @@
import type { UsersId } from './Users'; import { usersId, type UsersId } from './Users';
import type { PrezziarioIdprezziario } from './Prezziario'; import { prezziarioIdprezziario, type PrezziarioIdprezziario } from './Prezziario';
import type { ServizioServizioId } from './Servizio'; import { servizioServizioId, type ServizioServizioId } from './Servizio';
import type { default as OrderTypeEnum } from './OrderTypeEnum'; import { orderTypeEnum, type default as OrderTypeEnum } from './OrderTypeEnum';
import type { default as PaymentStatusEnum } from './PaymentStatusEnum'; import { paymentStatusEnum, type default as PaymentStatusEnum } from './PaymentStatusEnum';
import type { RinnoviId } from './Rinnovi'; import { rinnoviId, type RinnoviId } from './Rinnovi';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.ordini */ /** Identifier type for public.ordini */
export type OrdiniOrdineId = string & { __brand: 'public.ordini' }; export type OrdiniOrdineId = string & { __brand: 'public.ordini' };
@ -45,3 +46,56 @@ export type Ordini = Selectable<OrdiniTable>;
export type NewOrdini = Insertable<OrdiniTable>; export type NewOrdini = Insertable<OrdiniTable>;
export type OrdiniUpdate = Updateable<OrdiniTable>; export type OrdiniUpdate = Updateable<OrdiniTable>;
export const ordiniOrdineId = z.uuid().transform(value => value as OrdiniOrdineId);
export const OrdiniSchema = z.object({
ordine_id: ordiniOrdineId,
userid: usersId,
created_at: z.date(),
packid: prezziarioIdprezziario,
servizio_id: servizioServizioId.nullable(),
type: orderTypeEnum,
isActive: z.boolean(),
amount_cent: z.number(),
paymentmethod: z.string().nullable(),
paid_at: z.date().nullable(),
intent_id: z.string().nullable(),
paymentstatus: paymentStatusEnum.nullable(),
sconto: z.number(),
rinnovo_id: rinnoviId.nullable(),
});
export const NewOrdiniSchema = z.object({
ordine_id: ordiniOrdineId.optional(),
userid: usersId,
created_at: z.date().optional(),
packid: prezziarioIdprezziario,
servizio_id: servizioServizioId.optional().nullable(),
type: orderTypeEnum,
isActive: z.boolean().optional(),
amount_cent: z.number(),
paymentmethod: z.string().optional().nullable(),
paid_at: z.date().optional().nullable(),
intent_id: z.string().optional().nullable(),
paymentstatus: paymentStatusEnum.optional().nullable(),
sconto: z.number().optional(),
rinnovo_id: rinnoviId.optional().nullable(),
});
export const OrdiniUpdateSchema = z.object({
ordine_id: ordiniOrdineId.optional(),
userid: usersId.optional(),
created_at: z.date().optional(),
packid: prezziarioIdprezziario.optional(),
servizio_id: servizioServizioId.optional().nullable(),
type: orderTypeEnum.optional(),
isActive: z.boolean().optional(),
amount_cent: z.number().optional(),
paymentmethod: z.string().optional().nullable(),
paid_at: z.date().optional().nullable(),
intent_id: z.string().optional().nullable(),
paymentstatus: paymentStatusEnum.optional().nullable(),
sconto: z.number().optional(),
rinnovo_id: rinnoviId.optional().nullable(),
});

View file

@ -1,3 +1,5 @@
import { z } from 'zod';
/** Represents the enum public.PaymentStatusEnum */ /** Represents the enum public.PaymentStatusEnum */
enum PaymentStatusEnum { enum PaymentStatusEnum {
processing = 'processing', processing = 'processing',
@ -6,3 +8,10 @@ enum PaymentStatusEnum {
}; };
export default PaymentStatusEnum; export default PaymentStatusEnum;
/** Zod schema for PaymentStatusEnum */
export const paymentStatusEnum = z.enum([
'processing',
'success',
'failed',
]);

View file

@ -1,6 +1,7 @@
import type { UsersId } from './Users'; import { usersId, type UsersId } from './Users';
import type { PotenzialiGroupsId } from './PotenzialiGroups'; import { potenzialiGroupsId, type PotenzialiGroupsId } from './PotenzialiGroups';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.potenziali */ /** Identifier type for public.potenziali */
export type PotenzialiId = string & { __brand: 'public.potenziali' }; export type PotenzialiId = string & { __brand: 'public.potenziali' };
@ -25,3 +26,32 @@ export type Potenziali = Selectable<PotenzialiTable>;
export type NewPotenziali = Insertable<PotenzialiTable>; export type NewPotenziali = Insertable<PotenzialiTable>;
export type PotenzialiUpdate = Updateable<PotenzialiTable>; export type PotenzialiUpdate = Updateable<PotenzialiTable>;
export const potenzialiId = z.uuid().transform(value => value as PotenzialiId);
export const PotenzialiSchema = z.object({
id: potenzialiId,
name: z.string(),
descrizione: z.string().nullable(),
created_at: z.date(),
userid: usersId.nullable(),
potenziali_group_id: potenzialiGroupsId,
});
export const NewPotenzialiSchema = z.object({
id: potenzialiId.optional(),
name: z.string(),
descrizione: z.string().optional().nullable(),
created_at: z.date().optional(),
userid: usersId.optional().nullable(),
potenziali_group_id: potenzialiGroupsId,
});
export const PotenzialiUpdateSchema = z.object({
id: potenzialiId.optional(),
name: z.string().optional(),
descrizione: z.string().optional().nullable(),
created_at: z.date().optional(),
userid: usersId.optional().nullable(),
potenziali_group_id: potenzialiGroupsId.optional(),
});

View file

@ -1,4 +1,5 @@
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.potenziali_groups */ /** Identifier type for public.potenziali_groups */
export type PotenzialiGroupsId = string & { __brand: 'public.potenziali_groups' }; export type PotenzialiGroupsId = string & { __brand: 'public.potenziali_groups' };
@ -17,3 +18,23 @@ export type PotenzialiGroups = Selectable<PotenzialiGroupsTable>;
export type NewPotenzialiGroups = Insertable<PotenzialiGroupsTable>; export type NewPotenzialiGroups = Insertable<PotenzialiGroupsTable>;
export type PotenzialiGroupsUpdate = Updateable<PotenzialiGroupsTable>; export type PotenzialiGroupsUpdate = Updateable<PotenzialiGroupsTable>;
export const potenzialiGroupsId = z.uuid().transform(value => value as PotenzialiGroupsId);
export const PotenzialiGroupsSchema = z.object({
id: potenzialiGroupsId,
name: z.string(),
color: z.string(),
});
export const NewPotenzialiGroupsSchema = z.object({
id: potenzialiGroupsId.optional(),
name: z.string(),
color: z.string().optional(),
});
export const PotenzialiGroupsUpdateSchema = z.object({
id: potenzialiGroupsId.optional(),
name: z.string().optional(),
color: z.string().optional(),
});

View file

@ -1,6 +1,7 @@
import type { default as OrderTypeEnum } from './OrderTypeEnum'; import { orderTypeEnum, type default as OrderTypeEnum } from './OrderTypeEnum';
import type { default as TipologiaPosizioneEnum } from './TipologiaPosizioneEnum'; import { tipologiaPosizioneEnum, type default as TipologiaPosizioneEnum } from './TipologiaPosizioneEnum';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.prezziario */ /** Identifier type for public.prezziario */
export type PrezziarioIdprezziario = string & { __brand: 'public.prezziario' }; export type PrezziarioIdprezziario = string & { __brand: 'public.prezziario' };
@ -37,3 +38,50 @@ export type Prezziario = Selectable<PrezziarioTable>;
export type NewPrezziario = Insertable<PrezziarioTable>; export type NewPrezziario = Insertable<PrezziarioTable>;
export type PrezziarioUpdate = Updateable<PrezziarioTable>; export type PrezziarioUpdate = Updateable<PrezziarioTable>;
export const prezziarioIdprezziario = z.string().transform(value => value as PrezziarioIdprezziario);
export const PrezziarioSchema = z.object({
idprezziario: prezziarioIdprezziario,
prezzo_cent: z.number(),
testo_condizioni: z.string().nullable(),
isActive: z.boolean(),
nome_it: z.string(),
nome_en: z.string(),
desc_it: z.string(),
desc_en: z.string(),
sconto: z.number(),
order_type: orderTypeEnum.nullable(),
service_type: tipologiaPosizioneEnum.nullable(),
service_variant: z.number().nullable(),
});
export const NewPrezziarioSchema = z.object({
idprezziario: prezziarioIdprezziario,
prezzo_cent: z.number(),
testo_condizioni: z.string().optional().nullable(),
isActive: z.boolean().optional(),
nome_it: z.string(),
nome_en: z.string(),
desc_it: z.string(),
desc_en: z.string(),
sconto: z.number().optional(),
order_type: orderTypeEnum.optional().nullable(),
service_type: tipologiaPosizioneEnum.optional().nullable(),
service_variant: z.number().optional().nullable(),
});
export const PrezziarioUpdateSchema = z.object({
idprezziario: prezziarioIdprezziario.optional(),
prezzo_cent: z.number().optional(),
testo_condizioni: z.string().optional().nullable(),
isActive: z.boolean().optional(),
nome_it: z.string().optional(),
nome_en: z.string().optional(),
desc_it: z.string().optional(),
desc_en: z.string().optional(),
sconto: z.number().optional(),
order_type: orderTypeEnum.optional().nullable(),
service_type: tipologiaPosizioneEnum.optional().nullable(),
service_variant: z.number().optional().nullable(),
});

View file

@ -1,4 +1,5 @@
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.provincie */ /** Identifier type for public.provincie */
export type ProvincieId = number & { __brand: 'public.provincie' }; export type ProvincieId = number & { __brand: 'public.provincie' };
@ -17,3 +18,23 @@ export type Provincie = Selectable<ProvincieTable>;
export type NewProvincie = Insertable<ProvincieTable>; export type NewProvincie = Insertable<ProvincieTable>;
export type ProvincieUpdate = Updateable<ProvincieTable>; export type ProvincieUpdate = Updateable<ProvincieTable>;
export const provincieId = z.number().transform(value => value as ProvincieId);
export const ProvincieSchema = z.object({
id: provincieId,
nome: z.string(),
sigla: z.string(),
});
export const NewProvincieSchema = z.object({
id: provincieId.optional(),
nome: z.string(),
sigla: z.string(),
});
export const ProvincieUpdateSchema = z.object({
id: provincieId.optional(),
nome: z.string().optional(),
sigla: z.string().optional(),
});

View file

@ -1,4 +1,5 @@
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Represents the table public.ratelimiter */ /** Represents the table public.ratelimiter */
export default interface RatelimiterTable { export default interface RatelimiterTable {
@ -14,3 +15,21 @@ export type Ratelimiter = Selectable<RatelimiterTable>;
export type NewRatelimiter = Insertable<RatelimiterTable>; export type NewRatelimiter = Insertable<RatelimiterTable>;
export type RatelimiterUpdate = Updateable<RatelimiterTable>; export type RatelimiterUpdate = Updateable<RatelimiterTable>;
export const RatelimiterSchema = z.object({
key: z.string(),
request_timestamp: z.date(),
request_count: z.number(),
});
export const NewRatelimiterSchema = z.object({
key: z.string(),
request_timestamp: z.date(),
request_count: z.number(),
});
export const RatelimiterUpdateSchema = z.object({
key: z.string().optional(),
request_timestamp: z.date().optional(),
request_count: z.number().optional(),
});

View file

@ -1,5 +1,6 @@
import type { UsersId } from './Users'; import { usersId, type UsersId } from './Users';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.rinnovi */ /** Identifier type for public.rinnovi */
export type RinnoviId = string & { __brand: 'public.rinnovi' }; export type RinnoviId = string & { __brand: 'public.rinnovi' };
@ -24,3 +25,32 @@ export type Rinnovi = Selectable<RinnoviTable>;
export type NewRinnovi = Insertable<RinnoviTable>; export type NewRinnovi = Insertable<RinnoviTable>;
export type RinnoviUpdate = Updateable<RinnoviTable>; export type RinnoviUpdate = Updateable<RinnoviTable>;
export const rinnoviId = z.uuid().transform(value => value as RinnoviId);
export const RinnoviSchema = z.object({
id: rinnoviId,
userId: usersId,
codice: z.string(),
decorrenza: z.date(),
gestionale_id: z.string().nullable(),
scadenza: z.date(),
});
export const NewRinnoviSchema = z.object({
id: rinnoviId.optional(),
userId: usersId,
codice: z.string(),
decorrenza: z.date(),
gestionale_id: z.string().optional().nullable(),
scadenza: z.date(),
});
export const RinnoviUpdateSchema = z.object({
id: rinnoviId.optional(),
userId: usersId.optional(),
codice: z.string().optional(),
decorrenza: z.date().optional(),
gestionale_id: z.string().optional().nullable(),
scadenza: z.date().optional(),
});

View file

@ -1,7 +1,8 @@
import type { UsersId } from './Users'; import { usersId, type UsersId } from './Users';
import type { default as TipologiaPosizioneEnum } from './TipologiaPosizioneEnum'; import { tipologiaPosizioneEnum, type default as TipologiaPosizioneEnum } from './TipologiaPosizioneEnum';
import type { UsersStorageUserStorageId } from './UsersStorage'; import { usersStorageUserStorageId, type UsersStorageUserStorageId } from './UsersStorage';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.servizio */ /** Identifier type for public.servizio */
export type ServizioServizioId = string & { __brand: 'public.servizio' }; export type ServizioServizioId = string & { __brand: 'public.servizio' };
@ -78,3 +79,110 @@ export type Servizio = Selectable<ServizioTable>;
export type NewServizio = Insertable<ServizioTable>; export type NewServizio = Insertable<ServizioTable>;
export type ServizioUpdate = Updateable<ServizioTable>; export type ServizioUpdate = Updateable<ServizioTable>;
export const servizioServizioId = z.uuid().transform(value => value as ServizioServizioId);
export const ServizioSchema = z.object({
servizio_id: servizioServizioId,
user_id: usersId,
created_at: z.date(),
tipologia: tipologiaPosizioneEnum,
arredato: z.boolean(),
budget: z.number(),
n_adulti: z.number(),
n_minori: z.number(),
animali: z.boolean(),
fumatori: z.boolean(),
giardino: z.boolean(),
parcheggio: z.boolean(),
terrazzo: z.boolean(),
ascensore: z.boolean(),
pianoterra: z.boolean(),
motivazione_transitorio: z.string().nullable(),
reddito: z.string().nullable(),
decorrenza: z.date().nullable(),
isInterrotto: z.boolean(),
entromese: z.number().nullable(),
permanenza: z.number().nullable(),
isOkAcconto: z.boolean(),
isOkSaldo: z.boolean(),
isOkConsulenza: z.boolean(),
doc_motivazione_ref: usersStorageUserStorageId.nullable(),
scadenza_motivazione_transitoria: z.date().nullable(),
skipPayment: z.boolean(),
skipControlloDoc: z.boolean(),
skipDocMotivazione: z.boolean(),
onboardOk: z.boolean(),
interruzioneDays: z.number(),
acceptedInterr: z.boolean(),
});
export const NewServizioSchema = z.object({
servizio_id: servizioServizioId.optional(),
user_id: usersId,
created_at: z.date().optional(),
tipologia: tipologiaPosizioneEnum,
arredato: z.boolean().optional(),
budget: z.number(),
n_adulti: z.number(),
n_minori: z.number(),
animali: z.boolean().optional(),
fumatori: z.boolean().optional(),
giardino: z.boolean().optional(),
parcheggio: z.boolean().optional(),
terrazzo: z.boolean().optional(),
ascensore: z.boolean().optional(),
pianoterra: z.boolean().optional(),
motivazione_transitorio: z.string().optional().nullable(),
reddito: z.string().optional().nullable(),
decorrenza: z.date().optional().nullable(),
isInterrotto: z.boolean().optional(),
entromese: z.number().optional().nullable(),
permanenza: z.number().optional().nullable(),
isOkAcconto: z.boolean().optional(),
isOkSaldo: z.boolean().optional(),
isOkConsulenza: z.boolean().optional(),
doc_motivazione_ref: usersStorageUserStorageId.optional().nullable(),
scadenza_motivazione_transitoria: z.date().optional().nullable(),
skipPayment: z.boolean().optional(),
skipControlloDoc: z.boolean().optional(),
skipDocMotivazione: z.boolean().optional(),
onboardOk: z.boolean().optional(),
interruzioneDays: z.number().optional(),
acceptedInterr: z.boolean().optional(),
});
export const ServizioUpdateSchema = z.object({
servizio_id: servizioServizioId.optional(),
user_id: usersId.optional(),
created_at: z.date().optional(),
tipologia: tipologiaPosizioneEnum.optional(),
arredato: z.boolean().optional(),
budget: z.number().optional(),
n_adulti: z.number().optional(),
n_minori: z.number().optional(),
animali: z.boolean().optional(),
fumatori: z.boolean().optional(),
giardino: z.boolean().optional(),
parcheggio: z.boolean().optional(),
terrazzo: z.boolean().optional(),
ascensore: z.boolean().optional(),
pianoterra: z.boolean().optional(),
motivazione_transitorio: z.string().optional().nullable(),
reddito: z.string().optional().nullable(),
decorrenza: z.date().optional().nullable(),
isInterrotto: z.boolean().optional(),
entromese: z.number().optional().nullable(),
permanenza: z.number().optional().nullable(),
isOkAcconto: z.boolean().optional(),
isOkSaldo: z.boolean().optional(),
isOkConsulenza: z.boolean().optional(),
doc_motivazione_ref: usersStorageUserStorageId.optional().nullable(),
scadenza_motivazione_transitoria: z.date().optional().nullable(),
skipPayment: z.boolean().optional(),
skipControlloDoc: z.boolean().optional(),
skipDocMotivazione: z.boolean().optional(),
onboardOk: z.boolean().optional(),
interruzioneDays: z.number().optional(),
acceptedInterr: z.boolean().optional(),
});

View file

@ -1,7 +1,8 @@
import type { ServizioServizioId } from './Servizio'; import { servizioServizioId, type ServizioServizioId } from './Servizio';
import type { AnnunciId } from './Annunci'; import { annunciId, type AnnunciId } from './Annunci';
import type { default as StatusConfermaEnum } from './StatusConfermaEnum'; import { statusConfermaEnum, type default as StatusConfermaEnum } from './StatusConfermaEnum';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.servizio_annunci */ /** Identifier type for public.servizio_annunci */
export type ServizioAnnunciServizioAnnunciId = number & { __brand: 'public.servizio_annunci' }; export type ServizioAnnunciServizioAnnunciId = number & { __brand: 'public.servizio_annunci' };
@ -44,3 +45,59 @@ export type ServizioAnnunci = Selectable<ServizioAnnunciTable>;
export type NewServizioAnnunci = Insertable<ServizioAnnunciTable>; export type NewServizioAnnunci = Insertable<ServizioAnnunciTable>;
export type ServizioAnnunciUpdate = Updateable<ServizioAnnunciTable>; export type ServizioAnnunciUpdate = Updateable<ServizioAnnunciTable>;
export const servizioAnnunciServizioAnnunciId = z.number().transform(value => value as ServizioAnnunciServizioAnnunciId);
export const ServizioAnnunciSchema = z.object({
servizio_annunci_id: servizioAnnunciServizioAnnunciId,
servizio_id: servizioServizioId,
annunci_id: annunciId,
created_at: z.date(),
open_contatti_at: z.date().nullable(),
doc_contratto_ref: z.string().nullable(),
gestionale_id: z.number().nullable(),
contratto_decorrenza: z.date().nullable(),
contratto_scadenza: z.date().nullable(),
contratto_tipo: z.string().nullable(),
doc_registrazione_ref: z.string().nullable(),
doc_contratto_added: z.boolean(),
doc_registrazione_added: z.boolean(),
note: z.string().nullable(),
status_conferma: statusConfermaEnum.nullable(),
});
export const NewServizioAnnunciSchema = z.object({
servizio_annunci_id: servizioAnnunciServizioAnnunciId.optional(),
servizio_id: servizioServizioId,
annunci_id: annunciId,
created_at: z.date().optional(),
open_contatti_at: z.date().optional().nullable(),
doc_contratto_ref: z.string().optional().nullable(),
gestionale_id: z.number().optional().nullable(),
contratto_decorrenza: z.date().optional().nullable(),
contratto_scadenza: z.date().optional().nullable(),
contratto_tipo: z.string().optional().nullable(),
doc_registrazione_ref: z.string().optional().nullable(),
doc_contratto_added: z.boolean().optional(),
doc_registrazione_added: z.boolean().optional(),
note: z.string().optional().nullable(),
status_conferma: statusConfermaEnum.optional().nullable(),
});
export const ServizioAnnunciUpdateSchema = z.object({
servizio_annunci_id: servizioAnnunciServizioAnnunciId.optional(),
servizio_id: servizioServizioId.optional(),
annunci_id: annunciId.optional(),
created_at: z.date().optional(),
open_contatti_at: z.date().optional().nullable(),
doc_contratto_ref: z.string().optional().nullable(),
gestionale_id: z.number().optional().nullable(),
contratto_decorrenza: z.date().optional().nullable(),
contratto_scadenza: z.date().optional().nullable(),
contratto_tipo: z.string().optional().nullable(),
doc_registrazione_ref: z.string().optional().nullable(),
doc_contratto_added: z.boolean().optional(),
doc_registrazione_added: z.boolean().optional(),
note: z.string().optional().nullable(),
status_conferma: statusConfermaEnum.optional().nullable(),
});

View file

@ -1,6 +1,7 @@
import type { AnnunciId } from './Annunci'; import { annunciId, type AnnunciId } from './Annunci';
import type { UsersId } from './Users'; import { usersId, type UsersId } from './Users';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Represents the table public.servizio_interessi */ /** Represents the table public.servizio_interessi */
export default interface ServizioInteressiTable { export default interface ServizioInteressiTable {
@ -14,3 +15,18 @@ export type ServizioInteressi = Selectable<ServizioInteressiTable>;
export type NewServizioInteressi = Insertable<ServizioInteressiTable>; export type NewServizioInteressi = Insertable<ServizioInteressiTable>;
export type ServizioInteressiUpdate = Updateable<ServizioInteressiTable>; export type ServizioInteressiUpdate = Updateable<ServizioInteressiTable>;
export const ServizioInteressiSchema = z.object({
annuncioId: annunciId,
userId: usersId,
});
export const NewServizioInteressiSchema = z.object({
annuncioId: annunciId,
userId: usersId,
});
export const ServizioInteressiUpdateSchema = z.object({
annuncioId: annunciId.optional(),
userId: usersId.optional(),
});

View file

@ -1,3 +1,5 @@
import { z } from 'zod';
/** Represents the enum public.StatusConfermaEnum */ /** Represents the enum public.StatusConfermaEnum */
enum StatusConfermaEnum { enum StatusConfermaEnum {
'Inviato conferma' = 'Inviato conferma', 'Inviato conferma' = 'Inviato conferma',
@ -6,3 +8,10 @@ enum StatusConfermaEnum {
}; };
export default StatusConfermaEnum; export default StatusConfermaEnum;
/** Zod schema for StatusConfermaEnum */
export const statusConfermaEnum = z.enum([
'Inviato conferma',
'Conferma accettata',
'Caparra versata',
]);

View file

@ -1,4 +1,5 @@
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.testi_e_stringhe */ /** Identifier type for public.testi_e_stringhe */
export type TestiEStringheStingaId = string & { __brand: 'public.testi_e_stringhe' }; export type TestiEStringheStingaId = string & { __brand: 'public.testi_e_stringhe' };
@ -15,3 +16,20 @@ export type TestiEStringhe = Selectable<TestiEStringheTable>;
export type NewTestiEStringhe = Insertable<TestiEStringheTable>; export type NewTestiEStringhe = Insertable<TestiEStringheTable>;
export type TestiEStringheUpdate = Updateable<TestiEStringheTable>; export type TestiEStringheUpdate = Updateable<TestiEStringheTable>;
export const testiEStringheStingaId = z.string().transform(value => value as TestiEStringheStingaId);
export const TestiEStringheSchema = z.object({
stinga_id: testiEStringheStingaId,
stringa_value: z.string().nullable(),
});
export const NewTestiEStringheSchema = z.object({
stinga_id: testiEStringheStingaId,
stringa_value: z.string().optional().nullable(),
});
export const TestiEStringheUpdateSchema = z.object({
stinga_id: testiEStringheStingaId.optional(),
stringa_value: z.string().optional().nullable(),
});

View file

@ -1,3 +1,5 @@
import { z } from 'zod';
/** Represents the enum public.TipologiaPosizioneEnum */ /** Represents the enum public.TipologiaPosizioneEnum */
enum TipologiaPosizioneEnum { enum TipologiaPosizioneEnum {
Transitorio = 'Transitorio', Transitorio = 'Transitorio',
@ -5,3 +7,9 @@ enum TipologiaPosizioneEnum {
}; };
export default TipologiaPosizioneEnum; export default TipologiaPosizioneEnum;
/** Zod schema for TipologiaPosizioneEnum */
export const tipologiaPosizioneEnum = z.enum([
'Transitorio',
'Stabile',
]);

View file

@ -1,6 +1,7 @@
import type { UsersId } from './Users'; import { usersId, type UsersId } from './Users';
import type { EtichetteIdEtichetta } from './Etichette'; import { etichetteIdEtichetta, type EtichetteIdEtichetta } from './Etichette';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Represents the table public.user_etichette */ /** Represents the table public.user_etichette */
export default interface UserEtichetteTable { export default interface UserEtichetteTable {
@ -14,3 +15,18 @@ export type UserEtichette = Selectable<UserEtichetteTable>;
export type NewUserEtichette = Insertable<UserEtichetteTable>; export type NewUserEtichette = Insertable<UserEtichetteTable>;
export type UserEtichetteUpdate = Updateable<UserEtichetteTable>; export type UserEtichetteUpdate = Updateable<UserEtichetteTable>;
export const UserEtichetteSchema = z.object({
userId: usersId,
etichettaId: etichetteIdEtichetta,
});
export const NewUserEtichetteSchema = z.object({
userId: usersId,
etichettaId: etichetteIdEtichetta,
});
export const UserEtichetteUpdateSchema = z.object({
userId: usersId.optional(),
etichettaId: etichetteIdEtichetta.optional(),
});

View file

@ -1,4 +1,5 @@
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.user_invites */ /** Identifier type for public.user_invites */
export type UserInvitesId = string & { __brand: 'public.user_invites' }; export type UserInvitesId = string & { __brand: 'public.user_invites' };
@ -21,3 +22,29 @@ export type UserInvites = Selectable<UserInvitesTable>;
export type NewUserInvites = Insertable<UserInvitesTable>; export type NewUserInvites = Insertable<UserInvitesTable>;
export type UserInvitesUpdate = Updateable<UserInvitesTable>; export type UserInvitesUpdate = Updateable<UserInvitesTable>;
export const userInvitesId = z.uuid().transform(value => value as UserInvitesId);
export const UserInvitesSchema = z.object({
id: userInvitesId,
email: z.string(),
token: z.string(),
expires_at: z.date(),
created_at: z.date().nullable(),
});
export const NewUserInvitesSchema = z.object({
id: userInvitesId.optional(),
email: z.string(),
token: z.string(),
expires_at: z.date(),
created_at: z.date().optional().nullable(),
});
export const UserInvitesUpdateSchema = z.object({
id: userInvitesId.optional(),
email: z.string().optional(),
token: z.string().optional(),
expires_at: z.date().optional(),
created_at: z.date().optional().nullable(),
});

View file

@ -1,4 +1,5 @@
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.users */ /** Identifier type for public.users */
export type UsersId = string & { __brand: 'public.users' }; export type UsersId = string & { __brand: 'public.users' };
@ -51,3 +52,74 @@ export type Users = Selectable<UsersTable>;
export type NewUsers = Insertable<UsersTable>; export type NewUsers = Insertable<UsersTable>;
export type UsersUpdate = Updateable<UsersTable>; export type UsersUpdate = Updateable<UsersTable>;
export const usersId = z.uuid().transform(value => value as UsersId);
export const UsersSchema = z.object({
id: usersId,
username: z.string(),
email: z.string(),
isAdmin: z.boolean(),
isBlocked: z.boolean(),
password: z.string(),
nome: z.string(),
cognome: z.string(),
created_at: z.date(),
reset_password_token: z.string().nullable(),
reset_password_expires: z.date().nullable(),
telefono: z.string(),
isAdminMade: z.boolean().nullable(),
salt: z.string(),
mustChangePassword: z.boolean(),
note: z.string().nullable(),
comms_enabled: z.boolean(),
extra_telefono_titolo: z.string().nullable(),
extra_telefono_numero: z.string().nullable(),
usedInvite: z.boolean(),
});
export const NewUsersSchema = z.object({
id: usersId.optional(),
username: z.string(),
email: z.string(),
isAdmin: z.boolean().optional(),
isBlocked: z.boolean().optional(),
password: z.string(),
nome: z.string(),
cognome: z.string(),
created_at: z.date().optional(),
reset_password_token: z.string().optional().nullable(),
reset_password_expires: z.date().optional().nullable(),
telefono: z.string(),
isAdminMade: z.boolean().optional().nullable(),
salt: z.string(),
mustChangePassword: z.boolean().optional(),
note: z.string().optional().nullable(),
comms_enabled: z.boolean().optional(),
extra_telefono_titolo: z.string().optional().nullable(),
extra_telefono_numero: z.string().optional().nullable(),
usedInvite: z.boolean().optional(),
});
export const UsersUpdateSchema = z.object({
id: usersId.optional(),
username: z.string().optional(),
email: z.string().optional(),
isAdmin: z.boolean().optional(),
isBlocked: z.boolean().optional(),
password: z.string().optional(),
nome: z.string().optional(),
cognome: z.string().optional(),
created_at: z.date().optional(),
reset_password_token: z.string().optional().nullable(),
reset_password_expires: z.date().optional().nullable(),
telefono: z.string().optional(),
isAdminMade: z.boolean().optional().nullable(),
salt: z.string().optional(),
mustChangePassword: z.boolean().optional(),
note: z.string().optional().nullable(),
comms_enabled: z.boolean().optional(),
extra_telefono_titolo: z.string().optional().nullable(),
extra_telefono_numero: z.string().optional().nullable(),
usedInvite: z.boolean().optional(),
});

View file

@ -1,6 +1,7 @@
import type { UsersId } from './Users'; import { usersId, type UsersId } from './Users';
import type { UsersStorageUserStorageId } from './UsersStorage'; import { usersStorageUserStorageId, type UsersStorageUserStorageId } from './UsersStorage';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.users_anagrafica */ /** Identifier type for public.users_anagrafica */
export type UsersAnagraficaIdanagrafica = string & { __brand: 'public.users_anagrafica' }; export type UsersAnagraficaIdanagrafica = string & { __brand: 'public.users_anagrafica' };
@ -43,3 +44,59 @@ export type UsersAnagrafica = Selectable<UsersAnagraficaTable>;
export type NewUsersAnagrafica = Insertable<UsersAnagraficaTable>; export type NewUsersAnagrafica = Insertable<UsersAnagraficaTable>;
export type UsersAnagraficaUpdate = Updateable<UsersAnagraficaTable>; export type UsersAnagraficaUpdate = Updateable<UsersAnagraficaTable>;
export const usersAnagraficaIdanagrafica = z.uuid().transform(value => value as UsersAnagraficaIdanagrafica);
export const UsersAnagraficaSchema = z.object({
idanagrafica: usersAnagraficaIdanagrafica,
userid: usersId,
luogo_nascita: z.string().nullable(),
data_nascita: z.date().nullable(),
nazione_nascita: z.string().nullable(),
codice_fiscale: z.string().nullable(),
via_residenza: z.string().nullable(),
civico_residenza: z.string().nullable(),
comune_residenza: z.string().nullable(),
provincia_residenza: z.string().nullable(),
cap_residenza: z.string().nullable(),
nazione_residenza: z.string().nullable(),
sesso: z.string().nullable(),
doc_personale_fronte_ref: usersStorageUserStorageId.nullable(),
doc_personale_retro_ref: usersStorageUserStorageId.nullable(),
});
export const NewUsersAnagraficaSchema = z.object({
idanagrafica: usersAnagraficaIdanagrafica.optional(),
userid: usersId,
luogo_nascita: z.string().optional().nullable(),
data_nascita: z.date().optional().nullable(),
nazione_nascita: z.string().optional().nullable(),
codice_fiscale: z.string().optional().nullable(),
via_residenza: z.string().optional().nullable(),
civico_residenza: z.string().optional().nullable(),
comune_residenza: z.string().optional().nullable(),
provincia_residenza: z.string().optional().nullable(),
cap_residenza: z.string().optional().nullable(),
nazione_residenza: z.string().optional().nullable(),
sesso: z.string().optional().nullable(),
doc_personale_fronte_ref: usersStorageUserStorageId.optional().nullable(),
doc_personale_retro_ref: usersStorageUserStorageId.optional().nullable(),
});
export const UsersAnagraficaUpdateSchema = z.object({
idanagrafica: usersAnagraficaIdanagrafica.optional(),
userid: usersId.optional(),
luogo_nascita: z.string().optional().nullable(),
data_nascita: z.date().optional().nullable(),
nazione_nascita: z.string().optional().nullable(),
codice_fiscale: z.string().optional().nullable(),
via_residenza: z.string().optional().nullable(),
civico_residenza: z.string().optional().nullable(),
comune_residenza: z.string().optional().nullable(),
provincia_residenza: z.string().optional().nullable(),
cap_residenza: z.string().optional().nullable(),
nazione_residenza: z.string().optional().nullable(),
sesso: z.string().optional().nullable(),
doc_personale_fronte_ref: usersStorageUserStorageId.optional().nullable(),
doc_personale_retro_ref: usersStorageUserStorageId.optional().nullable(),
});

View file

@ -1,5 +1,6 @@
import type { UsersId } from './Users'; import { usersId, type UsersId } from './Users';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.users_storage */ /** Identifier type for public.users_storage */
export type UsersStorageUserStorageId = string & { __brand: 'public.users_storage' }; export type UsersStorageUserStorageId = string & { __brand: 'public.users_storage' };
@ -20,3 +21,26 @@ export type UsersStorage = Selectable<UsersStorageTable>;
export type NewUsersStorage = Insertable<UsersStorageTable>; export type NewUsersStorage = Insertable<UsersStorageTable>;
export type UsersStorageUpdate = Updateable<UsersStorageTable>; export type UsersStorageUpdate = Updateable<UsersStorageTable>;
export const usersStorageUserStorageId = z.uuid().transform(value => value as UsersStorageUserStorageId);
export const UsersStorageSchema = z.object({
user_storage_id: usersStorageUserStorageId,
userId: usersId,
storageId: z.string(),
from_admin: z.boolean(),
});
export const NewUsersStorageSchema = z.object({
user_storage_id: usersStorageUserStorageId.optional(),
userId: usersId,
storageId: z.string(),
from_admin: z.boolean().optional(),
});
export const UsersStorageUpdateSchema = z.object({
user_storage_id: usersStorageUserStorageId.optional(),
userId: usersId.optional(),
storageId: z.string().optional(),
from_admin: z.boolean().optional(),
});

View file

@ -1,4 +1,5 @@
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely'; import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Represents the table public.videos_refs */ /** Represents the table public.videos_refs */
export default interface VideosRefsTable { export default interface VideosRefsTable {
@ -18,3 +19,27 @@ export type VideosRefs = Selectable<VideosRefsTable>;
export type NewVideosRefs = Insertable<VideosRefsTable>; export type NewVideosRefs = Insertable<VideosRefsTable>;
export type VideosRefsUpdate = Updateable<VideosRefsTable>; export type VideosRefsUpdate = Updateable<VideosRefsTable>;
export const VideosRefsSchema = z.object({
codice: z.string(),
ordine: z.number(),
video: z.string(),
thumb: z.string(),
og_url: z.string(),
});
export const NewVideosRefsSchema = z.object({
codice: z.string(),
ordine: z.number(),
video: z.string(),
thumb: z.string(),
og_url: z.string(),
});
export const VideosRefsUpdateSchema = z.object({
codice: z.string().optional(),
ordine: z.number().optional(),
video: z.string().optional(),
thumb: z.string().optional(),
og_url: z.string().optional(),
});

View file

@ -1,5 +1,34 @@
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc"; import z from "zod";
import { import {
ComuniUpdateSchema,
comuniId,
NewComuniSchema,
} from "~/schemas/public/Comuni";
import {
NazioniUpdateSchema,
NewNazioniSchema,
nazioniId,
} from "~/schemas/public/Nazioni";
import {
NewProvincieSchema,
ProvincieUpdateSchema,
provincieId,
} from "~/schemas/public/Provincie";
import {
adminProcedure,
createTRPCRouter,
publicProcedure,
} from "~/server/api/trpc";
import {
createComune,
createNazione,
createProvincia,
deleteComune,
deleteNazione,
deleteProvincia,
editComune,
editNazione,
editProvincia,
getComuni, getComuni,
getNazioni, getNazioni,
getProvincie, getProvincie,
@ -9,11 +38,86 @@ export const catastoRouter = createTRPCRouter({
getComuni: publicProcedure.query(async () => { getComuni: publicProcedure.query(async () => {
return await getComuni(); return await getComuni();
}), }),
createComune: adminProcedure
.input(NewComuniSchema)
.mutation(async ({ input }) => {
return await createComune(input);
}),
editComune: adminProcedure
.input(
z.object({
id: comuniId,
data: ComuniUpdateSchema,
}),
)
.mutation(async ({ input }) => {
const { id, data } = input;
return await editComune({ id, data });
}),
deleteComune: adminProcedure
.input(
z.object({
id: comuniId,
}),
)
.mutation(async ({ input }) => {
return await deleteComune(input.id);
}),
getProvincie: publicProcedure.query(async () => { getProvincie: publicProcedure.query(async () => {
return await getProvincie(); return await getProvincie();
}), }),
createProvincia: adminProcedure
.input(NewProvincieSchema)
.mutation(async ({ input }) => {
return await createProvincia(input);
}),
editProvincia: adminProcedure
.input(
z.object({
id: provincieId,
data: ProvincieUpdateSchema,
}),
)
.mutation(async ({ input }) => {
const { id, data } = input;
return await editProvincia({ id, data });
}),
deleteProvincia: adminProcedure
.input(
z.object({
id: provincieId,
}),
)
.mutation(async ({ input }) => {
return await deleteProvincia(input.id);
}),
getNazioni: publicProcedure.query(async () => { getNazioni: publicProcedure.query(async () => {
return await getNazioni(); return await getNazioni();
}), }),
createNazione: adminProcedure
.input(NewNazioniSchema)
.mutation(async ({ input }) => {
return await createNazione(input);
}),
editNazione: adminProcedure
.input(
z.object({
id: nazioniId,
data: NazioniUpdateSchema,
}),
)
.mutation(async ({ input }) => {
const { id, data } = input;
return await editNazione({ id, data });
}),
deleteNazione: adminProcedure
.input(
z.object({
id: nazioniId,
}),
)
.mutation(async ({ input }) => {
return await deleteNazione(input.id);
}),
}); });

View file

@ -1,5 +1,20 @@
import { TRPCError } from "@trpc/server"; import { TRPCError } from "@trpc/server";
import { sql } from "kysely"; import { sql } from "kysely";
import type {
ComuniId,
ComuniUpdate,
NewComuni,
} from "~/schemas/public/Comuni";
import type {
NazioniId,
NazioniUpdate,
NewNazioni,
} from "~/schemas/public/Nazioni";
import type {
NewProvincie,
ProvincieId,
ProvincieUpdate,
} from "~/schemas/public/Provincie";
import { db } from "../db"; import { db } from "../db";
export const getComuni = async () => { export const getComuni = async () => {
@ -17,6 +32,48 @@ export const getComuni = async () => {
} }
}; };
export const editComune = async ({
id,
data,
}: {
id: ComuniId;
data: ComuniUpdate;
}) => {
try {
await db.updateTable("comuni").set(data).where("id", "=", id).execute();
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: `Error while editing Comune: ${(e as Error).message}`,
});
}
};
export const createComune = async (data: NewComuni) => {
const { id, ...rest } = data;
try {
await db.insertInto("comuni").values(rest).execute();
return "ok";
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: `Error while creating Comune: ${(e as Error).message}`,
});
}
};
export const deleteComune = async (id: ComuniId) => {
try {
await db.deleteFrom("comuni").where("id", "=", id).execute();
return "ok";
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: `Error while deleting Comune: ${(e as Error).message}`,
});
}
};
export const getProvincie = async () => { export const getProvincie = async () => {
try { try {
return await db.selectFrom("provincie").selectAll().execute(); return await db.selectFrom("provincie").selectAll().execute();
@ -28,6 +85,49 @@ export const getProvincie = async () => {
} }
}; };
export const editProvincia = async ({
id,
data,
}: {
id: ProvincieId;
data: ProvincieUpdate;
}) => {
try {
await db.updateTable("provincie").set(data).where("id", "=", id).execute();
return "ok";
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: `Error while editing Provincia: ${(e as Error).message}`,
});
}
};
export const createProvincia = async (data: NewProvincie) => {
const { id, ...rest } = data;
try {
await db.insertInto("provincie").values(rest).execute();
return "ok";
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: `Error while creating Provincia: ${(e as Error).message}`,
});
}
};
export const deleteProvincia = async (id: ProvincieId) => {
try {
await db.deleteFrom("provincie").where("id", "=", id).execute();
return "ok";
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: `Error while deleting Provincia: ${(e as Error).message}`,
});
}
};
export const getNazioni = async () => { export const getNazioni = async () => {
try { try {
return await db return await db
@ -43,3 +143,46 @@ export const getNazioni = async () => {
}); });
} }
}; };
export const editNazione = async ({
id,
data,
}: {
id: NazioniId;
data: NazioniUpdate;
}) => {
try {
await db.updateTable("nazioni").set(data).where("id", "=", id).execute();
return "ok";
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: `Error while editing Nazione: ${(e as Error).message}`,
});
}
};
export const createNazione = async (data: NewNazioni) => {
const { id, ...rest } = data;
try {
await db.insertInto("nazioni").values(rest).execute();
return "ok";
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: `Error while creating Nazione: ${(e as Error).message}`,
});
}
};
export const deleteNazione = async (id: NazioniId) => {
try {
await db.deleteFrom("nazioni").where("id", "=", id).execute();
return "ok";
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: `Error while deleting Nazione: ${(e as Error).message}`,
});
}
};

View file

@ -3,12 +3,15 @@ import type { AnnunciId } from "~/schemas/public/Annunci";
import type { BanlistId } from "~/schemas/public/Banlist"; import type { BanlistId } from "~/schemas/public/Banlist";
import BanType from "~/schemas/public/BanType"; import BanType from "~/schemas/public/BanType";
import type { ChatsChatid } from "~/schemas/public/Chats"; import type { ChatsChatid } from "~/schemas/public/Chats";
import type { ComuniId } from "~/schemas/public/Comuni";
import type { EtichetteIdEtichetta } from "~/schemas/public/Etichette"; import type { EtichetteIdEtichetta } from "~/schemas/public/Etichette";
import type { EventQueueEventId } from "~/schemas/public/EventQueue"; import type { EventQueueEventId } from "~/schemas/public/EventQueue";
import type { FlagsId } from "~/schemas/public/Flags"; import type { FlagsId } from "~/schemas/public/Flags";
import type { MessagesMessageid } from "~/schemas/public/Messages"; import type { MessagesMessageid } from "~/schemas/public/Messages";
import type { NazioniId } from "~/schemas/public/Nazioni";
import type { OrdiniOrdineId } from "~/schemas/public/Ordini"; import type { OrdiniOrdineId } from "~/schemas/public/Ordini";
import type { PrezziarioIdprezziario } from "~/schemas/public/Prezziario"; import type { PrezziarioIdprezziario } from "~/schemas/public/Prezziario";
import type { ProvincieId } from "~/schemas/public/Provincie";
import type { RinnoviId } from "~/schemas/public/Rinnovi"; import type { RinnoviId } from "~/schemas/public/Rinnovi";
import type { ServizioServizioId } from "~/schemas/public/Servizio"; import type { ServizioServizioId } from "~/schemas/public/Servizio";
import type { TestiEStringheStingaId } from "~/schemas/public/TestiEStringhe"; import type { TestiEStringheStingaId } from "~/schemas/public/TestiEStringhe";
@ -84,15 +87,20 @@ export const zServizioId = z.custom<ServizioServizioId>(
"falied to validate ServizioId", "falied to validate ServizioId",
); );
// export const zComuneId = z.custom<ComuniId>( export const zComuneId = z.custom<ComuniId>(
// (val) => typeof val === "number", (val) => typeof val === "number",
// "falied to validate ComuneId", "falied to validate ComuneId",
// ); );
// export const zNazioneId = z.custom<NazioniId>( export const zProvincieId = z.custom<ProvincieId>(
// (val) => typeof val === "number", (val) => typeof val === "number",
// "falied to validate NazioneId", "falied to validate ProvinciaId",
// ); );
export const zNazioneId = z.custom<NazioniId>(
(val) => typeof val === "number",
"falied to validate NazioneId",
);
export const zRinnovoId = z.custom<RinnoviId>( export const zRinnovoId = z.custom<RinnoviId>(
(val) => typeof val === "string", (val) => typeof val === "string",