- API NestJS + Prisma (base mep) : auth admin/employés, magasins, design de carte avec récompenses et images, comptes du personnel - Admin Vite/React : liste et fiche magasin, assistant de carte avec aperçu Apple/Google Wallet, gestion des employés - Logo MonEspacePro (Claude Design) en SVG, favicon Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
219 lines
7.6 KiB
Text
219 lines
7.6 KiB
Text
// ─────────────────────────────────────────────────────────────
|
|
// MonEspacePro (MEP) — carte de fidélité dématérialisée
|
|
// Prisma + MySQL, base « mep » (séparée de GoSortir).
|
|
// ─────────────────────────────────────────────────────────────
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "mysql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
// ── Administration (moi) ──────────────────────────────────────
|
|
model Admin {
|
|
id String @id @default(cuid())
|
|
email String @unique
|
|
passwordHash String
|
|
createdAt DateTime @default(now())
|
|
}
|
|
|
|
// ── Magasins ──────────────────────────────────────────────────
|
|
enum StoreStatus {
|
|
DRAFT /// créé, carte pas encore conçue / abonnement pas encore actif
|
|
ACTIVE
|
|
SUSPENDED /// paiement échoué : scans et inscriptions refusés
|
|
CLOSED
|
|
}
|
|
|
|
model Store {
|
|
id String @id @default(cuid())
|
|
/// Identifiant public court utilisé dans les URL d'inscription (/c/<slug>).
|
|
slug String @unique
|
|
name String
|
|
addressLine String
|
|
postalCode String
|
|
city String
|
|
siret String @db.Char(14)
|
|
contactName String
|
|
contactEmail String
|
|
contactPhone String
|
|
status StoreStatus @default(DRAFT)
|
|
|
|
// Anti-triche : réglages par magasin
|
|
maxAmountCents Int @default(50000) /// plafond d'un montant saisi
|
|
minScanIntervalSec Int @default(300) /// délai minimum entre deux crédits d'un même client
|
|
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
cardDesign CardDesign?
|
|
staff StaffUser[]
|
|
cards LoyaltyCard[]
|
|
transactions Transaction[]
|
|
subscription Subscription?
|
|
invoices Invoice[]
|
|
}
|
|
|
|
enum PointsMode {
|
|
AMOUNT /// points proportionnels au montant (pointsPerEuro)
|
|
STAMP /// un tampon par passage
|
|
}
|
|
|
|
model CardDesign {
|
|
id String @id @default(cuid())
|
|
storeId String @unique
|
|
store Store @relation(fields: [storeId], references: [id], onDelete: Cascade)
|
|
programName String
|
|
logoPath String?
|
|
stripPath String? /// bandeau
|
|
backgroundColor String @default("#1F2937")
|
|
foregroundColor String @default("#FFFFFF")
|
|
labelColor String @default("#D1D5DB")
|
|
pointsMode PointsMode @default(AMOUNT)
|
|
pointsPerEuro Decimal @default(1) @db.Decimal(6, 2)
|
|
rewards Reward[]
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model Reward {
|
|
id String @id @default(cuid())
|
|
cardDesignId String
|
|
cardDesign CardDesign @relation(fields: [cardDesignId], references: [id], onDelete: Cascade)
|
|
label String
|
|
cost Int /// points ou tampons nécessaires
|
|
active Boolean @default(true)
|
|
transactions Transaction[]
|
|
}
|
|
|
|
// ── Personnel du magasin (app Pro) ────────────────────────────
|
|
enum StaffRole {
|
|
MANAGER
|
|
EMPLOYEE
|
|
}
|
|
|
|
model StaffUser {
|
|
id String @id @default(cuid())
|
|
storeId String
|
|
store Store @relation(fields: [storeId], references: [id], onDelete: Cascade)
|
|
email String @unique
|
|
displayName String
|
|
passwordHash String
|
|
role StaffRole @default(EMPLOYEE)
|
|
active Boolean @default(true)
|
|
/// Incrémenté pour révoquer tous les jetons de rafraîchissement.
|
|
tokenVersion Int @default(0)
|
|
createdAt DateTime @default(now())
|
|
transactions Transaction[]
|
|
}
|
|
|
|
// ── Clients finaux ────────────────────────────────────────────
|
|
model Customer {
|
|
id String @id @default(cuid())
|
|
firstName String
|
|
email String
|
|
consentAt DateTime /// consentement RGPD horodaté
|
|
createdAt DateTime @default(now())
|
|
cards LoyaltyCard[]
|
|
}
|
|
|
|
model LoyaltyCard {
|
|
id String @id @default(cuid())
|
|
storeId String
|
|
store Store @relation(fields: [storeId], references: [id], onDelete: Cascade)
|
|
customerId String
|
|
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
|
|
/// Numéro de série du pass Wallet ; contenu du QR (non devinable).
|
|
serial String @unique
|
|
/// Jeton d'authentification du service web Apple Wallet.
|
|
authToken String
|
|
balance Int @default(0)
|
|
lastCreditAt DateTime?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
transactions Transaction[]
|
|
devices AppleRegistration[]
|
|
|
|
@@unique([storeId, customerId])
|
|
}
|
|
|
|
enum TransactionType {
|
|
CREDIT
|
|
REDEEM
|
|
ADJUST /// correction manuelle (gérant)
|
|
}
|
|
|
|
/// Journal immuable : chaque scan est enregistré avec l'employé.
|
|
model Transaction {
|
|
id String @id @default(cuid())
|
|
storeId String
|
|
store Store @relation(fields: [storeId], references: [id], onDelete: Cascade)
|
|
cardId String
|
|
card LoyaltyCard @relation(fields: [cardId], references: [id], onDelete: Cascade)
|
|
staffId String
|
|
staff StaffUser @relation(fields: [staffId], references: [id])
|
|
type TransactionType
|
|
amountCents Int?
|
|
points Int /// positif (crédit) ou négatif (récompense)
|
|
rewardId String?
|
|
reward Reward? @relation(fields: [rewardId], references: [id])
|
|
createdAt DateTime @default(now())
|
|
|
|
@@index([storeId, createdAt])
|
|
@@index([cardId, createdAt])
|
|
}
|
|
|
|
// ── Apple Wallet (service web PassKit) ────────────────────────
|
|
model AppleDevice {
|
|
id String @id @default(cuid())
|
|
deviceLibraryId String @unique
|
|
pushToken String
|
|
registrations AppleRegistration[]
|
|
}
|
|
|
|
model AppleRegistration {
|
|
deviceId String
|
|
device AppleDevice @relation(fields: [deviceId], references: [id], onDelete: Cascade)
|
|
cardId String
|
|
card LoyaltyCard @relation(fields: [cardId], references: [id], onDelete: Cascade)
|
|
createdAt DateTime @default(now())
|
|
|
|
@@id([deviceId, cardId])
|
|
}
|
|
|
|
// ── Facturation ───────────────────────────────────────────────
|
|
enum SubscriptionStatus {
|
|
INCOMPLETE
|
|
ACTIVE
|
|
PAST_DUE
|
|
CANCELED
|
|
}
|
|
|
|
model Subscription {
|
|
id String @id @default(cuid())
|
|
storeId String @unique
|
|
store Store @relation(fields: [storeId], references: [id], onDelete: Cascade)
|
|
stripeCustomerId String? @unique
|
|
stripeSubscriptionId String? @unique
|
|
status SubscriptionStatus @default(INCOMPLETE)
|
|
currentPeriodEnd DateTime?
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model Invoice {
|
|
id String @id @default(cuid())
|
|
/// Numérotation continue, sans trou : MEP-2026-000001
|
|
number String @unique
|
|
sequence Int @unique
|
|
storeId String
|
|
store Store @relation(fields: [storeId], references: [id])
|
|
stripeInvoiceId String? @unique
|
|
amountCents Int
|
|
periodStart DateTime
|
|
periodEnd DateTime
|
|
issuedAt DateTime @default(now())
|
|
paidAt DateTime?
|
|
pdfPath String?
|
|
}
|