Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 

128 Zeilen
4.3 KiB

  1. //
  2. // mdlSpecItemValue.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 mdlSpecItemValue: Model, Content {
  12. static let schema = "specItemValue"
  13. @ID(custom: "id", generatedBy: .database) var id: Int?
  14. @Field(key: "value") var value: String?
  15. @Field(key: "sortOrder") var sortorder: Int?
  16. @Field(key: "isActive") var isactive: Bool?
  17. @Parent(key: "specItemId") var specitem: mdlSpecItem
  18. @Parent(key: "valueTypeId") var valuetype: mdlValueType
  19. @Timestamp(key: "createDate", on: .create) var createdate: Date?
  20. @Field(key: "createUserId") var createuserid: Int?
  21. @Timestamp(key: "updateDate", on: .update) var updatedate: Date?
  22. @Field(key: "updateUserId") var updateuserid: Int?
  23. init() { }
  24. init(id: Int? = nil, value: String? = nil, sortorder: Int? = nil, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil, specitemid: Int, valuetypeid: Int) {
  25. self.id = id
  26. self.value = value
  27. self.sortorder = sortorder
  28. self.$specitem.$id.value = specitemid
  29. self.$valuetype.$id.value = valuetypeid
  30. self.isactive = isactive
  31. self.createuserid = createuserid
  32. self.updateuserid = updateuserid
  33. }
  34. }
  35. extension mdlSpecItemValue{
  36. struct Create: AsyncMigration {
  37. func prepare(on database: Database) async throws {
  38. try await database.schema("specItemValue")
  39. .field("id", .int, .identifier(auto: true))
  40. .field("value", .string)
  41. .field("sortOrder", .int)
  42. .field("itemId", .int, .references("item", "id"))//need to fix
  43. .field("isActive", .bool)
  44. .field("createDate", .datetime)
  45. .field("createUserId", .int)
  46. .field("updateDate", .datetime)
  47. .field("updateUserId", .int)
  48. .create()
  49. }
  50. func revert(on database: Database) async throws {
  51. try await database.schema("specItemValue").delete()
  52. }
  53. }
  54. struct Mod1: AsyncMigration{
  55. func revert(on database: FluentKit.Database) async throws {
  56. try await database.schema("specItemValue")
  57. .deleteField("specItemId")
  58. .field("itemId", .int, .references("specItem", "id"))
  59. .update()
  60. }
  61. func prepare(on database: FluentKit.Database) async throws {
  62. try await database.schema("specItemValue")
  63. .deleteField("itemId")
  64. .field("specItemId", .int, .references("specItem", "id"))
  65. .update()
  66. }
  67. }
  68. struct Mod2: AsyncMigration{
  69. func revert(on database: FluentKit.Database) async throws {
  70. try await database.schema("specItemValue")
  71. .deleteField("valueTypeId")
  72. .update()
  73. }
  74. func prepare(on database: FluentKit.Database) async throws {
  75. try await database.schema("specItemValue")
  76. .field("valueTypeId", .int, .references("valueType", "id"))
  77. .update()
  78. }
  79. }
  80. public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlSpecItemValue>{
  81. let query = mdlSpecItemValue.query(on: req.db)
  82. .with(\.$specitem)
  83. .with(\.$valuetype)
  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. }