inspections.prisma 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. model InspectionTemplate {
  2. id String @id @default(cuid())
  3. name String
  4. description String?
  5. isDefault Boolean @default(false)
  6. createdAt DateTime @default(now())
  7. updatedAt DateTime @updatedAt
  8. // Regulatory profile. `country` is an ISO-3166 alpha-2 code (or null for a
  9. // shop-specific checklist), `standard` names the regime the template follows
  10. // (e.g. "eu-2014-45"), and `severityScale` picks which defect vocabulary the
  11. // technician grades against — see Lib/conditions.ts.
  12. country String?
  13. standard String? @default("custom")
  14. severityScale String @default("eu")
  15. /// Provenance, for templates that came from a package rather than being
  16. /// written here. `packageId` is namespaced and stable across renames
  17. /// ("torqvoice/eu-roadworthiness"), which is what lets the library tell an
  18. /// update from a duplicate. Null on a template the workshop wrote itself.
  19. packageId String?
  20. packageVersion String?
  21. /// Where it came from: "builtin", "file" or "catalogue".
  22. packageSource String?
  23. organizationId String
  24. organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  25. sections InspectionTemplateSection[]
  26. inspections Inspection[]
  27. @@index([organizationId])
  28. @@index([organizationId, packageId])
  29. @@map("inspection_templates")
  30. }
  31. model InspectionTemplateSection {
  32. id String @id @default(cuid())
  33. name String
  34. description String?
  35. // Regulation reference for the section, e.g. "1" for Braking equipment in
  36. // Directive 2014/45/EU Annex I.
  37. code String?
  38. sortOrder Int @default(0)
  39. templateId String
  40. template InspectionTemplate @relation(fields: [templateId], references: [id], onDelete: Cascade)
  41. items InspectionTemplateItem[]
  42. @@index([templateId])
  43. @@map("inspection_template_sections")
  44. }
  45. model InspectionTemplateItem {
  46. id String @id @default(cuid())
  47. name String
  48. description String?
  49. // Regulation reference for the check, e.g. "1.1.13".
  50. code String?
  51. sortOrder Int @default(0)
  52. // How the technician records the result: "condition" (defect grading only),
  53. // "measurement" (numeric value in `unit`, graded against min/max),
  54. // "text" (free text) or "choice" (one of `choices`).
  55. inputType String @default("condition")
  56. unit String?
  57. minValue Float?
  58. maxValue Float?
  59. choices String[] @default([])
  60. required Boolean @default(false)
  61. photoRequired Boolean @default(false)
  62. // Defect severity applied when a measurement falls outside min/max.
  63. defaultSeverity String?
  64. // Phrases this workshop wants offered when a defect is recorded against the
  65. // check, on top of the built-in catalogue. See Lib/defectCatalogue.ts.
  66. defectSuggestions String[] @default([])
  67. sectionId String
  68. section InspectionTemplateSection @relation(fields: [sectionId], references: [id], onDelete: Cascade)
  69. @@index([sectionId])
  70. @@map("inspection_template_items")
  71. }
  72. model Inspection {
  73. id String @id @default(cuid())
  74. status String @default("in_progress")
  75. mileage Int?
  76. notes String?
  77. startDateTime DateTime?
  78. endDateTime DateTime?
  79. publicToken String? @unique
  80. completedAt DateTime?
  81. createdAt DateTime @default(now())
  82. updatedAt DateTime @updatedAt
  83. vehicleId String
  84. vehicle Vehicle @relation(fields: [vehicleId], references: [id], onDelete: Cascade)
  85. templateId String
  86. template InspectionTemplate @relation(fields: [templateId], references: [id])
  87. technicianId String?
  88. technician Technician? @relation(fields: [technicianId], references: [id], onDelete: SetNull)
  89. /// See ServiceRecord.workBayId — an inspection occupies a bay just as a
  90. /// repair does, and the work board lanes both the same way.
  91. workBayId String?
  92. workBay WorkBay? @relation(fields: [workBayId], references: [id], onDelete: SetNull)
  93. sortOrder Int @default(0)
  94. // Roadworthiness certificate fields required by Directive 2014/45/EU Annex IV.
  95. // `inspectorName` and `certificateNumber` are snapshots taken at completion so
  96. // the issued certificate stays stable even if staff or settings change later.
  97. /// Snapshot of how this inspection was graded, taken when it was created.
  98. /// Read in preference to the template's current setting: a workshop that
  99. /// later switches a template to the EU scale must not relabel a certificate
  100. /// it already issued. Null on inspections that predate the snapshot; those
  101. /// fall back to the template, which the migration pinned to its old scale.
  102. severityScale String?
  103. country String?
  104. vehicleCategory String?
  105. nextTestDue DateTime?
  106. certificateNumber String?
  107. inspectorName String?
  108. testLocation String?
  109. organizationId String
  110. items InspectionItem[]
  111. quoteRequests InspectionQuoteRequest[]
  112. quotes Quote[]
  113. serviceRecords ServiceRecord[]
  114. importBatchId String?
  115. importBatch ImportBatch? @relation(fields: [importBatchId], references: [id], onDelete: SetNull)
  116. @@index([vehicleId])
  117. @@index([organizationId])
  118. @@index([technicianId])
  119. @@index([workBayId])
  120. @@map("inspections")
  121. }
  122. model InspectionItem {
  123. id String @id @default(cuid())
  124. name String
  125. section String
  126. sortOrder Int @default(0)
  127. condition String @default("not_inspected")
  128. notes String?
  129. imageUrls String[] @default([])
  130. // Copied from the template at creation so an inspection stays readable even
  131. // after its template is edited or deleted.
  132. description String?
  133. code String?
  134. sectionCode String?
  135. inputType String @default("condition")
  136. unit String?
  137. minValue Float?
  138. maxValue Float?
  139. choices String[] @default([])
  140. required Boolean @default(false)
  141. photoRequired Boolean @default(false)
  142. defaultSeverity String?
  143. defectSuggestions String[] @default([])
  144. measuredValue Float?
  145. textValue String?
  146. inspectionId String
  147. inspection Inspection @relation(fields: [inspectionId], references: [id], onDelete: Cascade)
  148. @@index([inspectionId])
  149. @@map("inspection_items")
  150. }
  151. model InspectionQuoteRequest {
  152. id String @id @default(cuid())
  153. status String @default("pending")
  154. message String?
  155. selectedItemIds String[]
  156. createdAt DateTime @default(now())
  157. inspectionId String
  158. inspection Inspection @relation(fields: [inspectionId], references: [id], onDelete: Cascade)
  159. organizationId String
  160. @@index([organizationId])
  161. @@index([inspectionId])
  162. @@map("inspection_quote_requests")
  163. }