condition-marks.prisma 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /// A mark on the vehicle's condition map: a dent, a scratch, a chip, drawn
  2. /// on a line drawing of the car by tapping where it is.
  3. ///
  4. /// Marks belong to the vehicle, not to the sheet they were drawn on. An
  5. /// inspection or a work order records new ones; the next visit starts with
  6. /// the ones still there, greyed, and either confirms them or clears them as
  7. /// repaired. That is what makes "new since last time" a fact rather than an
  8. /// argument. The sheet a mark was drawn on is kept for the print, and lets
  9. /// go of the mark rather than taking it with it when the sheet is deleted.
  10. model ConditionMark {
  11. id String @id @default(cuid())
  12. organizationId String
  13. organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  14. vehicleId String
  15. vehicle Vehicle @relation(fields: [vehicleId], references: [id], onDelete: Cascade)
  16. /// Where it was recorded: the inspection check or the work order's drop-off.
  17. inspectionId String?
  18. inspection Inspection? @relation(fields: [inspectionId], references: [id], onDelete: SetNull)
  19. inspectionItemId String?
  20. inspectionItem InspectionItem? @relation(fields: [inspectionItemId], references: [id], onDelete: SetNull)
  21. serviceRecordId String?
  22. serviceRecord ServiceRecord? @relation(fields: [serviceRecordId], references: [id], onDelete: SetNull)
  23. /// Which drawing it sits on, so a body type changed later cannot move it.
  24. bodyType String
  25. /// top | left | right | front | rear
  26. view String
  27. /// The named panel the tap landed on; see condition-map/Lib/drawingTypes.ts.
  28. panel String
  29. /// Position as a fraction of the view's box, 0..1 from the top-left.
  30. x Float
  31. y Float
  32. /// dent | scratch | chip | crack | rust | paint | previous_repair | missing
  33. kind String
  34. /// minor | major
  35. severity String @default("minor")
  36. note String?
  37. imageUrls String[] @default([])
  38. recordedAt DateTime @default(now())
  39. recordedById String?
  40. recordedBy User? @relation("ConditionMarkRecordedBy", fields: [recordedById], references: [id], onDelete: SetNull)
  41. /// Set when a later visit found the damage gone. The mark stays as history
  42. /// and stops printing as current.
  43. resolvedAt DateTime?
  44. resolvedById String?
  45. resolvedBy User? @relation("ConditionMarkResolvedBy", fields: [resolvedById], references: [id], onDelete: SetNull)
  46. /// Set with resolvedAt when a later visit confirmed the damage still there
  47. /// and recorded it again: the id of that newer mark. Closed because it was
  48. /// superseded, not repaired, so the sheet it was drawn on still prints it
  49. /// as its own record while the vehicle shows the dent once.
  50. carriedToId String?
  51. createdAt DateTime @default(now())
  52. updatedAt DateTime @updatedAt
  53. @@index([vehicleId])
  54. @@index([inspectionId])
  55. @@index([inspectionItemId])
  56. @@index([serviceRecordId])
  57. @@index([organizationId])
  58. @@map("condition_marks")
  59. }
  60. /// A workshop's own kind of mark on the condition map: one of the eight
  61. /// built-in kinds renamed or recoloured (the row carries the built-in key),
  62. /// or a kind of the workshop's own. A mark refers to a kind by its key, so a
  63. /// renamed kind changes on every open document at once; an issued invoice and
  64. /// a completed inspection keep the kinds as they were in their own snapshots.
  65. model ConditionMarkType {
  66. id String @id @default(cuid())
  67. organizationId String
  68. organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  69. /// dent, scratch, chip, crack, rust, paint, previous_repair, missing for a
  70. /// built-in kind; a key made from the id for a workshop's own.
  71. key String
  72. name String
  73. /// circle | diamond | triangle | square | cross | hex
  74. shape String
  75. /// A hex colour, printed as it is.
  76. color String
  77. sortOrder Int @default(0)
  78. /// Kept out of the picker; marks that carry it still show and print.
  79. hidden Boolean @default(false)
  80. createdAt DateTime @default(now())
  81. updatedAt DateTime @updatedAt
  82. @@unique([organizationId, key])
  83. @@index([organizationId])
  84. @@map("condition_mark_types")
  85. }