25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

96 satır
3.0 KiB

  1. //
  2. // mdlReason.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 mdlReason: Model, Content {
  12. static let schema = "reason"
  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. @Children(for: \.$reason) var workorders: [mdlWorkOrder]
  18. @Timestamp(key: "createDate", on: .create) var createdate: Date?
  19. @Field(key: "createUserId") var createuserid: Int?
  20. @Timestamp(key: "updateDate", on: .update) var updatedate: Date?
  21. @Field(key: "updateUserId") var updateuserid: Int?
  22. init() { }
  23. init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil) {
  24. self.id = id
  25. self.name = name
  26. self.description = description
  27. self.isactive = isactive
  28. self.createuserid = createuserid
  29. self.updateuserid = updateuserid
  30. }
  31. }
  32. extension mdlReason{
  33. struct Create: AsyncMigration {
  34. func prepare(on database: Database) async throws {
  35. try await database.schema("reason")
  36. .field("id", .int, .identifier(auto: true))
  37. .field("name", .string)
  38. .field("description", .string)
  39. .field("isActive", .bool)
  40. .field("createDate", .datetime)
  41. .field("createUserId", .int)
  42. .field("updateDate", .datetime)
  43. .field("updateUserId", .int)
  44. .create()
  45. }
  46. func revert(on database: Database) async throws {
  47. try await database.schema("reason").delete()
  48. }
  49. }
  50. public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlReason>{
  51. let query = mdlReason.query(on: req.db)
  52. .with(\.$workorders)
  53. if let x = req.parameters.get("x"){
  54. let decryptedString = try CustomCrypto.DecryptString(input: x)
  55. let array = decryptedString.components(separatedBy: ":")
  56. ///This call is the standard get by id call
  57. if (array.count == 1){
  58. let id = Int(array[0])!
  59. return query.filter(\.$id == id)
  60. }
  61. ///Optional else if if there are multiple parameters in the call
  62. ///You must include an else for each call that has parameters
  63. ///Need to check the endpoint to get the right filter statements
  64. ///else if(x.count == 2){
  65. /// let username = x[0]
  66. /// let password = x[1]
  67. /// return query.filter(\.$username == username).filter(\.$password == password)
  68. ///}
  69. else{
  70. throw Abort(.badRequest)
  71. }
  72. }
  73. else{
  74. return query
  75. }
  76. }
  77. }