appointments.prisma 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /// An appointment on the workshop calendar with no job behind it: a customer
  2. /// coming in to talk, a test drive, a supplier's visit. Work on a car is booked
  3. /// as a scheduled job instead (ServiceRecord with status `scheduled`), which
  4. /// holds a bay and gets a number. An appointment can become such a job, and is
  5. /// removed when it does.
  6. model Appointment {
  7. id String @id @default(cuid())
  8. title String
  9. /// Rich text from the editor, cleaned when it is saved and again when shown.
  10. description String?
  11. startAt DateTime
  12. endAt DateTime
  13. createdAt DateTime @default(now())
  14. updatedAt DateTime @updatedAt
  15. organizationId String
  16. organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  17. /// Who it is with, when it is with anyone on file.
  18. customerId String?
  19. customer Customer? @relation(fields: [customerId], references: [id], onDelete: SetNull)
  20. vehicleId String?
  21. vehicle Vehicle? @relation(fields: [vehicleId], references: [id], onDelete: SetNull)
  22. createdById String?
  23. createdBy User? @relation("AppointmentCreatedBy", fields: [createdById], references: [id], onDelete: SetNull)
  24. notifications AppointmentNotification[]
  25. @@index([organizationId, startAt])
  26. @@index([customerId])
  27. @@index([vehicleId])
  28. @@map("appointments")
  29. }
  30. /// One alert before an appointment or a booked job, the way a calendar sets
  31. /// them: how it goes out and how long before. It goes out once for each start
  32. /// time, so moving the appointment, here or on the work board, arms it again.
  33. model AppointmentNotification {
  34. id String @id @default(cuid())
  35. /// in_app | email | customer_sms | customer_email
  36. channel String
  37. /// How long before the start, in `unit`s.
  38. amount Int
  39. /// minutes | hours | days | weeks
  40. unit String
  41. /// HH:MM on that day for a notice given in days or weeks ("1 day before at
  42. /// 16:00"), on the workshop's clock. Null for minutes and hours.
  43. atTime String?
  44. /// The start it last went out for. Any other start means it has not gone
  45. /// out for this one yet.
  46. sentForStart DateTime?
  47. createdAt DateTime @default(now())
  48. updatedAt DateTime @updatedAt
  49. organizationId String
  50. organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  51. /// Who set it. An email to the workshop goes to them.
  52. userId String?
  53. user User? @relation("AppointmentNotificationUser", fields: [userId], references: [id], onDelete: SetNull)
  54. /// What it is for: an appointment, or a booked job. Exactly one is set.
  55. appointmentId String?
  56. appointment Appointment? @relation(fields: [appointmentId], references: [id], onDelete: Cascade)
  57. serviceRecordId String?
  58. serviceRecord ServiceRecord? @relation(fields: [serviceRecordId], references: [id], onDelete: Cascade)
  59. @@index([organizationId])
  60. @@index([appointmentId])
  61. @@index([serviceRecordId])
  62. @@map("appointment_notifications")
  63. }