Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

134 строки
4.5 KiB

  1. //
  2. // mdlLabSetting.swift
  3. //
  4. //
  5. // Created by Michiel Carman on 1/24/24.
  6. //
  7. import Fluent
  8. import Vapor
  9. import Foundation
  10. import FluentKit
  11. final class mdlLabSetting: Model, Content {
  12. static let schema = "labSetting"
  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: "barcodeDelimeter") var barcodedelimeter: String?
  17. @Field(key: "barcodeActive") var barcodeactive: Bool?
  18. @Field(key: "textActive") var textactive: Bool?
  19. @Field(key: "logoActive") var logoactive: Bool?
  20. @Field(key: "cpcl") var cpcl: String?
  21. @Parent(key: "locationId") var location: mdlLocation
  22. @Timestamp(key: "createDate", on: .create) var createdate: Date?
  23. @Field(key: "createUserId") var createuserid: Int?
  24. @Timestamp(key: "updateDate", on: .update) var updatedate: Date?
  25. @Field(key: "updateUserId") var updateuserid: Int?
  26. init() { }
  27. init(id: Int? = nil, name: String? = nil, description: String? = nil, barcodedelimeter: String? = nil, barcodeactive: Bool? = nil, textactive: Bool? = nil, logoactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil, cpc: String? = nil, locationid: Int) {
  28. self.id = id
  29. self.name = name
  30. self.description = description
  31. self.barcodedelimeter = barcodedelimeter
  32. self.barcodeactive = barcodeactive
  33. self.textactive = textactive
  34. self.logoactive = logoactive
  35. self.$location.$id.value = locationid
  36. self.createuserid = createuserid
  37. self.updateuserid = updateuserid
  38. self.cpcl = cpcl
  39. }
  40. }
  41. extension mdlLabSetting{
  42. struct Create: AsyncMigration {
  43. func prepare(on database: Database) async throws {
  44. try await database.schema("labSetting")
  45. .field("id", .int, .identifier(auto: true))
  46. .field("name", .string)
  47. .field("description", .string)
  48. .field("barcodeDelimeter", .string)
  49. .field("barcodeActive", .bool)
  50. .field("textActive", .bool)
  51. .field("logoActive", .bool)
  52. .field("createDate", .datetime)
  53. .field("createUserId", .int)
  54. .field("updateDate", .datetime)
  55. .field("updateUserId", .int)
  56. .create()
  57. }
  58. func revert(on database: Database) async throws {
  59. try await database.schema("labSetting").delete()
  60. }
  61. }
  62. struct Mod1: AsyncMigration{
  63. func prepare(on database: Database) async throws {
  64. try await database.schema("labSetting")
  65. .field("cpcl", .string)
  66. .update()
  67. }
  68. func revert(on database: Database) async throws {
  69. try await database.schema("labSetting")
  70. .deleteField("cpcl")
  71. .update()
  72. }
  73. }
  74. struct Mod2: AsyncMigration{
  75. func prepare(on database: Database) async throws {
  76. try await database.schema("labSetting")
  77. .field("locationId", .int, .references("location", "id"))
  78. .update()
  79. }
  80. func revert(on database: Database) async throws {
  81. try await database.schema("labSetting")
  82. .deleteField("locationId")
  83. .update()
  84. }
  85. }
  86. public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlLabSetting>{
  87. let query = mdlLabSetting.query(on: req.db)
  88. .with(\.$location)
  89. if let x = req.parameters.get("x"){
  90. let decryptedString = try CustomCrypto.DecryptString(input: x)
  91. let array = decryptedString.components(separatedBy: ":")
  92. ///This call is the standard get by id call
  93. if (array.count == 1){
  94. let id = Int(array[0])!
  95. return query.filter(\.$id == id)
  96. }
  97. ///Optional else if if there are multiple parameters in the call
  98. ///You must include an else for each call that has parameters
  99. ///Need to check the endpoint to get the right filter statements
  100. ///else if(x.count == 2){
  101. /// let username = x[0]
  102. /// let password = x[1]
  103. /// return query.filter(\.$username == username).filter(\.$password == password)
  104. ///}
  105. else{
  106. throw Abort(.badRequest)
  107. }
  108. }
  109. else{
  110. return query
  111. }
  112. }
  113. }