Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 

219 righe
9.2 KiB

  1. //
  2. // mdlTblValue.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 mdlTblValue: Model, Content {
  12. static let schema = "tblValue"
  13. @ID(custom: "id", generatedBy: .database) var id: Int?
  14. @Field(key: "field") var field: String?
  15. @Field(key: "value") var value: String?
  16. @Timestamp(key: "createDate", on: .create) var createdate: Date?
  17. @Field(key: "createUserId") var createuserid: Int?
  18. @Timestamp(key: "updateDate", on: .update) var updatedate: Date?
  19. @Field(key: "updateUserId") var updateuserid: Int?
  20. @Parent(key: "localeId") var locale: mdlLocale
  21. @OptionalParent(key: "categoryId") var category: mdlCategory?
  22. @OptionalParent(key: "comparisonTypeId") var comparisontype: mdlComparisonType?
  23. @OptionalParent(key: "compartmentId") var compartment: mdlCompartment?
  24. @OptionalParent(key: "compartmentLocationId") var compartmentlocation: mdlCompartmentLocation?
  25. @OptionalParent(key: "contactTypeId") var contacttype: mdlContactType?
  26. @OptionalParent(key: "dataTypeId") var datatype: mdlDataType?
  27. @OptionalParent(key: "divisiontId") var division: mdlDivision?
  28. @OptionalParent(key: "equipmentTypeId") var equipmenttype: mdlEquipmentType?
  29. @OptionalParent(key: "fluidId") var fluid: mdlFluid?
  30. @OptionalParent(key: "fuelId") var fuel: mdlFuel?
  31. @OptionalParent(key: "gateId") var gate: mdlGate?
  32. @OptionalParent(key: "incompleteReasonId") var incompletereason: mdlIncompleteReason?
  33. @OptionalParent(key: "inputTypeId") var inputtype: mdlInputType?
  34. @OptionalParent(key: "inspectionItemId") var inspectionitem: mdlInspectionItem?
  35. @OptionalParent(key: "inspectionItemResponseId") var inspectionitemresponse: mdlInspectionItemResponse?
  36. @OptionalParent(key: "inspectionLevelId") var inspectionlevel: mdlInspectionLevel?
  37. @OptionalParent(key: "inspectionTypeId") var inspectiontype: mdlInspectionType?
  38. @OptionalParent(key: "itemId") var item: mdlItem?
  39. @OptionalParent(key: "itemResponseTypeId") var itemresponsetype: mdlItemResponseType?
  40. init() { }
  41. init(id: Int? = nil,
  42. field: String? = nil,
  43. value: String? = nil,
  44. localid: Int,
  45. categoryid: Int? = nil,
  46. comparisontypeid: Int? = nil,
  47. compartmentid: Int? = nil,
  48. compartmentlocationid: Int? = nil,
  49. contacttypeid: Int? = nil,
  50. datatypeid: Int? = nil,
  51. divisionid: Int? = nil,
  52. equipmenttypeid: Int? = nil,
  53. fluidid: Int? = nil,
  54. gateid: Int? = nil,
  55. fuelid: Int? = nil,
  56. incompletereasonid: Int? = nil,
  57. inputtypeid: Int? = nil,
  58. inspectionitemid: Int? = nil,
  59. inspectionitemresponseid: Int? = nil,
  60. inspectionlevelid: Int? = nil,
  61. inspectiontypeid: Int? = nil,
  62. itemid: Int? = nil,
  63. itemresponsetypeid: Int? = nil,
  64. createuserid: Int? = nil,
  65. updateuserid: Int? = nil
  66. ) {
  67. self.id = id
  68. self.field = field
  69. self.value = value
  70. self.$locale.$id.value = localid
  71. self.$category.$id.value = categoryid!
  72. self.$comparisontype.$id.value = comparisontypeid!
  73. self.$compartment.$id.value = compartmentid!
  74. self.$compartmentlocation.$id.value = compartmentlocationid!
  75. self.$contacttype.$id.value = contacttypeid!
  76. self.$datatype.$id.value = datatypeid!
  77. self.$division.$id.value = divisionid!
  78. self.$equipmenttype.$id.value = equipmenttypeid!
  79. self.$fluid.$id.value = fluidid!
  80. self.$fuel.$id.value = fuelid!
  81. self.$gate.$id.value = gateid!
  82. self.$incompletereason.$id.value = incompletereasonid!
  83. self.$inputtype.$id.value = inputtypeid!
  84. self.$inspectionitem.$id.value = inspectionitemid!
  85. self.$inspectionitemresponse.$id.value = inspectionitemresponseid!
  86. self.$inspectionlevel.$id.value = inspectionlevelid!
  87. self.$inspectiontype.$id.value = inspectiontypeid!
  88. self.$item.$id.value = itemid!
  89. self.$itemresponsetype.$id.value = itemresponsetypeid!
  90. self.createuserid = createuserid
  91. self.updateuserid = updateuserid
  92. }
  93. }
  94. extension mdlTblValue{
  95. struct Create: AsyncMigration {
  96. func prepare(on database: Database) async throws {
  97. try await database.schema("tblValue")
  98. .field("id", .int, .identifier(auto: true))
  99. .field("field", .string)
  100. .field("value", .string)
  101. .field("localeId", .int, .references("locale", "id"))
  102. .field("categoryId", .int, .references("category", "id"))
  103. .field("comparisonTypeId", .int, .references("comparisonType", "id"))
  104. .field("createDate", .datetime)
  105. .field("createUserId", .int)
  106. .field("updateDate", .datetime)
  107. .field("updateUserId", .int)
  108. .create()
  109. }
  110. func revert(on database: Database) async throws {
  111. try await database.schema("tblValue").delete()
  112. }
  113. }
  114. struct AddOptionalParents: AsyncMigration {
  115. func prepare(on database: Database) async throws {
  116. try await database.schema("tblValue")
  117. .field("compartmentId", .int, .references("compartment", "id"))
  118. .field("compartmentLocationId", .int, .references("compartmentLocation", "id"))
  119. .field("contactTypeId", .int, .references("contactType", "id"))
  120. .field("dataTypeId", .int, .references("dataType", "id"))
  121. .field("divisionId", .int, .references("division", "id"))
  122. .field("equipmentTypeId", .int, .references("equipmentType", "id"))
  123. .field("fluidId", .int, .references("fluid", "id"))
  124. .field("fuelId", .int, .references("fuel", "id"))
  125. .field("gateId", .int, .references("gate", "id"))
  126. .field("incompleteReasonId", .int, .references("incompleteReason", "id"))
  127. .field("inputTypeId", .int, .references("inputType", "id"))
  128. .field("inspectionItemId", .int, .references("inspectionItemId", "id"))
  129. .field("inspectionItemResponseId", .int, .references("inspectionItemResposne", "id"))
  130. .field("inspectionLevelId", .int, .references("inspectionLevel", "id"))
  131. .field("inspectionTypeId", .int, .references("inspectionType", "id"))
  132. .field("itemId", .int, .references("item", "id"))
  133. .field("itemResponseTypeId", .int, .references("itemResponseType", "id"))
  134. .update()
  135. }
  136. func revert(on database: Database) async throws {
  137. try await database.schema("tblValue")
  138. .deleteField("compartmentId")
  139. .deleteField("compartmentLocationId")
  140. .deleteField("contactTypeId")
  141. .deleteField("dataTypeId")
  142. .deleteField("divisionId")
  143. .deleteField("equipmentTypeId")
  144. .deleteField("fluidId")
  145. .deleteField("fuelId")
  146. .deleteField("gateId")
  147. .deleteField("incompleteReasonId")
  148. .deleteField("inputTypeId")
  149. .deleteField("inspectionItemId")
  150. .deleteField("inspectionItemResponseId")
  151. .deleteField("inspectionLevelId")
  152. .deleteField("inspectionTypeId")
  153. .deleteField("itemResponseTypeId")
  154. .update()
  155. }
  156. }
  157. public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlTblValue>{
  158. let query = mdlTblValue.query(on: req.db)
  159. .with(\.$locale)
  160. .with(\.$category)
  161. .with(\.$comparisontype)
  162. .with(\.$compartment)
  163. .with(\.$compartmentlocation)
  164. .with(\.$contacttype)
  165. .with(\.$datatype)
  166. .with(\.$division)
  167. .with(\.$equipmenttype)
  168. .with(\.$fluid)
  169. .with(\.$fuel)
  170. .with(\.$gate)
  171. .with(\.$incompletereason)
  172. .with(\.$inputtype)
  173. .with(\.$inspectionitem)
  174. .with(\.$inspectionitemresponse)
  175. .with(\.$inspectionlevel)
  176. .with(\.$inspectiontype)
  177. .with(\.$item)
  178. .with(\.$itemresponsetype)
  179. if let x = req.parameters.get("x"){
  180. let decryptedString = try CustomCrypto.DecryptString(input: x)
  181. let array = decryptedString.components(separatedBy: ":")
  182. ///This call is the standard get by id call
  183. if (array.count == 1){
  184. let id = Int(array[0])!
  185. return query.filter(\.$id == id)
  186. }
  187. ///Optional else if if there are multiple parameters in the call
  188. ///You must include an else for each call that has parameters
  189. ///Need to check the endpoint to get the right filter statements
  190. ///else if(x.count == 2){
  191. /// let username = x[0]
  192. /// let password = x[1]
  193. /// return query.filter(\.$username == username).filter(\.$password == password)
  194. ///}
  195. else{
  196. throw Abort(.badRequest)
  197. }
  198. }
  199. else{
  200. return query
  201. }
  202. }
  203. }