appointments.prisma 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. /// Made up by the booking dialog each time it opens and sent with the
  26. /// booking, so a booking sent twice (the answer to the first was lost) is
  27. /// found again instead of made again.
  28. bookingToken String?
  29. @@unique([organizationId, bookingToken])
  30. @@index([organizationId, startAt])
  31. @@index([customerId])
  32. @@index([vehicleId])
  33. @@map("appointments")
  34. }
  35. /// One alert before an appointment or a booked job, the way a calendar sets
  36. /// them: how it goes out and how long before. It goes out once for each start
  37. /// time, so moving the appointment, here or on the work board, arms it again.
  38. model AppointmentNotification {
  39. id String @id @default(cuid())
  40. /// in_app | email | customer_sms | customer_email
  41. channel String
  42. /// How long before the start, in `unit`s.
  43. amount Int
  44. /// minutes | hours | days | weeks
  45. unit String
  46. /// HH:MM on that day for a notice given in days or weeks ("1 day before at
  47. /// 16:00"), on the workshop's clock. Null for minutes and hours.
  48. atTime String?
  49. /// The start it last went out for. Any other start means it has not gone
  50. /// out for this one yet.
  51. sentForStart DateTime?
  52. createdAt DateTime @default(now())
  53. updatedAt DateTime @updatedAt
  54. organizationId String
  55. organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  56. /// Who set it. An email to the workshop goes to them.
  57. userId String?
  58. user User? @relation("AppointmentNotificationUser", fields: [userId], references: [id], onDelete: SetNull)
  59. /// What it is for: an appointment, or a booked job. Exactly one is set.
  60. appointmentId String?
  61. appointment Appointment? @relation(fields: [appointmentId], references: [id], onDelete: Cascade)
  62. serviceRecordId String?
  63. serviceRecord ServiceRecord? @relation(fields: [serviceRecordId], references: [id], onDelete: Cascade)
  64. @@index([organizationId])
  65. @@index([appointmentId])
  66. @@index([serviceRecordId])
  67. @@map("appointment_notifications")
  68. }