Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

72 řádky
2.2 KiB

  1. //
  2. // mdlInspectionLevel.swift
  3. //
  4. //
  5. // Created by Michiel Carman on 2/16/24.
  6. //
  7. import Fluent
  8. import Vapor
  9. import Foundation
  10. import FluentKit
  11. final class mdlInspectionLevel: Model, Content {
  12. static let schema = "inspectionLevel"
  13. @ID(custom: "id", generatedBy: .database) var id: Int?
  14. @Field(key: "name") var name: String?
  15. @Field(key: "description") var description: String?
  16. @Field(key: "isActive") var isactive: Bool?
  17. @Parent(key: "inspectionTypeId") var inspectiontype: mdlInspectionType
  18. @Children(for: \.$level) var inspections: [mdlInspection]
  19. @Children(for: \.$level) var templates: [mdlTemplate]
  20. @Timestamp(key: "createDate", on: .create) var createdate: Date?
  21. @Field(key: "createUserId") var createuserid: Int?
  22. @Timestamp(key: "updateDate", on: .update) var updatedate: Date?
  23. @Field(key: "updateUserId") var updateuserid: Int?
  24. init() { }
  25. init(id: Int? = nil,
  26. name: String? = nil,
  27. description: String? = nil,
  28. isactive: Bool? = true,
  29. inspectiontypeid: Int,
  30. createuserid: Int? = nil,
  31. updateuserid: Int? = nil
  32. ) {
  33. self.id = id
  34. self.name = name
  35. self.description = description
  36. self.isactive = isactive
  37. self.$inspectiontype.$id.value = inspectiontypeid
  38. self.createuserid = createuserid
  39. self.updateuserid = updateuserid
  40. }
  41. }
  42. extension mdlInspectionLevel{
  43. struct Create: AsyncMigration {
  44. func prepare(on database: Database) async throws {
  45. try await database.schema("inspectionLevel")
  46. .field("id", .int, .identifier(auto: true))
  47. .field("name", .string)
  48. .field("description", .string)
  49. .field("isactive", .bool)
  50. .field("inspectionTypeId", .int)
  51. .field("createDate", .datetime)
  52. .field("createUserId", .int)
  53. .field("updateDate", .datetime)
  54. .field("updateUserId", .int)
  55. .create()
  56. }
  57. func revert(on database: Database) async throws {
  58. try await database.schema("inspectionLevel").delete()
  59. }
  60. }
  61. }