reports.prisma 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. model StatusReport {
  2. id String @id @default(cuid())
  3. title String?
  4. message String? @db.Text
  5. videoUrl String?
  6. videoFileName String?
  7. publicToken String @unique
  8. status String @default("draft") // draft | published | sent | viewed
  9. sentVia String? // email, sms, telegram (comma-separated)
  10. sentAt DateTime?
  11. viewedAt DateTime?
  12. customerFeedback String? @db.Text
  13. feedbackAt DateTime?
  14. expiresAt DateTime?
  15. createdAt DateTime @default(now())
  16. updatedAt DateTime @updatedAt
  17. /// A report belongs to a work order or to an inspection, never both and
  18. /// never neither: what the customer is being shown a video of.
  19. serviceRecordId String?
  20. serviceRecord ServiceRecord? @relation(fields: [serviceRecordId], references: [id], onDelete: Cascade)
  21. inspectionId String?
  22. inspection Inspection? @relation(fields: [inspectionId], references: [id], onDelete: Cascade)
  23. organizationId String
  24. organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  25. technicianId String?
  26. technician Technician? @relation(fields: [technicianId], references: [id], onDelete: SetNull)
  27. @@index([serviceRecordId])
  28. @@index([inspectionId])
  29. @@index([organizationId])
  30. @@index([publicToken])
  31. @@index([expiresAt])
  32. @@map("status_reports")
  33. }
  34. model ReportSchedule {
  35. id String @id @default(cuid())
  36. name String @default("Scheduled Report")
  37. frequency String // "daily" | "weekly" | "monthly" etc.
  38. dateRange String @default("last30d") // "last1d" | "last7d" | "last30d" | "ytd" | "allTime" etc.
  39. sections String // JSON array of section keys
  40. recipients String // JSON array of user IDs
  41. nextRunDate DateTime
  42. endDate DateTime?
  43. isActive Boolean @default(true)
  44. lastRunAt DateTime?
  45. runCount Int @default(0)
  46. createdAt DateTime @default(now())
  47. updatedAt DateTime @updatedAt
  48. organizationId String
  49. organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  50. createdById String
  51. @@index([organizationId])
  52. @@index([nextRunDate, isActive])
  53. @@map("report_schedules")
  54. }