Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

122 lignes
4.3 KiB

  1. //
  2. // mdlInspectionItemSpecItem.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 mdlInspectionItemSpecItem: Model, Content {
  12. static let schema = "inspectionItemSpecItem"
  13. @ID(custom: "id", generatedBy: .database) var id: Int?
  14. @Parent(key: "inspectionItemSpecId") var inspectionitemspec: mdlInspectionItemSpec
  15. @Parent(key: "comparisonTypeId") var comparisontype: mdlComparisonType
  16. @Parent(key: "unitId") var unit: mdlUnit
  17. @Field(key: "name") var name: String?
  18. @Field(key: "average") var average: Float?
  19. @Field(key: "qualifier") var qualifier: String?
  20. @Field(key: "result") var result: String?
  21. @Field(key: "sortOrder") var sortorder: Int?
  22. @Children(for: \.$specitem) var tests: [mdlInspectionItemSpecItemTest]
  23. @Children(for: \.$specitem) var values: [mdlInspectionItemSpecItemValue]
  24. @Timestamp(key: "createDate", on: .create) var createdate: Date?
  25. @Field(key: "createUserId") var createuserid: Int?
  26. @Timestamp(key: "updateDate", on: .update) var updatedate: Date?
  27. @Field(key: "updateUserId") var updateuserid: Int?
  28. init() { }
  29. init(id: Int? = nil,
  30. inspectionitemspecid: Int,
  31. comparisontypeid: Int,
  32. unitid: Int,
  33. name: String? = nil,
  34. average: Float? = nil,
  35. qualifier: String? = nil,
  36. result: String? = nil,
  37. sortorder: Int? = 0,
  38. createuserid: Int? = -1,
  39. updateuserid: Int? = -1
  40. ) {
  41. self.id = id
  42. self.$inspectionitemspec.$id.value = inspectionitemspecid
  43. self.$comparisontype.$id.value = comparisontypeid
  44. self.$unit.$id.value = unitid
  45. self.name = name
  46. self.average = average
  47. self.qualifier = qualifier
  48. self.result = result
  49. self.sortorder = sortorder
  50. self.createuserid = createuserid
  51. self.updateuserid = updateuserid
  52. }
  53. }
  54. extension mdlInspectionItemSpecItem{
  55. struct Create: AsyncMigration {
  56. func prepare(on database: Database) async throws {
  57. try await database.schema("inspectionItemSpecItem")
  58. .field("id", .int, .identifier(auto: true))
  59. .field("inspectionItemSpecId", .int, .references("inspectionItemSpec", "id"))
  60. .field("comparisonTypeId", .int, .references("comparisonType", "id"))
  61. .field("unitId", .int, .references("unit", "id"))
  62. .field("name", .string)
  63. .field("average", .float)
  64. .field("qualifier", .string)
  65. .field("result", .string)
  66. .field("sortOrder", .int)
  67. .field("createDate", .datetime)
  68. .field("createUserId", .int)
  69. .field("updateDate", .datetime)
  70. .field("updateUserId", .int)
  71. .create()
  72. }
  73. func revert(on database: Database) async throws {
  74. try await database.schema("inspectionItemSpecItem").delete()
  75. }
  76. }
  77. public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlInspectionItemSpecItem>{
  78. let query = mdlInspectionItemSpecItem.query(on: req.db)
  79. .with(\.$inspectionitemspec)
  80. .with(\.$comparisontype)
  81. .with(\.$unit)
  82. .with(\.$tests)
  83. .with(\.$values)
  84. if let x = req.parameters.get("x"){
  85. let decryptedString = try CustomCrypto.DecryptString(input: x)
  86. let array = decryptedString.components(separatedBy: ":")
  87. ///This call is the standard get by id call
  88. if (array.count == 1){
  89. let id = Int(array[0])!
  90. return query.filter(\.$id == id)
  91. }
  92. ///Optional else if if there are multiple parameters in the call
  93. ///You must include an else for each call that has parameters
  94. ///Need to check the endpoint to get the right filter statements
  95. ///else if(x.count == 2){
  96. /// let username = x[0]
  97. /// let password = x[1]
  98. /// return query.filter(\.$username == username).filter(\.$password == password)
  99. ///}
  100. else{
  101. throw Abort(.badRequest)
  102. }
  103. }
  104. else{
  105. return query
  106. }
  107. }
  108. }