Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

143 wiersze
4.9 KiB

  1. //
  2. // Template.swift
  3. //
  4. //
  5. // Created by Michiel Carman on 10/27/21.
  6. //
  7. import Foundation
  8. import Vapor
  9. import Fluent
  10. import FluentPostgresDriver
  11. final class mdlTemplate: Model, Content{
  12. static let schema = "Template"
  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. @Field(key: "createUserId" ) var createuserid: Int?
  18. @Timestamp(key: "createDate", on: .create) var createdate: Date?
  19. @Field(key: "updateUserId") var updateuserid: Int?
  20. @Timestamp(key: "updateDate", on: .update) var updatedate: Date?
  21. @Parent(key: "inspectionTypeId") var inspectiontype: mdlInspectionType
  22. @Parent(key: "inspectionLevelId") var inspectionlevel: mdlInspectionLevel
  23. @Parent(key: "customerId") var customer: mdlCustomer
  24. @Parent(key: "productId") var product: mdlProduct
  25. @Parent(key: "makeId") var make: mdlMake
  26. @Parent(key: "modelId") var model: mdlModel
  27. @Parent(key: "machineId") var machine: mdlMachine
  28. @Children(for: \.$template) var categories: [mdlTemplateCategory]
  29. init(){}
  30. init(id: Int? = nil, name: String, description: String, isactive: Bool, createuserid: Int? = -1, createdate: Date? = nil, updateuserid: Int? = -1, updatedate: Date? = nil, inspectiontype: mdlInspectionType, inspectionlevel: mdlInspectionLevel, customer: mdlCustomer, product: mdlProduct, make: mdlMake, model: mdlModel, machine: mdlMachine, categories: [mdlTemplateCategory]?){
  31. self.id = id
  32. self.name = name
  33. self.description = description
  34. self.isactive = isactive
  35. self.createuserid = createuserid
  36. self.createdate = createdate
  37. self.updateuserid = updateuserid
  38. self.updatedate = updatedate
  39. self.$inspectiontype.id = inspectiontype.id!
  40. self.$inspectionlevel.id = inspectiontype.id!
  41. self.$customer.id = customer.id!
  42. self.$product.id = product.id!
  43. self.$make.id = make.id!
  44. self.$model.id = model.id!
  45. self.$machine.id = machine.id!
  46. self.$categories.value = categories
  47. }
  48. }
  49. extension mdlTemplate {
  50. struct Input: Content{
  51. let id: Int?
  52. let name: String
  53. let description: String
  54. let isactive: Bool
  55. let createdate: Date?
  56. let createuserid: Int?
  57. let updatedate: Date?
  58. let updateuserid: Int?
  59. let inspectiontype: mdlInspectionType
  60. let inspectionlevel: mdlInspectionLevel
  61. let customer: mdlCustomer
  62. let product: mdlProduct
  63. let make: mdlMake
  64. let model: mdlModel
  65. let machine: mdlMachine
  66. let categories: [mdlTemplateCategory]?
  67. }
  68. struct Output: Content{
  69. let id: Int?
  70. let name: String
  71. let description: String
  72. let isactive: Bool
  73. let createdate: Date?
  74. let createuserid: Int?
  75. let updatedate: Date?
  76. let updateuserid: Int?
  77. let inspectiontype: mdlInspectionType
  78. let inspectionlevel: mdlInspectionLevel
  79. let customer: mdlCustomer
  80. let product: mdlProduct
  81. let make: mdlMake
  82. let model: mdlModel
  83. let machine: mdlMachine
  84. let categories: [mdlTemplateCategory]?
  85. }
  86. struct create: Migration{
  87. func prepare(on database: Database) -> EventLoopFuture<Void> {
  88. return database.schema("Template")
  89. .field("id", .int, .identifier(auto: true))
  90. .field("name", .string)
  91. .field("description", .string)
  92. .field("isActive", .bool)
  93. .field("inspectionTypeId", .int, .references("InspectionType", "id"))
  94. .field("inspectionLevelId", .int, .references("InspectionLevel", "id"))
  95. .field("customerId", .int, .references("Customer", "id"))
  96. .field("productId", .int, .references("Product", "id"))
  97. .field("makeId", .int, .references("Make", "id"))
  98. .field("modelId", .int, .references("Model", "id"))
  99. .field("machineId", .int, .references("Machine", "id"))
  100. .field("createUserId", .int)
  101. .field("createDate", .datetime)
  102. .field("updateUserId", .int)
  103. .field("updateDate", .datetime)
  104. .create()
  105. }
  106. func revert(on database: Database) -> EventLoopFuture<Void> {
  107. database.schema("Template").delete()
  108. }
  109. }
  110. /* Uncomment if you need to seed the table.
  111. struct seed: Migration {
  112. func prepare(on database: Database) -> EventLoopFuture<Void> {
  113. // 1
  114. let array: [<#Model#>] = [
  115. <#init#>
  116. ]
  117. // 2
  118. return array.map { obj in
  119. obj.save(on: database)
  120. }
  121. .flatten(on: database.eventLoop)
  122. }
  123. func revert(on database: Database) -> EventLoopFuture<Void> {
  124. // 3
  125. <#Model#>.query(on: database).delete()
  126. }
  127. }
  128. */
  129. }