mail@pastecode.io avatar
15 days ago
2.9 kB
model Account {
  id     String @id @default(cuid())
  userId String @unique
  type   String

  user User @relation(fields: [userId], references: [id])

// 2 user types : normal user & payment verifier 
// -> 1 user many accounts
model User {
  id       String   @id @default(cuid())
  email    String   @unique
  username String   @unique
  govId    String   @unique
  birthday DateTime

  accounts      Account[]
  vehicles      Vehicle[]
  subscriptions Subscription[]
  tickets       Ticket[]

  // for verifier only
  session          Session[]
  verifiedPayments Payment[] @relation("VerifiedBy")

model Session {
  id        String   @id @default(cuid())
  userId    String
  expiresAt DateTime

  user User @relation(fields: [userId], references: [id])

// For acquiring info to print Ticket
// Vehicle arrives 
// -> scan Vehicle for govId                        => get Vehicle "type"
// -> compare Vehicle "type" to TicketType "type"   => get Ticket "type" + "price"
// userId acquired from Vehicle "govId"             => get User "subscriptions"

// For payment
// -> check if subscription exists for this vehicle => if exists, Payment "type" set to SUBSCRIBED, let vehicle pass thorough auto || if not: process at booth

// For ticket: Print all this information except paymentId
// Subscribed user: e-ticket
model Ticket {
  id             String   @id @default(cuid())
  userId         String
  vehicleId      String
  createdAt      DateTime @default(now())
  subscriptionId String?
  type           String
  price          Int
  paymentId      String   @unique

  ticketType   TicketTypes   @relation(fields: [type, price], references: [type, price])
  vehicle      Vehicle       @relation(fields: [vehicleId], references: [govId])
  user         User          @relation(fields: [userId], references: [id])
  subscription Subscription? @relation(fields: [subscriptionId], references: [id])
  payment      Payment?

model TicketTypes {
  type  String @unique
  price Int

  ticket Ticket[]

  @@unique([type, price])

model Vehicle {
  govId         String         @id @unique
  userId        String
  type          String
  subscriptions Subscription[]
  tickets       Ticket[]

  user User @relation(fields: [userId], references: [id])

  @@unique([govId, type])

// 1 subscription each vehicle
model Subscription {
  id        String @id @default(cuid())
  userId    String
  vehicleId String

  createdAt DateTime
  expireAt  DateTime

  user    User     @relation(fields: [userId], references: [id])
  vehicle Vehicle  @relation(fields: [vehicleId], references: [govId])
  tickets Ticket[]

model Payment {
  ticketId String @id
  type     String // CASH / CARD / SUBSCRIBED / ...

  createdAt  DateTime
  verifierId String
  paid       Boolean

  verifier User   @relation("VerifiedBy", fields: [verifierId], references: [id])
  ticket   Ticket @relation(fields: [ticketId], references: [id])
Leave a Comment