160 lines
7.1 KiB
TypeScript
160 lines
7.1 KiB
TypeScript
import {
|
|
boolean,
|
|
int,
|
|
mysqlEnum,
|
|
mysqlTable,
|
|
text,
|
|
timestamp,
|
|
varchar,
|
|
} from "drizzle-orm/mysql-core";
|
|
|
|
// ─── Utilisateurs ────────────────────────────────────────────────────────────
|
|
|
|
export const users = mysqlTable("users", {
|
|
id: int("id").autoincrement().primaryKey(),
|
|
openId: varchar("openId", { length: 64 }).notNull().unique(),
|
|
name: text("name"),
|
|
email: varchar("email", { length: 320 }),
|
|
loginMethod: varchar("loginMethod", { length: 64 }),
|
|
role: mysqlEnum("role", ["user", "admin"]).default("user").notNull(),
|
|
// Profil SONUM : referent = référent numérique, gestionnaire = gestionnaire SONUM
|
|
sonumRole: mysqlEnum("sonumRole", ["referent", "gestionnaire"]).default("referent").notNull(),
|
|
// CGU acceptée
|
|
cguAccepted: boolean("cguAccepted").default(false).notNull(),
|
|
cguAcceptedAt: timestamp("cguAcceptedAt"),
|
|
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
|
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
|
|
lastSignedIn: timestamp("lastSignedIn").defaultNow().notNull(),
|
|
});
|
|
|
|
export type User = typeof users.$inferSelect;
|
|
export type InsertUser = typeof users.$inferInsert;
|
|
|
|
// ─── Référentiel : Éditeurs ───────────────────────────────────────────────────
|
|
|
|
export const editeurs = mysqlTable("editeurs", {
|
|
id: int("id").autoincrement().primaryKey(),
|
|
nom: varchar("nom", { length: 255 }).notNull(),
|
|
estValide: boolean("estValide").default(true).notNull(), // false = ajouté par un référent, en attente de validation FEHAP
|
|
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
|
});
|
|
|
|
export type Editeur = typeof editeurs.$inferSelect;
|
|
|
|
// ─── Référentiel : Blocs Fonctionnels ────────────────────────────────────────
|
|
|
|
export const blocsFonctionnels = mysqlTable("blocs_fonctionnels", {
|
|
id: int("id").autoincrement().primaryKey(),
|
|
nom: varchar("nom", { length: 255 }).notNull(),
|
|
estValide: boolean("estValide").default(true).notNull(),
|
|
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
|
});
|
|
|
|
export type BlocFonctionnel = typeof blocsFonctionnels.$inferSelect;
|
|
|
|
// ─── Référentiel : Solutions ──────────────────────────────────────────────────
|
|
|
|
export const solutions = mysqlTable("solutions", {
|
|
id: int("id").autoincrement().primaryKey(),
|
|
nom: varchar("nom", { length: 255 }).notNull(),
|
|
editeurId: int("editeurId").notNull(),
|
|
blocFonctionnelId: int("blocFonctionnelId"),
|
|
estValide: boolean("estValide").default(true).notNull(),
|
|
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
|
});
|
|
|
|
export type Solution = typeof solutions.$inferSelect;
|
|
|
|
// ─── Établissements ───────────────────────────────────────────────────────────
|
|
|
|
export const etablissements = mysqlTable("etablissements", {
|
|
id: int("id").autoincrement().primaryKey(),
|
|
finess: varchar("finess", { length: 20 }),
|
|
nom: varchar("nom", { length: 255 }).notNull(),
|
|
region: varchar("region", { length: 100 }),
|
|
departement: varchar("departement", { length: 100 }),
|
|
typeActivite: varchar("typeActivite", { length: 100 }),
|
|
tailleEffectifs: varchar("tailleEffectifs", { length: 50 }),
|
|
// Référent numérique responsable
|
|
referentId: int("referentId"),
|
|
// Visibilité : "tous" = visible par tous les référents, "gestionnaires" = visible uniquement par gestionnaires SONUM
|
|
visibilite: mysqlEnum("visibilite", ["tous", "gestionnaires"]).default("tous").notNull(),
|
|
// Acceptation mise en relation
|
|
accepteMiseEnRelation: boolean("accepteMiseEnRelation").default(true).notNull(),
|
|
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
|
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
|
|
});
|
|
|
|
export type Etablissement = typeof etablissements.$inferSelect;
|
|
|
|
// ─── Logiciels par Établissement ─────────────────────────────────────────────
|
|
|
|
export const logicielsEtablissements = mysqlTable("logiciels_etablissements", {
|
|
id: int("id").autoincrement().primaryKey(),
|
|
etablissementId: int("etablissementId").notNull(),
|
|
solutionId: int("solutionId").notNull(),
|
|
etatDeploiement: mysqlEnum("etatDeploiement", [
|
|
"demarrage",
|
|
"en_cours",
|
|
"operationnel",
|
|
"en_remplacement",
|
|
]).notNull(),
|
|
modeHebergement: mysqlEnum("modeHebergement", [
|
|
"hds",
|
|
"on_premise",
|
|
"hybride",
|
|
]),
|
|
modeFacturation: mysqlEnum("modeFacturation", [
|
|
"saas",
|
|
"achat_maintenance",
|
|
"location",
|
|
]),
|
|
interoperabilite: mysqlEnum("interoperabilite", ["non", "oui_interface", "oui_eai"]),
|
|
versionMajeure: varchar("versionMajeure", { length: 50 }),
|
|
commentaire: text("commentaire"),
|
|
// Contact référent pour ce logiciel
|
|
contactNom: varchar("contactNom", { length: 255 }),
|
|
contactFonction: varchar("contactFonction", { length: 255 }),
|
|
contactEmail: varchar("contactEmail", { length: 320 }),
|
|
saisiePar: int("saisiePar"), // userId
|
|
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
|
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
|
|
});
|
|
|
|
export type LogicielEtablissement = typeof logicielsEtablissements.$inferSelect;
|
|
|
|
// ─── Traçabilité : Consultations ──────────────────────────────────────────────
|
|
|
|
export const consultations = mysqlTable("consultations", {
|
|
id: int("id").autoincrement().primaryKey(),
|
|
etablissementId: int("etablissementId").notNull(),
|
|
consultePar: int("consultePar").notNull(), // userId
|
|
consultéParNom: varchar("consulteParNom", { length: 255 }),
|
|
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
|
});
|
|
|
|
export type Consultation = typeof consultations.$inferSelect;
|
|
|
|
// ─── Demandes de Contact ──────────────────────────────────────────────────────
|
|
|
|
export const demandesContact = mysqlTable("demandes_contact", {
|
|
id: int("id").autoincrement().primaryKey(),
|
|
// Établissement cible
|
|
etablissementCibleId: int("etablissementCibleId").notNull(),
|
|
// Demandeur
|
|
demandeurId: int("demandeurId").notNull(),
|
|
demandeurNom: varchar("demandeurNom", { length: 255 }),
|
|
demandeurEmail: varchar("demandeurEmail", { length: 320 }),
|
|
// Message
|
|
message: text("message").notNull(),
|
|
// Statut
|
|
statut: mysqlEnum("statut", ["en_attente", "repondu", "ferme"]).default("en_attente").notNull(),
|
|
reponse: text("reponse"),
|
|
reponsePar: int("reponsePar"),
|
|
reponduAt: timestamp("reponduAt"),
|
|
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
|
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
|
|
});
|
|
|
|
export type DemandeContact = typeof demandesContact.$inferSelect;
|