From f46a11d762d605510312c11b1553dae571da65ca Mon Sep 17 00:00:00 2001 From: AV77web Date: Mon, 22 Jun 2026 16:51:56 +0200 Subject: [PATCH] inseriti i types e i constraints e aggiunta la via in 02_seed.sql --- initdb/01_schema.sql | 1 + src/types/index.ts | 35 ++++++++++++++++++++++++++++++ src/validation/constraints.ts | 40 +++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 src/types/index.ts create mode 100644 src/validation/constraints.ts diff --git a/initdb/01_schema.sql b/initdb/01_schema.sql index a42ddae..975191f 100644 --- a/initdb/01_schema.sql +++ b/initdb/01_schema.sql @@ -32,6 +32,7 @@ CREATE TABLE IF NOT EXISTS cliente ( ClienteID INT UNSIGNED NOT NULL AUTO_INCREMENT, Nome VARCHAR(100) NOT NULL, Cognome VARCHAR(100) NOT NULL, + Via VARCHAR(100) NOT NULL, Comune VARCHAR(100) NOT NULL, Provincia VARCHAR(2) NOT NULL, Telefono VARCHAR(30) NOT NULL, diff --git a/src/types/index.ts b/src/types/index.ts new file mode 100644 index 0000000..cb5febd --- /dev/null +++ b/src/types/index.ts @@ -0,0 +1,35 @@ +import { CONSEGNA_CONSTRAINTS, UTENTE_CONSTRAINTS } from "../validation/constraints.js"; + +export type Ruolo = (typeof UTENTE_CONSTRAINTS.ruolo.allowedValues)[number]; + +export type StatoConsegna = (typeof CONSEGNA_CONSTRAINTS.stato.allowedValues)[number]; + +export interface Utente { + UtenteID: number; + Nome: string; + Cognome: string; + Email: string; + PasswordHash: string; + Ruolo: Ruolo; +} + +export interface Cliente { + ClienteID: number; + Nome: string; + Via: string; + Cognome: string; + Comune: string; + Provincia: string; + Telefono: string; + Email: string; + Note: string | null; +} + +export interface Consegna { + ConsegnaID: number; + ClienteID: number; + DataRitiro: Date; + DataConsegna: Date; + Stato: StatoConsegna; + ChiaveConsegna: string; +} diff --git a/src/validation/constraints.ts b/src/validation/constraints.ts new file mode 100644 index 0000000..abc5035 --- /dev/null +++ b/src/validation/constraints.ts @@ -0,0 +1,40 @@ +//========================================= +// File: constraints.ts +// Vincoli derivati da initdb/01_schema.sql. +// author: "villari.andrea@libero.it" +// version: "1.0.0 2026-06-18" +//========================================= + +export const UTENTE_CONSTRAINTS = { + nome: { maxLength: 100, required: true }, + cognome: { maxLength: 100, required: true }, + email: { maxLength: 255, required: true }, + password: { minLength: 8, maxLength: 72, required: true }, + ruolo: {allowedValues: ["Operatore", "Amministratore"], + required: true, + } + } as const; + + export const CLIENTE_CONSTRAINTS = { + nome: { maxLength: 100, required: true }, + cognome: { maxLength: 100, required: true }, + via: {maxLength: 100, required: true}, + Comune: {maxLength: 100, required: true}, + Provincia: {maxLength: 2, required: true}, + telefono: { maxLength: 30, required: true }, + email: { maxLength: 255, required: true }, + note: { required: false }, + } as const; + + + export const CONSEGNA_CONSTRAINTS = { + dataconsegna: { required: true }, + dataritiro: {required: true}, + stato: { + allowedValues: ["da ritirare", "in consegna", "in giacenza", "in deposito"], + required: true, + }, + chiaveConsegna: { maxLength: 8, required: true }, + clienteId: { required: true }, + } as const; + \ No newline at end of file