|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- //
- // mdlTblValue.swift
- //
- //
- // Created by Michiel Carman on 2/16/24.
- //
-
-
- import Fluent
- import Vapor
- import Foundation
- import FluentKit
-
- final class mdlTblValue: Model, Content {
- static let schema = "tblValue"
-
- @ID(custom: "id", generatedBy: .database) var id: Int?
-
- @Field(key: "field") var field: String?
- @Field(key: "value") var value: String?
-
- @Timestamp(key: "createDate", on: .create) var createdate: Date?
- @Field(key: "createUserId") var createuserid: Int?
- @Timestamp(key: "updateDate", on: .update) var updatedate: Date?
- @Field(key: "updateUserId") var updateuserid: Int?
-
- @Parent(key: "localeId") var locale: mdlLocale
- @OptionalParent(key: "categoryId") var category: mdlCategory?
- @OptionalParent(key: "comparisonTypeId") var comparisontype: mdlComparisonType?
- @OptionalParent(key: "compartmentId") var compartment: mdlCompartment?
- @OptionalParent(key: "compartmentLocationId") var compartmentlocation: mdlCompartmentLocation?
- @OptionalParent(key: "contactTypeId") var contacttype: mdlContactType?
- @OptionalParent(key: "dataTypeId") var datatype: mdlDataType?
- @OptionalParent(key: "divisiontId") var division: mdlDivision?
- @OptionalParent(key: "equipmentTypeId") var equipmenttype: mdlEquipmentType?
- @OptionalParent(key: "fluidId") var fluid: mdlFluid?
- @OptionalParent(key: "fuelId") var fuel: mdlFuel?
- @OptionalParent(key: "gateId") var gate: mdlGate?
- @OptionalParent(key: "incompleteReasonId") var incompletereason: mdlIncompleteReason?
- @OptionalParent(key: "inputTypeId") var inputtype: mdlInputType?
- @OptionalParent(key: "inspectionItemId") var inspectionitem: mdlInspectionItem?
- @OptionalParent(key: "inspectionItemResponseId") var inspectionitemresponse: mdlInspectionItemResponse?
- @OptionalParent(key: "inspectionLevelId") var inspectionlevel: mdlInspectionLevel?
- @OptionalParent(key: "inspectionTypeId") var inspectiontype: mdlInspectionType?
- @OptionalParent(key: "itemId") var item: mdlItem?
- @OptionalParent(key: "itemResponseTypeId") var itemresponsetype: mdlItemResponseType?
-
- init() { }
-
- init(id: Int? = nil,
- field: String? = nil,
- value: String? = nil,
- localid: Int,
- categoryid: Int? = nil,
- comparisontypeid: Int? = nil,
- compartmentid: Int? = nil,
- compartmentlocationid: Int? = nil,
- contacttypeid: Int? = nil,
- datatypeid: Int? = nil,
- divisionid: Int? = nil,
- equipmenttypeid: Int? = nil,
- fluidid: Int? = nil,
- gateid: Int? = nil,
- fuelid: Int? = nil,
- incompletereasonid: Int? = nil,
- inputtypeid: Int? = nil,
- inspectionitemid: Int? = nil,
- inspectionitemresponseid: Int? = nil,
- inspectionlevelid: Int? = nil,
- inspectiontypeid: Int? = nil,
- itemid: Int? = nil,
- itemresponsetypeid: Int? = nil,
- createuserid: Int? = nil,
- updateuserid: Int? = nil
- ) {
- self.id = id
- self.field = field
- self.value = value
- self.$locale.$id.value = localid
- self.$category.$id.value = categoryid!
- self.$comparisontype.$id.value = comparisontypeid!
- self.$compartment.$id.value = compartmentid!
- self.$compartmentlocation.$id.value = compartmentlocationid!
- self.$contacttype.$id.value = contacttypeid!
- self.$datatype.$id.value = datatypeid!
- self.$division.$id.value = divisionid!
- self.$equipmenttype.$id.value = equipmenttypeid!
- self.$fluid.$id.value = fluidid!
- self.$fuel.$id.value = fuelid!
- self.$gate.$id.value = gateid!
- self.$incompletereason.$id.value = incompletereasonid!
- self.$inputtype.$id.value = inputtypeid!
- self.$inspectionitem.$id.value = inspectionitemid!
- self.$inspectionitemresponse.$id.value = inspectionitemresponseid!
- self.$inspectionlevel.$id.value = inspectionlevelid!
- self.$inspectiontype.$id.value = inspectiontypeid!
- self.$item.$id.value = itemid!
- self.$itemresponsetype.$id.value = itemresponsetypeid!
- self.createuserid = createuserid
- self.updateuserid = updateuserid
- }
- }
- extension mdlTblValue{
- struct Create: AsyncMigration {
- func prepare(on database: Database) async throws {
- try await database.schema("tblValue")
- .field("id", .int, .identifier(auto: true))
- .field("field", .string)
- .field("value", .string)
- .field("localeId", .int, .references("locale", "id"))
- .field("categoryId", .int, .references("category", "id"))
- .field("comparisonTypeId", .int, .references("comparisonType", "id"))
- .field("createDate", .datetime)
- .field("createUserId", .int)
- .field("updateDate", .datetime)
- .field("updateUserId", .int)
- .create()
- }
-
- func revert(on database: Database) async throws {
- try await database.schema("tblValue").delete()
- }
- }
- struct AddOptionalParents: AsyncMigration {
- func prepare(on database: Database) async throws {
- try await database.schema("tblValue")
- .field("compartmentId", .int, .references("compartment", "id"))
- .field("compartmentLocationId", .int, .references("compartmentLocation", "id"))
- .field("contactTypeId", .int, .references("contactType", "id"))
- .field("dataTypeId", .int, .references("dataType", "id"))
- .field("divisionId", .int, .references("division", "id"))
- .field("equipmentTypeId", .int, .references("equipmentType", "id"))
- .field("fluidId", .int, .references("fluid", "id"))
- .field("fuelId", .int, .references("fuel", "id"))
- .field("gateId", .int, .references("gate", "id"))
- .field("incompleteReasonId", .int, .references("incompleteReason", "id"))
- .field("inputTypeId", .int, .references("inputType", "id"))
- .field("inspectionItemId", .int, .references("inspectionItemId", "id"))
- .field("inspectionItemResponseId", .int, .references("inspectionItemResposne", "id"))
- .field("inspectionLevelId", .int, .references("inspectionLevel", "id"))
- .field("inspectionTypeId", .int, .references("inspectionType", "id"))
- .field("itemId", .int, .references("item", "id"))
- .field("itemResponseTypeId", .int, .references("itemResponseType", "id"))
- .update()
- }
-
- func revert(on database: Database) async throws {
- try await database.schema("tblValue")
- .deleteField("compartmentId")
- .deleteField("compartmentLocationId")
- .deleteField("contactTypeId")
- .deleteField("dataTypeId")
- .deleteField("divisionId")
- .deleteField("equipmentTypeId")
- .deleteField("fluidId")
- .deleteField("fuelId")
- .deleteField("gateId")
- .deleteField("incompleteReasonId")
- .deleteField("inputTypeId")
- .deleteField("inspectionItemId")
- .deleteField("inspectionItemResponseId")
- .deleteField("inspectionLevelId")
- .deleteField("inspectionTypeId")
- .deleteField("itemResponseTypeId")
- .update()
- }
- }
- public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlTblValue>{
-
- let query = mdlTblValue.query(on: req.db)
- .with(\.$locale)
- .with(\.$category)
- .with(\.$comparisontype)
- .with(\.$compartment)
- .with(\.$compartmentlocation)
- .with(\.$contacttype)
- .with(\.$datatype)
- .with(\.$division)
- .with(\.$equipmenttype)
- .with(\.$fluid)
- .with(\.$fuel)
- .with(\.$gate)
- .with(\.$incompletereason)
- .with(\.$inputtype)
- .with(\.$inspectionitem)
- .with(\.$inspectionitemresponse)
- .with(\.$inspectionlevel)
- .with(\.$inspectiontype)
- .with(\.$item)
- .with(\.$itemresponsetype)
-
- if let x = req.parameters.get("x"){
- let decryptedString = try CustomCrypto.DecryptString(input: x)
- let array = decryptedString.components(separatedBy: ":")
- ///This call is the standard get by id call
- if (array.count == 1){
- let id = Int(array[0])!
- return query.filter(\.$id == id)
- }
- ///Optional else if if there are multiple parameters in the call
- ///You must include an else for each call that has parameters
- ///Need to check the endpoint to get the right filter statements
- ///else if(x.count == 2){
- /// let username = x[0]
- /// let password = x[1]
- /// return query.filter(\.$username == username).filter(\.$password == password)
- ///}
- else{
- throw Abort(.badRequest)
- }
-
- }
- else{
- return query
- }
- }
- }
-
|