Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
3.6 kB
2
Indexable
Never
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id       String   @id @default(uuid())
  name     String
  lastName String
  email    String   @unique
  phone    String
  password String
  role     UserRole
  barber   Barber?
}

enum UserRole {
  ADMIN
  STAFF
  BARBER
  CLIENT
}

// A barber is a user that can provide services
model Barber {
  id                 String         @id @default(uuid())
  user               User           @relation(fields: [userId], references: [id])
  userId             String         @unique
  services           Service[]
  shifts             Shift[]
  availabilities     Availability[]
  successfulServices Int            @default(0)
  cancelledServices  Int            @default(0)
  active             Boolean        @default(true)
}

// A client is a user that can schedule services
model Client {
  id                 String  @id @default(uuid())
  name               String
  lastName           String
  email              String  @unique
  phone              String
  shifts             Shift[]
  successfulServices Int     @default(0)
  cancelledServices  Int     @default(0)
}

// A service is a type of service that can be provided by a barber
model Service {
  id       String   @id @default(uuid())
  name     String
  // Price in cents 
  price    Int
  duration Int // Duration in minutes
  barbers  Barber[]
  shifts   Shift[]
}

// A shift is a service that has been scheduled by a client
model Shift {
  id        String      @id @default(uuid())
  status    ShiftStatus @default(SCHEDULED)
  barber    Barber      @relation(fields: [barberId], references: [id])
  barberId  String
  client    Client      @relation(fields: [clientId], references: [id])
  clientId  String
  service   Service     @relation(fields: [serviceId], references: [id])
  serviceId String
}

// The status of a shift
// SCHEDULED: The shift has been scheduled by a client
// COMPLETED: The shift has been completed
// CANCELLED: The shift has been cancelled
// CONFIRMED: The shift has been confirmed by the client via text message or email
enum ShiftStatus {
  SCHEDULED
  COMPLETED
  CANCELLED
  CONFIRMED
}

model BarberShop {
  id           String         @id @default(uuid())
  name         String
  address      String
  phone        String
  openingHours OpeningHours[]
  specialDates SpecialDate[]
}

model OpeningHours {
  id           String     @id @default(uuid())
  barberShop   BarberShop @relation(fields: [barberShopId], references: [id])
  barberShopId String
  dayOfWeek    DayOfWeek
  openTime     String
  closeTime    String
}

model SpecialDate {
  id             String        @id @default(uuid())
  date           DateTime
  openTime       String?
  closeTime      String?
  isClosed       Boolean       @default(false)
  Availability   Availability? @relation(fields: [availabilityId], references: [id])
  availabilityId String?
  BarberShop     BarberShop?   @relation(fields: [barberShopId], references: [id])
  barberShopId   String?
}

model Availability {
  id          String        @id @default(uuid())
  barber      Barber        @relation(fields: [barberId], references: [id])
  barberId    String
  dayOfWeek   DayOfWeek
  startTime   String // Time in 24h format
  endTime     String // Time in 24h format
  specialDate SpecialDate[]
}

enum DayOfWeek {
  MONDAY
  TUESDAY
  WEDNESDAY
  THURSDAY
  FRIDAY
  SATURDAY
  SUNDAY
}
Leave a Comment