diff --git a/Sources/App/Controllers/AuthControllers/cntrlRole.swift b/Sources/App/Controllers/AuthControllers/cntrlRole.swift index 2099689..2e7969d 100644 --- a/Sources/App/Controllers/AuthControllers/cntrlRole.swift +++ b/Sources/App/Controllers/AuthControllers/cntrlRole.swift @@ -12,33 +12,30 @@ struct cntrlRole: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("roles") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { todo in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlRole] { - try await mdlRole.query(on: req.db).with(\.$users).all() + try await mdlRole.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlRole{ + return try await mdlRole.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlRole { let obj = try req.content.decode(mdlRole.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlRole{ - let obj = try req.content.decode(mdlRole.self) - let dbobj = try await mdlRole.query(on: req.db).filter(\.$id == obj.id!).first()! - dbobj.description = obj.description - dbobj.name = obj.name - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlRole.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/AuthControllers/cntrlSegment.swift b/Sources/App/Controllers/AuthControllers/cntrlSegment.swift index 51a147b..0d55cc7 100644 --- a/Sources/App/Controllers/AuthControllers/cntrlSegment.swift +++ b/Sources/App/Controllers/AuthControllers/cntrlSegment.swift @@ -12,32 +12,30 @@ struct cntrlSegment: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("segments") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlSegment] { - try await mdlSegment.query(on: req.db).all() + try await mdlSegment.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlSegment{ + return try await mdlSegment.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlSegment { let obj = try req.content.decode(mdlSegment.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlSegment{ - let obj = try req.content.decode(mdlSegment.self) - let dbobj = try await mdlSegment.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlSegment.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/AuthControllers/cntrlUser.swift b/Sources/App/Controllers/AuthControllers/cntrlUser.swift index 28ff1ed..ca2983a 100644 --- a/Sources/App/Controllers/AuthControllers/cntrlUser.swift +++ b/Sources/App/Controllers/AuthControllers/cntrlUser.swift @@ -15,59 +15,29 @@ struct cntrlUser: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("users") rts.get(use: index) - rts.get("login", ":credentials", use: login) + rts.get("login", ":x", use: login) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { todo in + rts.group(":x") { todo in rts.delete(use: delete) } - rts.get("api", use: api) - - //let encryptionKey = SymmetricKey(data: Environment.get("ENCRYPTION_KEY")!.data(using: .utf8)!) -// rts.get(use: "login"){ -// req -> String in guard let dataQuery = req.query[String.self, at: "data"], let data = Data(base64Encoded: dataQuery) else{ -// throw Abort(.badRequest) -// } -// let encryptionKey = SymmetricKey(size: .bits256) { -// let sealedBox = try AES.GCM.SealedBox(combined: data) -// let decryptedData = try AES.GCM.open(sealedBox, using: encryptionKey) -// guard let decryptedString = String(data: decryptedData, encoding: .utf8) else{ -// throw Abort(.internalServerError, "Failed to decode decrypted data.") -// } -// } -// } } func api(req: Request) async throws -> String{ return Environment.get("API_KEY")! } - func login(req: Request) async throws -> mdlUser{ - guard let dataQuery = req.parameters.get("credentials") else{ - throw Abort(.badRequest) - } - let decryptedString = try CustomCrypto.DecryptString(input: dataQuery) - - let credentials = decryptedString.components(separatedBy: ":") - guard credentials.count == 2 else { - throw Abort(.badRequest, reason: "Invalid credential format.") - } - let username = credentials[0] - let password = credentials[1] - - return try await mdlUser.query(on: req.db) - .with(\.$roles) - .with(\.$division) - .with(\.$gate) - .with(\.$location) - .filter(\.$username == username) - .filter( \.$password == password) - .first()! + return try await mdlUser.ObjQuery(req: req).first()! } func index(req: Request) async throws -> [mdlUser] { - try await mdlUser.query(on: req.db).with(\.$roles).all() + //try await mdlUser.query(on: req.db).with(\.$roles).all() + return try await mdlUser.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlUser{ + return try await mdlUser.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlUser { @@ -78,22 +48,10 @@ struct cntrlUser: RouteCollection { try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlUser{ - let obj = try req.content.decode(mdlUser.self) - let dbobj = try await mdlUser.query(on: req.db).filter(\.$id == obj.id!).first()! - dbobj.firstname = obj.firstname - dbobj.lastname = obj.lastname - dbobj.email = obj.email - dbobj.password = obj.password - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } + func delete(req: Request) async throws -> HTTPStatus { - guard let obj = try await mdlUser.find(req.parameters.get("id"), on: req.db) else { + guard let obj = try await mdlUser.find(req.parameters.get("x"), on: req.db) else { throw Abort(.notFound) } try await obj.delete(on: req.db) diff --git a/Sources/App/Controllers/BaseControllers/ChildControllers/cntrlResponseType.swift b/Sources/App/Controllers/BaseControllers/ChildControllers/cntrlResponseType.swift index 0705e56..6a54921 100644 --- a/Sources/App/Controllers/BaseControllers/ChildControllers/cntrlResponseType.swift +++ b/Sources/App/Controllers/BaseControllers/ChildControllers/cntrlResponseType.swift @@ -12,32 +12,30 @@ struct cntrlResponseType: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("responsetypes") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlResponseType] { - try await mdlResponseType.query(on: req.db).all() + try await mdlResponseType.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlResponseType{ + return try await mdlResponseType.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlResponseType { let obj = try req.content.decode(mdlResponseType.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlResponseType{ - let obj = try req.content.decode(mdlResponseType.self) - let dbobj = try await mdlResponseType.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlResponseType.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/ChildControllers/cntrlUnit.swift b/Sources/App/Controllers/BaseControllers/ChildControllers/cntrlUnit.swift index 6ebea9a..a49c461 100644 --- a/Sources/App/Controllers/BaseControllers/ChildControllers/cntrlUnit.swift +++ b/Sources/App/Controllers/BaseControllers/ChildControllers/cntrlUnit.swift @@ -12,32 +12,30 @@ struct cntrlUnit: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("units") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlUnit] { - try await mdlUnit.query(on: req.db).all() + try await mdlUnit.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlUnit{ + return try await mdlUnit.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlUnit { let obj = try req.content.decode(mdlUnit.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlUnit{ - let obj = try req.content.decode(mdlUnit.self) - let dbobj = try await mdlUnit.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlUnit.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlCategory.swift b/Sources/App/Controllers/BaseControllers/cntrlCategory.swift index e6c7eae..a78eefe 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlCategory.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlCategory.swift @@ -5,34 +5,30 @@ struct cntrlCategory: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("categories") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { todo in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlCategory] { - try await mdlCategory.query(on: req.db).all() + try await mdlCategory.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlCategory{ + return try await mdlCategory.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlCategory { let obj = try req.content.decode(mdlCategory.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlCategory{ - let obj = try req.content.decode(mdlCategory.self) - let dbobj = try await mdlCategory.query(on: req.db).filter(\.$id == obj.id!).first()! - dbobj.description = obj.description - dbobj.name = obj.name - dbobj.updatedate = Date() - dbobj.isactive = obj.isactive - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlCategory.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlComparisonType.swift b/Sources/App/Controllers/BaseControllers/cntrlComparisonType.swift index 956b388..0c21278 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlComparisonType.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlComparisonType.swift @@ -10,34 +10,32 @@ import Vapor struct cntrlComparisonType: RouteCollection { func boot(routes: RoutesBuilder) throws { - let rts = routes.grouped("comparisonTypes") + let rts = routes.grouped("comparisontypes") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlComparisonType] { - try await mdlComparisonType.query(on: req.db).all() + try await mdlComparisonType.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlComparisonType{ + return try await mdlComparisonType.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlComparisonType { let obj = try req.content.decode(mdlComparisonType.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlComparisonType{ - let obj = try req.content.decode(mdlComparisonType.self) - let dbobj = try await mdlComparisonType.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlComparisonType.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlContactType.swift b/Sources/App/Controllers/BaseControllers/cntrlContactType.swift index fa0a821..f2194a6 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlContactType.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlContactType.swift @@ -10,34 +10,32 @@ import Vapor struct cntrlContactType: RouteCollection { func boot(routes: RoutesBuilder) throws { - let rts = routes.grouped("contactTypes") + let rts = routes.grouped("contacttypes") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlContactType] { - try await mdlContactType.query(on: req.db).all() + try await mdlContactType.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlContactType{ + return try await mdlContactType.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlContactType { let obj = try req.content.decode(mdlContactType.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlContactType{ - let obj = try req.content.decode(mdlContactType.self) - let dbobj = try await mdlContactType.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlContactType.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlDataType.swift b/Sources/App/Controllers/BaseControllers/cntrlDataType.swift index eb7c437..2452e35 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlDataType.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlDataType.swift @@ -3,43 +3,32 @@ import Vapor struct cntrlDataTypes: RouteCollection { func boot(routes: RoutesBuilder) throws { - let rts = routes.grouped("dataTypes") + let rts = routes.grouped("datatypes") rts.get(use: index) - rts.get(":id", use: search) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in - rt.delete(use: delete) + rts.group(":x") { rt in + rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlDataType] { - try await mdlDataType.query(on: req.db).with(\.$units).all() + try await mdlDataType.ObjQuery(req: req).with(\.$units).all() } - func search(req: Request) async throws -> mdlDataType{ - guard let id = req.parameters.get("id", as: Int.self) else{ - throw Abort(.notFound) - } - return try await mdlDataType.query(on: req.db).with(\.$units).filter(\.$id == id).first()! + func read(req:Request) async throws -> mdlDataType{ + return try await mdlDataType.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlDataType { let obj = try req.content.decode(mdlDataType.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlDataType{ - let obj = try req.content.decode(mdlDataType.self) - let dbobj = try await mdlDataType.query(on: req.db).with(\.$units).filter(\.$id == obj.id!).first()! - dbobj.description = obj.description - dbobj.name = obj.name - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlDataType.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlDivision.swift b/Sources/App/Controllers/BaseControllers/cntrlDivision.swift index 3377595..7aba2be 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlDivision.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlDivision.swift @@ -12,32 +12,30 @@ struct cntrlDivision: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("divisions") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlDivision] { - try await mdlDivision.query(on: req.db).all() + try await mdlDivision.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlDivision{ + return try await mdlDivision.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlDivision { let obj = try req.content.decode(mdlDivision.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlDivision{ - let obj = try req.content.decode(mdlDivision.self) - let dbobj = try await mdlDivision.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlDivision.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlEquipmentType.swift b/Sources/App/Controllers/BaseControllers/cntrlEquipmentType.swift index cd1e04b..ff4f32d 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlEquipmentType.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlEquipmentType.swift @@ -12,32 +12,30 @@ struct cntrlEquipmentType: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("equipmenttypes") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlEquipmentType] { - try await mdlEquipmentType.query(on: req.db).all() + try await mdlEquipmentType.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlEquipmentType{ + return try await mdlEquipmentType.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlEquipmentType { let obj = try req.content.decode(mdlEquipmentType.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlEquipmentType{ - let obj = try req.content.decode(mdlEquipmentType.self) - let dbobj = try await mdlEquipmentType.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlEquipmentType.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlFluid.swift b/Sources/App/Controllers/BaseControllers/cntrlFluid.swift index a726ef1..bba7b9e 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlFluid.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlFluid.swift @@ -12,32 +12,30 @@ struct cntrlFluid: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("fluids") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlFluid] { - try await mdlFluid.query(on: req.db).all() + try await mdlFluid.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlFluid{ + return try await mdlFluid.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlFluid { let obj = try req.content.decode(mdlFluid.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlFluid{ - let obj = try req.content.decode(mdlFluid.self) - let dbobj = try await mdlFluid.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlFluid.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlFuel.swift b/Sources/App/Controllers/BaseControllers/cntrlFuel.swift index 9ea9f77..cba15f0 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlFuel.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlFuel.swift @@ -12,32 +12,30 @@ struct cntrlFuel: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("fuels") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlFuel] { - try await mdlFuel.query(on: req.db).all() + try await mdlFuel.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlFuel{ + return try await mdlFuel.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlFuel { let obj = try req.content.decode(mdlFuel.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlFuel{ - let obj = try req.content.decode(mdlFuel.self) - let dbobj = try await mdlFuel.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlFuel.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlGate.swift b/Sources/App/Controllers/BaseControllers/cntrlGate.swift index 2a79915..1554327 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlGate.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlGate.swift @@ -12,32 +12,30 @@ struct cntrlGate: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("gates") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlGate] { - try await mdlGate.query(on: req.db).all() + try await mdlGate.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlGate{ + return try await mdlGate.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlGate { let obj = try req.content.decode(mdlGate.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlGate{ - let obj = try req.content.decode(mdlGate.self) - let dbobj = try await mdlGate.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlGate.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlIncompleteReason.swift b/Sources/App/Controllers/BaseControllers/cntrlIncompleteReason.swift index ed17786..2b32876 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlIncompleteReason.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlIncompleteReason.swift @@ -12,15 +12,20 @@ struct cntrlIncompleteReason: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("incompletereasons") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlIncompleteReason] { - try await mdlIncompleteReason.query(on: req.db).all() + try await mdlIncompleteReason.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlIncompleteReason{ + return try await mdlIncompleteReason.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlIncompleteReason { @@ -28,16 +33,6 @@ struct cntrlIncompleteReason: RouteCollection { try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlIncompleteReason{ - let obj = try req.content.decode(mdlIncompleteReason.self) - let dbobj = try await mdlIncompleteReason.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlIncompleteReason.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlInputType.swift b/Sources/App/Controllers/BaseControllers/cntrlInputType.swift index d2e5e7f..f466472 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlInputType.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlInputType.swift @@ -12,32 +12,30 @@ struct cntrlInputType: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("inputtypes") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlInputType] { - try await mdlInputType.query(on: req.db).all() + try await mdlInputType.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlInputType{ + return try await mdlInputType.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlInputType { let obj = try req.content.decode(mdlInputType.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlInputType{ - let obj = try req.content.decode(mdlInputType.self) - let dbobj = try await mdlInputType.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlInputType.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlJobSite.swift b/Sources/App/Controllers/BaseControllers/cntrlJobSite.swift index 8afa17c..4b92151 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlJobSite.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlJobSite.swift @@ -12,32 +12,30 @@ struct cntrlJobSite: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("jobsites") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlJobSite] { - try await mdlJobSite.query(on: req.db).all() + try await mdlJobSite.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlJobSite{ + return try await mdlJobSite.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlJobSite { let obj = try req.content.decode(mdlJobSite.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlJobSite{ - let obj = try req.content.decode(mdlJobSite.self) - let dbobj = try await mdlJobSite.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlJobSite.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlLevel.swift b/Sources/App/Controllers/BaseControllers/cntrlLevel.swift index 51eea06..93bcc0b 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlLevel.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlLevel.swift @@ -12,32 +12,30 @@ struct cntrlLevel: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("levels") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlLevel] { try await mdlLevel.query(on: req.db).all() } + func read(req:Request) async throws -> mdlLevel{ + return try await mdlLevel.ObjQuery(req: req).first()! + } + func create(req: Request) async throws -> mdlLevel { let obj = try req.content.decode(mdlLevel.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlLevel{ - let obj = try req.content.decode(mdlLevel.self) - let dbobj = try await mdlLevel.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlLevel.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlLocation.swift b/Sources/App/Controllers/BaseControllers/cntrlLocation.swift index 2f22bed..2f3ae1d 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlLocation.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlLocation.swift @@ -12,32 +12,30 @@ struct cntrlLocation: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("locations") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlLocation] { - try await mdlLocation.query(on: req.db).all() + try await mdlLocation.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlLocation{ + return try await mdlLocation.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlLocation { let obj = try req.content.decode(mdlLocation.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlLocation{ - let obj = try req.content.decode(mdlLocation.self) - let dbobj = try await mdlLocation.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlLocation.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlNoteType.swift b/Sources/App/Controllers/BaseControllers/cntrlNoteType.swift index 7c916c7..15c613d 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlNoteType.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlNoteType.swift @@ -12,32 +12,30 @@ struct cntrlNoteType: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("notetypes") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlNoteType] { - try await mdlNoteType.query(on: req.db).all() + try await mdlNoteType.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlNoteType{ + return try await mdlNoteType.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlNoteType { let obj = try req.content.decode(mdlNoteType.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlNoteType{ - let obj = try req.content.decode(mdlNoteType.self) - let dbobj = try await mdlNoteType.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlNoteType.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlPart.swift b/Sources/App/Controllers/BaseControllers/cntrlPart.swift index a0ce52a..ee123b3 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlPart.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlPart.swift @@ -12,32 +12,30 @@ struct cntrlPart: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("parts") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlPart] { - try await mdlPart.query(on: req.db).all() + try await mdlPart.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlPart{ + return try await mdlPart.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlPart { let obj = try req.content.decode(mdlPart.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlPart{ - let obj = try req.content.decode(mdlPart.self) - let dbobj = try await mdlPart.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlPart.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlPriority.swift b/Sources/App/Controllers/BaseControllers/cntrlPriority.swift index ca2435a..37d9194 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlPriority.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlPriority.swift @@ -12,32 +12,30 @@ struct cntrlPriority: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("priorities") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlPriority] { - try await mdlPriority.query(on: req.db).all() + try await mdlPriority.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlPriority{ + return try await mdlPriority.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlPriority { let obj = try req.content.decode(mdlPriority.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlPriority{ - let obj = try req.content.decode(mdlPriority.self) - let dbobj = try await mdlPriority.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlPriority.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlReason.swift b/Sources/App/Controllers/BaseControllers/cntrlReason.swift index 154fa21..a3a2024 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlReason.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlReason.swift @@ -12,32 +12,30 @@ struct cntrlReason: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("reasons") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlReason] { - try await mdlReason.query(on: req.db).all() + try await mdlReason.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlReason{ + return try await mdlReason.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlReason { let obj = try req.content.decode(mdlReason.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlReason{ - let obj = try req.content.decode(mdlReason.self) - let dbobj = try await mdlReason.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlReason.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlRepairType.swift b/Sources/App/Controllers/BaseControllers/cntrlRepairType.swift index d9f9174..8318b5f 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlRepairType.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlRepairType.swift @@ -12,32 +12,30 @@ struct cntrlRepairType: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("repairtypes") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlRepairType] { - try await mdlRepairType.query(on: req.db).all() + try await mdlRepairType.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlRepairType{ + return try await mdlRepairType.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlRepairType { let obj = try req.content.decode(mdlRepairType.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlRepairType{ - let obj = try req.content.decode(mdlRepairType.self) - let dbobj = try await mdlRepairType.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlRepairType.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlSMSCCode.swift b/Sources/App/Controllers/BaseControllers/cntrlSMSCCode.swift index 6cc48ce..6521cb8 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlSMSCCode.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlSMSCCode.swift @@ -12,32 +12,30 @@ struct cntrlSMSCCode: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("smsccodes") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlSMSCCode] { - try await mdlSMSCCode.query(on: req.db).all() + try await mdlSMSCCode.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlSMSCCode{ + return try await mdlSMSCCode.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlSMSCCode { let obj = try req.content.decode(mdlSMSCCode.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlSMSCCode{ - let obj = try req.content.decode(mdlSMSCCode.self) - let dbobj = try await mdlSMSCCode.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlSMSCCode.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlSignatureType.swift b/Sources/App/Controllers/BaseControllers/cntrlSignatureType.swift index 83ae730..fc4d279 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlSignatureType.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlSignatureType.swift @@ -12,32 +12,30 @@ struct cntrlSignatureType: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("signaturetypes") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlSignatureType] { - try await mdlSignatureType.query(on: req.db).all() + try await mdlSignatureType.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlSignatureType{ + return try await mdlSignatureType.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlSignatureType { let obj = try req.content.decode(mdlSignatureType.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlSignatureType{ - let obj = try req.content.decode(mdlSignatureType.self) - let dbobj = try await mdlSignatureType.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlSignatureType.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlState.swift b/Sources/App/Controllers/BaseControllers/cntrlState.swift index 4d48b07..a99b08b 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlState.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlState.swift @@ -12,32 +12,30 @@ struct cntrlState: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("states") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlState] { - try await mdlState.query(on: req.db).all() + try await mdlState.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlState{ + return try await mdlState.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlState { let obj = try req.content.decode(mdlState.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlState{ - let obj = try req.content.decode(mdlState.self) - let dbobj = try await mdlState.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlState.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlStatus.swift b/Sources/App/Controllers/BaseControllers/cntrlStatus.swift index 647aa99..acdcfe4 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlStatus.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlStatus.swift @@ -12,32 +12,30 @@ struct cntrlStatus: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("statuses") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlStatus] { - try await mdlStatus.query(on: req.db).all() + try await mdlStatus.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlStatus{ + return try await mdlStatus.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlStatus { let obj = try req.content.decode(mdlStatus.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlStatus{ - let obj = try req.content.decode(mdlStatus.self) - let dbobj = try await mdlStatus.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlStatus.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlValueType.swift b/Sources/App/Controllers/BaseControllers/cntrlValueType.swift index d7d6e6c..c7bad2f 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlValueType.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlValueType.swift @@ -3,43 +3,32 @@ import Vapor struct cntrlValueType: RouteCollection { func boot(routes: RoutesBuilder) throws { - let rts = routes.grouped("valueTypes") + let rts = routes.grouped("valuetypes") rts.get(use: index) - rts.get(":id", use: search) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in - rt.delete(use: delete) + rts.group(":x") { rt in + rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlValueType] { - try await mdlValueType.query(on: req.db).all() + try await mdlValueType.ObjQuery(req: req).all() } - func search(req: Request) async throws -> mdlValueType{ - guard let id = req.parameters.get("id", as: Int.self) else{ - throw Abort(.notFound) - } - return try await mdlValueType.query(on: req.db).filter(\.$id == id).first()! + func read(req:Request) async throws -> mdlValueType{ + return try await mdlValueType.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlValueType { let obj = try req.content.decode(mdlValueType.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlValueType{ - let obj = try req.content.decode(mdlValueType.self) - let dbobj = try await mdlValueType.query(on: req.db).filter(\.$id == obj.id!).first()! - dbobj.description = obj.description - dbobj.name = obj.name - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlValueType.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/BaseControllers/cntrlViscosity.swift b/Sources/App/Controllers/BaseControllers/cntrlViscosity.swift index 66f8a6d..0dcebc1 100644 --- a/Sources/App/Controllers/BaseControllers/cntrlViscosity.swift +++ b/Sources/App/Controllers/BaseControllers/cntrlViscosity.swift @@ -12,19 +12,27 @@ struct cntrlViscosity: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("viscosities") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlViscosity] { - try await mdlViscosity.query(on: req.db).all() + try await mdlViscosity.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlViscosity{ + return try await mdlViscosity.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlViscosity { let obj = try req.content.decode(mdlViscosity.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } diff --git a/Sources/App/Controllers/CompartmentControllers/cntrlCompartment.swift b/Sources/App/Controllers/CompartmentControllers/cntrlCompartment.swift index 11e985b..fa7fc81 100644 --- a/Sources/App/Controllers/CompartmentControllers/cntrlCompartment.swift +++ b/Sources/App/Controllers/CompartmentControllers/cntrlCompartment.swift @@ -12,32 +12,30 @@ struct cntrlCompartment: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("compartments") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlCompartment] { - try await mdlCompartment.query(on: req.db).all() + try await mdlCompartment.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlCompartment{ + return try await mdlCompartment.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlCompartment { let obj = try req.content.decode(mdlCompartment.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlCompartment{ - let obj = try req.content.decode(mdlCompartment.self) - let dbobj = try await mdlCompartment.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlCompartment.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/CompartmentControllers/cntrlCompartmentLocation.swift b/Sources/App/Controllers/CompartmentControllers/cntrlCompartmentLocation.swift index 1425c44..93b5271 100644 --- a/Sources/App/Controllers/CompartmentControllers/cntrlCompartmentLocation.swift +++ b/Sources/App/Controllers/CompartmentControllers/cntrlCompartmentLocation.swift @@ -12,19 +12,27 @@ struct cntrlCompartmentLocation: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("compartmentlocations") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlCompartmentLocation] { - try await mdlCompartmentLocation.query(on: req.db).all() + try await mdlCompartmentLocation.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlCompartmentLocation{ + return try await mdlCompartmentLocation.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlCompartmentLocation { let obj = try req.content.decode(mdlCompartmentLocation.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } diff --git a/Sources/App/Controllers/CustomerControllers/cntrlContact.swift b/Sources/App/Controllers/CustomerControllers/cntrlContact.swift index f293e9c..ab94825 100644 --- a/Sources/App/Controllers/CustomerControllers/cntrlContact.swift +++ b/Sources/App/Controllers/CustomerControllers/cntrlContact.swift @@ -12,32 +12,30 @@ struct cntrlContact: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("contacts") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlContact] { - try await mdlContact.query(on: req.db).all() + try await mdlContact.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlContact{ + return try await mdlContact.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlContact { let obj = try req.content.decode(mdlContact.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlContact{ - let obj = try req.content.decode(mdlContact.self) - let dbobj = try await mdlContact.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlContact.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/CustomerControllers/cntrlContactInfo.swift b/Sources/App/Controllers/CustomerControllers/cntrlContactInfo.swift index da1994b..1709b03 100644 --- a/Sources/App/Controllers/CustomerControllers/cntrlContactInfo.swift +++ b/Sources/App/Controllers/CustomerControllers/cntrlContactInfo.swift @@ -12,32 +12,30 @@ struct cntrlContactInfo: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("contactinfos") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlContactInfo] { - try await mdlContactInfo.query(on: req.db).all() + try await mdlContactInfo.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlContactInfo{ + return try await mdlContactInfo.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlContactInfo { let obj = try req.content.decode(mdlContactInfo.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlContactInfo{ - let obj = try req.content.decode(mdlContactInfo.self) - let dbobj = try await mdlContactInfo.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlContactInfo.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/CustomerControllers/cntrlCustomer.swift b/Sources/App/Controllers/CustomerControllers/cntrlCustomer.swift index 64d5273..31d02f2 100644 --- a/Sources/App/Controllers/CustomerControllers/cntrlCustomer.swift +++ b/Sources/App/Controllers/CustomerControllers/cntrlCustomer.swift @@ -12,32 +12,30 @@ struct cntrlCustomer: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("customers") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlCustomer] { - try await mdlCustomer.query(on: req.db).all() + try await mdlCustomer.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlCustomer{ + return try await mdlCustomer.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlCustomer { let obj = try req.content.decode(mdlCustomer.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlCustomer{ - let obj = try req.content.decode(mdlCustomer.self) - let dbobj = try await mdlCustomer.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlCustomer.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/CustomerControllers/cntrlEquipment.swift b/Sources/App/Controllers/CustomerControllers/cntrlEquipment.swift index c9b614b..fbc4747 100644 --- a/Sources/App/Controllers/CustomerControllers/cntrlEquipment.swift +++ b/Sources/App/Controllers/CustomerControllers/cntrlEquipment.swift @@ -12,32 +12,30 @@ struct cntrlEquipment: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("equipments") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlEquipment] { - try await mdlEquipment.query(on: req.db).all() + try await mdlEquipment.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlEquipment{ + return try await mdlEquipment.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlEquipment { let obj = try req.content.decode(mdlEquipment.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlEquipment{ - let obj = try req.content.decode(mdlEquipment.self) - let dbobj = try await mdlEquipment.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlEquipment.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/CustomerControllers/cntrlMake.swift b/Sources/App/Controllers/CustomerControllers/cntrlMake.swift index 5de1936..4067786 100644 --- a/Sources/App/Controllers/CustomerControllers/cntrlMake.swift +++ b/Sources/App/Controllers/CustomerControllers/cntrlMake.swift @@ -12,32 +12,30 @@ struct cntrlMake: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("makes") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlMake] { - try await mdlMake.query(on: req.db).all() + try await mdlMake.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlMake{ + return try await mdlMake.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlMake { let obj = try req.content.decode(mdlMake.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlMake{ - let obj = try req.content.decode(mdlMake.self) - let dbobj = try await mdlMake.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlMake.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/CustomerControllers/cntrlModel.swift b/Sources/App/Controllers/CustomerControllers/cntrlModel.swift index 3e3005b..bd39da7 100644 --- a/Sources/App/Controllers/CustomerControllers/cntrlModel.swift +++ b/Sources/App/Controllers/CustomerControllers/cntrlModel.swift @@ -12,32 +12,30 @@ struct cntrlModel: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("models") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlModel] { - try await mdlModel.query(on: req.db).all() + try await mdlModel.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlModel{ + return try await mdlModel.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlModel { let obj = try req.content.decode(mdlModel.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlModel{ - let obj = try req.content.decode(mdlModel.self) - let dbobj = try await mdlModel.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlModel.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/CustomerControllers/cntrlObjectProperty.swift b/Sources/App/Controllers/CustomerControllers/cntrlObjectProperty.swift index 38e06ee..ef92bdf 100644 --- a/Sources/App/Controllers/CustomerControllers/cntrlObjectProperty.swift +++ b/Sources/App/Controllers/CustomerControllers/cntrlObjectProperty.swift @@ -12,32 +12,30 @@ struct cntrlObjProperty: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("objproperties") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlObjProperty] { - try await mdlObjProperty.query(on: req.db).all() + try await mdlObjProperty.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlObjProperty{ + return try await mdlObjProperty.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlObjProperty { let obj = try req.content.decode(mdlObjProperty.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlObjProperty{ - let obj = try req.content.decode(mdlObjProperty.self) - let dbobj = try await mdlObjProperty.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlObjProperty.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/CustomerControllers/cntrlProduct.swift b/Sources/App/Controllers/CustomerControllers/cntrlProduct.swift index dbd6079..fe7ff9a 100644 --- a/Sources/App/Controllers/CustomerControllers/cntrlProduct.swift +++ b/Sources/App/Controllers/CustomerControllers/cntrlProduct.swift @@ -12,32 +12,30 @@ struct cntrlProduct: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("products") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlProduct] { - try await mdlProduct.query(on: req.db).all() + try await mdlProduct.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlProduct{ + return try await mdlProduct.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlProduct { let obj = try req.content.decode(mdlProduct.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlProduct{ - let obj = try req.content.decode(mdlProduct.self) - let dbobj = try await mdlProduct.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlProduct.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/ItemControllers/cntrlItem.swift b/Sources/App/Controllers/ItemControllers/cntrlItem.swift index f2a2b5b..574822d 100644 --- a/Sources/App/Controllers/ItemControllers/cntrlItem.swift +++ b/Sources/App/Controllers/ItemControllers/cntrlItem.swift @@ -12,32 +12,30 @@ struct cntrlItem: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("items") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlItem] { - try await mdlItem.query(on: req.db).all() + try await mdlItem.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlItem{ + return try await mdlItem.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlItem { let obj = try req.content.decode(mdlItem.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlItem{ - let obj = try req.content.decode(mdlItem.self) - let dbobj = try await mdlItem.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlItem.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/ItemControllers/cntrlItemResponseType.swift b/Sources/App/Controllers/ItemControllers/cntrlItemResponseType.swift index 5a00fc6..f3d1ae5 100644 --- a/Sources/App/Controllers/ItemControllers/cntrlItemResponseType.swift +++ b/Sources/App/Controllers/ItemControllers/cntrlItemResponseType.swift @@ -12,32 +12,30 @@ struct cntrlItemResponseType: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("itemresponsetypes") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlItemResponseType] { - try await mdlItemResponseType.query(on: req.db).all() + try await mdlItemResponseType.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlItemResponseType{ + return try await mdlItemResponseType.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlItemResponseType { let obj = try req.content.decode(mdlItemResponseType.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlItemResponseType{ - let obj = try req.content.decode(mdlItemResponseType.self) - let dbobj = try await mdlItemResponseType.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlItemResponseType.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/LabControllers/cntrlLabSetting.swift b/Sources/App/Controllers/LabControllers/cntrlLabSetting.swift index da75487..83a8481 100644 --- a/Sources/App/Controllers/LabControllers/cntrlLabSetting.swift +++ b/Sources/App/Controllers/LabControllers/cntrlLabSetting.swift @@ -12,32 +12,30 @@ struct cntrlLabSetting: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("labsettings") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlLabSetting] { - try await mdlLabSetting.query(on: req.db).all() + try await mdlLabSetting.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlLabSetting{ + return try await mdlLabSetting.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlLabSetting { let obj = try req.content.decode(mdlLabSetting.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlLabSetting{ - let obj = try req.content.decode(mdlLabSetting.self) - let dbobj = try await mdlLabSetting.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlLabSetting.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/LinkingControllers/cntrlXFluidViscosity.swift b/Sources/App/Controllers/LinkingControllers/cntrlXFluidViscosity.swift index 1d1109f..1104af0 100644 --- a/Sources/App/Controllers/LinkingControllers/cntrlXFluidViscosity.swift +++ b/Sources/App/Controllers/LinkingControllers/cntrlXFluidViscosity.swift @@ -12,32 +12,30 @@ struct cntrlXFluidViscosity: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("xfluidviscosities") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlXFluidViscosity] { - try await mdlXFluidViscosity.query(on: req.db).all() + try await mdlXFluidViscosity.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlXFluidViscosity{ + return try await mdlXFluidViscosity.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlXFluidViscosity { let obj = try req.content.decode(mdlXFluidViscosity.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlXFluidViscosity{ - let obj = try req.content.decode(mdlXFluidViscosity.self) - let dbobj = try await mdlXFluidViscosity.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlXFluidViscosity.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/LinkingControllers/cntrlXUserRole.swift b/Sources/App/Controllers/LinkingControllers/cntrlXUserRole.swift index 287d46c..4b144a0 100644 --- a/Sources/App/Controllers/LinkingControllers/cntrlXUserRole.swift +++ b/Sources/App/Controllers/LinkingControllers/cntrlXUserRole.swift @@ -12,32 +12,30 @@ struct cntrlXUserRole: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("xuserroles") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlXUserRole] { - try await mdlXUserRole.query(on: req.db).all() + try await mdlXUserRole.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlXUserRole{ + return try await mdlXUserRole.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlXUserRole { let obj = try req.content.decode(mdlXUserRole.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlXUserRole{ - let obj = try req.content.decode(mdlXUserRole.self) - let dbobj = try await mdlXUserRole.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlXUserRole.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/OilSampleControllers/cntrlOilSample.swift b/Sources/App/Controllers/OilSampleControllers/cntrlOilSample.swift index 7ce9b84..5e46382 100644 --- a/Sources/App/Controllers/OilSampleControllers/cntrlOilSample.swift +++ b/Sources/App/Controllers/OilSampleControllers/cntrlOilSample.swift @@ -12,32 +12,30 @@ struct cntrlOilSample: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("oilsamples") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlOilSample] { - try await mdlOilSample.query(on: req.db).all() + try await mdlOilSample.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlOilSample{ + return try await mdlOilSample.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlOilSample { let obj = try req.content.decode(mdlOilSample.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlOilSample{ - let obj = try req.content.decode(mdlOilSample.self) - let dbobj = try await mdlOilSample.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlOilSample.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/SpecControllers/cntrlSpec.swift b/Sources/App/Controllers/SpecControllers/cntrlSpec.swift index 83573d5..4ff134b 100644 --- a/Sources/App/Controllers/SpecControllers/cntrlSpec.swift +++ b/Sources/App/Controllers/SpecControllers/cntrlSpec.swift @@ -12,32 +12,30 @@ struct cntrlSpec: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("specs") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlSpec] { - try await mdlSpec.query(on: req.db).all() + try await mdlSpec.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlSpec{ + return try await mdlSpec.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlSpec { let obj = try req.content.decode(mdlSpec.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlSpec{ - let obj = try req.content.decode(mdlSpec.self) - let dbobj = try await mdlSpec.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlSpec.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/SpecControllers/cntrlSpecItem.swift b/Sources/App/Controllers/SpecControllers/cntrlSpecItem.swift index 4d8873d..65725af 100644 --- a/Sources/App/Controllers/SpecControllers/cntrlSpecItem.swift +++ b/Sources/App/Controllers/SpecControllers/cntrlSpecItem.swift @@ -12,32 +12,30 @@ struct cntrlSpecItem: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("specitems") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlSpecItem] { - try await mdlSpecItem.query(on: req.db).all() + try await mdlSpecItem.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlSpecItem{ + return try await mdlSpecItem.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlSpecItem { let obj = try req.content.decode(mdlSpecItem.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlSpecItem{ - let obj = try req.content.decode(mdlSpecItem.self) - let dbobj = try await mdlSpecItem.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlSpecItem.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/SpecControllers/cntrlSpecItemValue.swift b/Sources/App/Controllers/SpecControllers/cntrlSpecItemValue.swift index 979243e..81255ab 100644 --- a/Sources/App/Controllers/SpecControllers/cntrlSpecItemValue.swift +++ b/Sources/App/Controllers/SpecControllers/cntrlSpecItemValue.swift @@ -12,32 +12,30 @@ struct cntrlSpecItemValue: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("specitemvalues") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlSpecItemValue] { - try await mdlSpecItemValue.query(on: req.db).all() + try await mdlSpecItemValue.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlSpecItemValue{ + return try await mdlSpecItemValue.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlSpecItemValue { let obj = try req.content.decode(mdlSpecItemValue.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlSpecItemValue{ - let obj = try req.content.decode(mdlSpecItemValue.self) - let dbobj = try await mdlSpecItemValue.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlSpecItemValue.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/TemplateControllers/cntrlTemplate.swift b/Sources/App/Controllers/TemplateControllers/cntrlTemplate.swift index f884a71..fe65079 100644 --- a/Sources/App/Controllers/TemplateControllers/cntrlTemplate.swift +++ b/Sources/App/Controllers/TemplateControllers/cntrlTemplate.swift @@ -12,32 +12,30 @@ struct cntrlTemplate: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("templates") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlTemplate] { - try await mdlTemplate.query(on: req.db).all() + try await mdlTemplate.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlTemplate{ + return try await mdlTemplate.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlTemplate { let obj = try req.content.decode(mdlTemplate.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlTemplate{ - let obj = try req.content.decode(mdlTemplate.self) - let dbobj = try await mdlTemplate.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlTemplate.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/TemplateControllers/cntrlTemplateCategory.swift b/Sources/App/Controllers/TemplateControllers/cntrlTemplateCategory.swift index b3abc9c..d62882f 100644 --- a/Sources/App/Controllers/TemplateControllers/cntrlTemplateCategory.swift +++ b/Sources/App/Controllers/TemplateControllers/cntrlTemplateCategory.swift @@ -12,32 +12,30 @@ struct cntrlTemplateCategory: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("templatecategories") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlTemplateCategory] { - try await mdlTemplateCategory.query(on: req.db).all() + try await mdlTemplateCategory.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlTemplateCategory{ + return try await mdlTemplateCategory.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlTemplateCategory { let obj = try req.content.decode(mdlTemplateCategory.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlTemplateCategory{ - let obj = try req.content.decode(mdlTemplateCategory.self) - let dbobj = try await mdlTemplateCategory.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlTemplateCategory.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/TemplateControllers/cntrlTemplateItemSpec.swift b/Sources/App/Controllers/TemplateControllers/cntrlTemplateItemSpec.swift index e999ec0..dee5363 100644 --- a/Sources/App/Controllers/TemplateControllers/cntrlTemplateItemSpec.swift +++ b/Sources/App/Controllers/TemplateControllers/cntrlTemplateItemSpec.swift @@ -12,32 +12,30 @@ struct cntrlTemplateItemSpec: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("templateitemspecs") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlTemplateItemSpec] { - try await mdlTemplateItemSpec.query(on: req.db).all() + try await mdlTemplateItemSpec.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlTemplateItemSpec{ + return try await mdlTemplateItemSpec.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlTemplateItemSpec { let obj = try req.content.decode(mdlTemplateItemSpec.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlTemplateItemSpec{ - let obj = try req.content.decode(mdlTemplateItemSpec.self) - let dbobj = try await mdlTemplateItemSpec.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlTemplateItemSpec.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/Attachments/cntrlWorkOrderAttachment.swift b/Sources/App/Controllers/WorkOrderControllers/Attachments/cntrlWorkOrderAttachment.swift index d5603ed..5894edf 100644 --- a/Sources/App/Controllers/WorkOrderControllers/Attachments/cntrlWorkOrderAttachment.swift +++ b/Sources/App/Controllers/WorkOrderControllers/Attachments/cntrlWorkOrderAttachment.swift @@ -12,32 +12,30 @@ struct cntrlWorkOrderAttachment: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("workorderattachments") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlWorkOrderAttachment] { - try await mdlWorkOrderAttachment.query(on: req.db).all() + try await mdlWorkOrderAttachment.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlWorkOrderAttachment{ + return try await mdlWorkOrderAttachment.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlWorkOrderAttachment { let obj = try req.content.decode(mdlWorkOrderAttachment.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlWorkOrderAttachment{ - let obj = try req.content.decode(mdlWorkOrderAttachment.self) - let dbobj = try await mdlWorkOrderAttachment.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlWorkOrderAttachment.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/Consumptions/cntrlConsumption.swift b/Sources/App/Controllers/WorkOrderControllers/Consumptions/cntrlConsumption.swift index 2d55ebf..652c11d 100644 --- a/Sources/App/Controllers/WorkOrderControllers/Consumptions/cntrlConsumption.swift +++ b/Sources/App/Controllers/WorkOrderControllers/Consumptions/cntrlConsumption.swift @@ -12,32 +12,30 @@ struct cntrlConsumption: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("consumptions") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlConsumption] { - try await mdlConsumption.query(on: req.db).all() + try await mdlConsumption.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlConsumption{ + return try await mdlConsumption.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlConsumption { let obj = try req.content.decode(mdlConsumption.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlConsumption{ - let obj = try req.content.decode(mdlConsumption.self) - let dbobj = try await mdlConsumption.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlConsumption.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspection.swift b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspection.swift index 1c51b6b..c04777f 100644 --- a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspection.swift +++ b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspection.swift @@ -12,32 +12,30 @@ struct cntrlInspection: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("inspections") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlInspection] { - try await mdlInspection.query(on: req.db).all() + try await mdlInspection.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlInspection{ + return try await mdlInspection.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlInspection { let obj = try req.content.decode(mdlInspection.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlInspection{ - let obj = try req.content.decode(mdlInspection.self) - let dbobj = try await mdlInspection.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlInspection.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionCategory.swift b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionCategory.swift index bac9665..672585b 100644 --- a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionCategory.swift +++ b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionCategory.swift @@ -12,32 +12,30 @@ struct cntrlInspectionCategory: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("inspectioncategories") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlInspectionCategory] { - try await mdlInspectionCategory.query(on: req.db).all() + return try await mdlInspectionCategory.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlInspectionCategory{ + return try await mdlInspectionCategory.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlInspectionCategory { let obj = try req.content.decode(mdlInspectionCategory.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlInspectionCategory{ - let obj = try req.content.decode(mdlInspectionCategory.self) - let dbobj = try await mdlInspectionCategory.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlInspectionCategory.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItem.swift b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItem.swift index 341378a..12f3b59 100644 --- a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItem.swift +++ b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItem.swift @@ -12,32 +12,30 @@ struct cntrlInspectionItem: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("inspectionitems") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlInspectionItem] { - try await mdlInspectionItem.query(on: req.db).all() + try await mdlInspectionItem.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlInspectionItem{ + return try await mdlInspectionItem.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlInspectionItem { let obj = try req.content.decode(mdlInspectionItem.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlInspectionItem{ - let obj = try req.content.decode(mdlInspectionItem.self) - let dbobj = try await mdlInspectionItem.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlInspectionItem.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemResponse.swift b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemResponse.swift index 5d9abd6..e1a01e3 100644 --- a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemResponse.swift +++ b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemResponse.swift @@ -12,32 +12,30 @@ struct cntrlInspectionItemResponse: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("inspectionitemresponses") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlInspectionItemResponse] { - try await mdlInspectionItemResponse.query(on: req.db).all() + try await mdlInspectionItemResponse.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlInspectionItemResponse{ + return try await mdlInspectionItemResponse.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlInspectionItemResponse { let obj = try req.content.decode(mdlInspectionItemResponse.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlInspectionItemResponse{ - let obj = try req.content.decode(mdlInspectionItemResponse.self) - let dbobj = try await mdlInspectionItemResponse.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlInspectionItemResponse.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpec.swift b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpec.swift index da611c3..b52addc 100644 --- a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpec.swift +++ b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpec.swift @@ -12,32 +12,30 @@ struct cntrlInspectionItemSpec: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("inspectionitemspecs") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlInspectionItemSpec] { - try await mdlInspectionItemSpec.query(on: req.db).all() + try await mdlInspectionItemSpec.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlInspectionItemSpec{ + return try await mdlInspectionItemSpec.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlInspectionItemSpec { let obj = try req.content.decode(mdlInspectionItemSpec.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlInspectionItemSpec{ - let obj = try req.content.decode(mdlInspectionItemSpec.self) - let dbobj = try await mdlInspectionItemSpec.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlInspectionItemSpec.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItem.swift b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItem.swift index 8599391..2354746 100644 --- a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItem.swift +++ b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItem.swift @@ -12,32 +12,30 @@ struct cntrlInspectionItemSpecItem: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("inspectionitemspecitems") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlInspectionItemSpecItem] { - try await mdlInspectionItemSpecItem.query(on: req.db).all() + try await mdlInspectionItemSpecItem.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlInspectionItemSpecItem{ + return try await mdlInspectionItemSpecItem.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlInspectionItemSpecItem { let obj = try req.content.decode(mdlInspectionItemSpecItem.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlInspectionItemSpecItem{ - let obj = try req.content.decode(mdlInspectionItemSpecItem.self) - let dbobj = try await mdlInspectionItemSpecItem.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlInspectionItemSpecItem.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItemTest.swift b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItemTest.swift index f2387c5..41239b8 100644 --- a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItemTest.swift +++ b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItemTest.swift @@ -12,32 +12,30 @@ struct cntrlInspectionItemSpecItemTest: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("inspectionitemspecitemtests") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlInspectionItemSpecItemTest] { - try await mdlInspectionItemSpecItemTest.query(on: req.db).all() + try await mdlInspectionItemSpecItemTest.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlInspectionItemSpecItemTest{ + return try await mdlInspectionItemSpecItemTest.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlInspectionItemSpecItemTest { let obj = try req.content.decode(mdlInspectionItemSpecItemTest.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlInspectionItemSpecItemTest{ - let obj = try req.content.decode(mdlInspectionItemSpecItemTest.self) - let dbobj = try await mdlInspectionItemSpecItemTest.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlInspectionItemSpecItemTest.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItemValue.swift b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItemValue.swift index 0be63ec..26312ba 100644 --- a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItemValue.swift +++ b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionItemSpecItemValue.swift @@ -12,32 +12,30 @@ struct cntrlInspectionItemSpecItemValue: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("inspectionitemspecitemvalues") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlInspectionItemSpecItemValue] { - try await mdlInspectionItemSpecItemValue.query(on: req.db).all() + try await mdlInspectionItemSpecItemValue.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlInspectionItemSpecItemValue{ + return try await mdlInspectionItemSpecItemValue.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlInspectionItemSpecItemValue { let obj = try req.content.decode(mdlInspectionItemSpecItemValue.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlInspectionItemSpecItemValue{ - let obj = try req.content.decode(mdlInspectionItemSpecItemValue.self) - let dbobj = try await mdlInspectionItemSpecItemValue.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlInspectionItemSpecItemValue.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionLevel.swift b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionLevel.swift index 8a77c6e..bd5af64 100644 --- a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionLevel.swift +++ b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionLevel.swift @@ -12,32 +12,30 @@ struct cntrlInspectionLevel: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("inspectionlevels") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlInspectionLevel] { - try await mdlInspectionLevel.query(on: req.db).all() + try await mdlInspectionLevel.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlInspectionLevel{ + return try await mdlInspectionLevel.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlInspectionLevel { let obj = try req.content.decode(mdlInspectionLevel.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlInspectionLevel{ - let obj = try req.content.decode(mdlInspectionLevel.self) - let dbobj = try await mdlInspectionLevel.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlInspectionLevel.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionType.swift b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionType.swift index aa8324e..a3ffa27 100644 --- a/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionType.swift +++ b/Sources/App/Controllers/WorkOrderControllers/Inspections/cntrlInspectionType.swift @@ -12,32 +12,30 @@ struct cntrlInspectionType: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("inspectiontypes") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlInspectionType] { - try await mdlInspectionType.query(on: req.db).all() + try await mdlInspectionType.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlInspectionType{ + return try await mdlInspectionType.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlInspectionType { let obj = try req.content.decode(mdlInspectionType.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlInspectionType{ - let obj = try req.content.decode(mdlInspectionType.self) - let dbobj = try await mdlInspectionType.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlInspectionType.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/Notes/cntrlNote.swift b/Sources/App/Controllers/WorkOrderControllers/Notes/cntrlNote.swift index 762d179..66549e5 100644 --- a/Sources/App/Controllers/WorkOrderControllers/Notes/cntrlNote.swift +++ b/Sources/App/Controllers/WorkOrderControllers/Notes/cntrlNote.swift @@ -12,32 +12,30 @@ struct cntrlNote: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("notes") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlNote] { - try await mdlNote.query(on: req.db).all() + try await mdlNote.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlNote{ + return try await mdlNote.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlNote { let obj = try req.content.decode(mdlNote.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlNote{ - let obj = try req.content.decode(mdlNote.self) - let dbobj = try await mdlNote.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlNote.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/Parts/cntrlWorkOrderPart.swift b/Sources/App/Controllers/WorkOrderControllers/Parts/cntrlWorkOrderPart.swift index ea61eec..02138b8 100644 --- a/Sources/App/Controllers/WorkOrderControllers/Parts/cntrlWorkOrderPart.swift +++ b/Sources/App/Controllers/WorkOrderControllers/Parts/cntrlWorkOrderPart.swift @@ -12,32 +12,30 @@ struct cntrlWorkOrderPart: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("workorderparts") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlWorkOrderPart] { - try await mdlWorkOrderPart.query(on: req.db).all() + try await mdlWorkOrderPart.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlWorkOrderPart{ + return try await mdlWorkOrderPart.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlWorkOrderPart { let obj = try req.content.decode(mdlWorkOrderPart.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlWorkOrderPart{ - let obj = try req.content.decode(mdlWorkOrderPart.self) - let dbobj = try await mdlWorkOrderPart.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlWorkOrderPart.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/SignatureControllers/cntrlSignature.swift b/Sources/App/Controllers/WorkOrderControllers/SignatureControllers/cntrlSignature.swift index a5a8be8..b42b41e 100644 --- a/Sources/App/Controllers/WorkOrderControllers/SignatureControllers/cntrlSignature.swift +++ b/Sources/App/Controllers/WorkOrderControllers/SignatureControllers/cntrlSignature.swift @@ -12,32 +12,30 @@ struct cntrlSignature: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("signatures") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlSignature] { - try await mdlSignature.query(on: req.db).all() + try await mdlSignature.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlSignature{ + return try await mdlSignature.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlSignature { let obj = try req.content.decode(mdlSignature.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlSignature{ - let obj = try req.content.decode(mdlSignature.self) - let dbobj = try await mdlSignature.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlSignature.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrder.swift b/Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrder.swift index bf04d6e..e5d1cd4 100644 --- a/Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrder.swift +++ b/Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrder.swift @@ -12,32 +12,30 @@ struct cntrlWorkOrder: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("workorders") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlWorkOrder] { - try await mdlWorkOrder.query(on: req.db).all() + try await mdlWorkOrder.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlWorkOrder{ + return try await mdlWorkOrder.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlWorkOrder { let obj = try req.content.decode(mdlWorkOrder.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlWorkOrder{ - let obj = try req.content.decode(mdlWorkOrder.self) - let dbobj = try await mdlWorkOrder.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlWorkOrder.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrderFlow.swift b/Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrderFlow.swift index cd2e216..760c884 100644 --- a/Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrderFlow.swift +++ b/Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrderFlow.swift @@ -12,32 +12,30 @@ struct cntrlWorkorderFlow: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("workorderflows") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlWorkOrderFlow] { - try await mdlWorkOrderFlow.query(on: req.db).all() + try await mdlWorkOrderFlow.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlWorkOrderFlow{ + return try await mdlWorkOrderFlow.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlWorkOrderFlow { let obj = try req.content.decode(mdlWorkOrderFlow.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlWorkOrderFlow{ - let obj = try req.content.decode(mdlWorkOrderFlow.self) - let dbobj = try await mdlWorkOrderFlow.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlWorkOrderFlow.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrderSegment.swift b/Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrderSegment.swift index 34dfcdc..d50a229 100644 --- a/Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrderSegment.swift +++ b/Sources/App/Controllers/WorkOrderControllers/cntrlWorkOrderSegment.swift @@ -12,32 +12,30 @@ struct cntrlWorkOrderSegment: RouteCollection { func boot(routes: RoutesBuilder) throws { let rts = routes.grouped("workordersegments") rts.get(use: index) + rts.get(":x", use: read) rts.post(use: create) - rts.put(use: update) - rts.group(":id") { rt in + rts.group(":x") { rt in rts.delete(use: delete) } + ///Add custom routes here } func index(req: Request) async throws -> [mdlWorkOrderSegment] { - try await mdlWorkOrderSegment.query(on: req.db).all() + try await mdlWorkOrderSegment.ObjQuery(req: req).all() + } + + func read(req:Request) async throws -> mdlWorkOrderSegment{ + return try await mdlWorkOrderSegment.ObjQuery(req: req).first()! } func create(req: Request) async throws -> mdlWorkOrderSegment { let obj = try req.content.decode(mdlWorkOrderSegment.self) + if(obj.id != nil){ + obj._$idExists = true + } try await obj.save(on: req.db) return obj } - func update(req: Request) async throws -> mdlWorkOrderSegment{ - let obj = try req.content.decode(mdlWorkOrderSegment.self) - let dbobj = try await mdlWorkOrderSegment.query(on: req.db).filter(\.$id == obj.id!).first()! - - dbobj.updatedate = Date() - dbobj.updateuserid = -1 - try await dbobj.update(on: req.db) - return dbobj - - } func delete(req: Request) async throws -> HTTPStatus { guard let obj = try await mdlWorkOrderSegment.find(req.parameters.get("id"), on: req.db) else { diff --git a/Sources/App/Models/AuthTables/mdlRole.swift b/Sources/App/Models/AuthTables/mdlRole.swift index b01c592..7a3da1f 100644 --- a/Sources/App/Models/AuthTables/mdlRole.swift +++ b/Sources/App/Models/AuthTables/mdlRole.swift @@ -86,6 +86,37 @@ extension mdlRole{ } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlRole.query(on: req.db) + .with(\.$users) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/AuthTables/mdlSegment.swift b/Sources/App/Models/AuthTables/mdlSegment.swift index 28ed1a3..d46168f 100644 --- a/Sources/App/Models/AuthTables/mdlSegment.swift +++ b/Sources/App/Models/AuthTables/mdlSegment.swift @@ -78,6 +78,36 @@ extension mdlSegment{ mdlSegment.query(on: database).delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlSegment.query(on: req.db) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/AuthTables/mdlUser.swift b/Sources/App/Models/AuthTables/mdlUser.swift index 811e590..b3329d3 100644 --- a/Sources/App/Models/AuthTables/mdlUser.swift +++ b/Sources/App/Models/AuthTables/mdlUser.swift @@ -84,7 +84,41 @@ extension mdlUser{ try await database.schema("user").delete() } } - + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlUser.query(on: req.db) + .with(\.$roles) + .with(\.$division) + .with(\.$location) + .with(\.$gate) + .with(\.$workorders) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/ChildTables/mdlResponseType.swift b/Sources/App/Models/BaseTables/ChildTables/mdlResponseType.swift index e238884..e70be73 100644 --- a/Sources/App/Models/BaseTables/ChildTables/mdlResponseType.swift +++ b/Sources/App/Models/BaseTables/ChildTables/mdlResponseType.swift @@ -77,6 +77,38 @@ extension mdlResponseType{ .update() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlResponseType.query(on: req.db) + .with(\.$repairtype) + .with(\.$responses) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/ChildTables/mdlUnit.swift b/Sources/App/Models/BaseTables/ChildTables/mdlUnit.swift index bd0e2e4..6b2e4fc 100644 --- a/Sources/App/Models/BaseTables/ChildTables/mdlUnit.swift +++ b/Sources/App/Models/BaseTables/ChildTables/mdlUnit.swift @@ -61,6 +61,37 @@ extension mdlUnit{ try await database.schema("unit").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlUnit.query(on: req.db) + .with(\.$datatype) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlCategory.swift b/Sources/App/Models/BaseTables/mdlCategory.swift index 8002fae..99a4c69 100644 --- a/Sources/App/Models/BaseTables/mdlCategory.swift +++ b/Sources/App/Models/BaseTables/mdlCategory.swift @@ -58,4 +58,36 @@ extension mdlCategory{ try await database.schema("category").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlCategory.query(on: req.db) + .with(\.$categories) + .with(\.$templatecategories) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlComparisonType.swift b/Sources/App/Models/BaseTables/mdlComparisonType.swift index 7faa68c..71d25f2 100644 --- a/Sources/App/Models/BaseTables/mdlComparisonType.swift +++ b/Sources/App/Models/BaseTables/mdlComparisonType.swift @@ -75,5 +75,35 @@ extension mdlComparisonType{ } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlComparisonType.query(on: req.db) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlContactType.swift b/Sources/App/Models/BaseTables/mdlContactType.swift index 7bcfb77..6821cf3 100644 --- a/Sources/App/Models/BaseTables/mdlContactType.swift +++ b/Sources/App/Models/BaseTables/mdlContactType.swift @@ -75,6 +75,36 @@ extension mdlContactType{ mdlContactType.query(on: database).delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlContactType.query(on: req.db) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlDataType.swift b/Sources/App/Models/BaseTables/mdlDataType.swift index c14a174..654819f 100644 --- a/Sources/App/Models/BaseTables/mdlDataType.swift +++ b/Sources/App/Models/BaseTables/mdlDataType.swift @@ -76,4 +76,35 @@ extension mdlDataType{ mdlDataType.query(on: database).delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlDataType.query(on: req.db) + .with(\.$units) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlDivision.swift b/Sources/App/Models/BaseTables/mdlDivision.swift index d626fb6..5d04402 100644 --- a/Sources/App/Models/BaseTables/mdlDivision.swift +++ b/Sources/App/Models/BaseTables/mdlDivision.swift @@ -60,6 +60,37 @@ extension mdlDivision{ try await database.schema("division").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlDivision.query(on: req.db) + .with(\.$users) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlEquipmentType.swift b/Sources/App/Models/BaseTables/mdlEquipmentType.swift index 87aaade..b6f4c4a 100644 --- a/Sources/App/Models/BaseTables/mdlEquipmentType.swift +++ b/Sources/App/Models/BaseTables/mdlEquipmentType.swift @@ -71,4 +71,34 @@ extension mdlEquipmentType{ mdlEquipmentType.query(on: database).delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlEquipmentType.query(on: req.db) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlFluid.swift b/Sources/App/Models/BaseTables/mdlFluid.swift index 86c101e..26f626f 100644 --- a/Sources/App/Models/BaseTables/mdlFluid.swift +++ b/Sources/App/Models/BaseTables/mdlFluid.swift @@ -60,6 +60,36 @@ extension mdlFluid{ try await database.schema("fluid").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlFluid.query(on: req.db) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlFuel.swift b/Sources/App/Models/BaseTables/mdlFuel.swift index 67e8a90..744fcd3 100644 --- a/Sources/App/Models/BaseTables/mdlFuel.swift +++ b/Sources/App/Models/BaseTables/mdlFuel.swift @@ -62,6 +62,37 @@ extension mdlFuel{ try await database.schema("fuel").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlFuel.query(on: req.db) + .with(\.$workorders) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlGate.swift b/Sources/App/Models/BaseTables/mdlGate.swift index c07ec71..ce5982b 100644 --- a/Sources/App/Models/BaseTables/mdlGate.swift +++ b/Sources/App/Models/BaseTables/mdlGate.swift @@ -59,6 +59,37 @@ try await database.schema("gate").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlGate.query(on: req.db) + .with(\.$users) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlIncompleteReason.swift b/Sources/App/Models/BaseTables/mdlIncompleteReason.swift index d959135..ffbc412 100644 --- a/Sources/App/Models/BaseTables/mdlIncompleteReason.swift +++ b/Sources/App/Models/BaseTables/mdlIncompleteReason.swift @@ -59,6 +59,37 @@ extension mdlIncompleteReason{ try await database.schema("incompleteReason").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlIncompleteReason.query(on: req.db) + .with(\.$workorders) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlInputType.swift b/Sources/App/Models/BaseTables/mdlInputType.swift index 55a2f8f..34b0e9a 100644 --- a/Sources/App/Models/BaseTables/mdlInputType.swift +++ b/Sources/App/Models/BaseTables/mdlInputType.swift @@ -75,4 +75,35 @@ extension mdlInputType{ } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlInputType.query(on: req.db) + .with(\.$inspectionitems) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlJobSite.swift b/Sources/App/Models/BaseTables/mdlJobSite.swift index 0f496ff..263380a 100644 --- a/Sources/App/Models/BaseTables/mdlJobSite.swift +++ b/Sources/App/Models/BaseTables/mdlJobSite.swift @@ -74,5 +74,35 @@ extension mdlJobSite{ mdlJobSite.query(on: database).delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlJobSite.query(on: req.db) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlLevel.swift b/Sources/App/Models/BaseTables/mdlLevel.swift index 7a065c1..6bad3d6 100644 --- a/Sources/App/Models/BaseTables/mdlLevel.swift +++ b/Sources/App/Models/BaseTables/mdlLevel.swift @@ -60,6 +60,36 @@ extension mdlLevel{ try await database.schema("level").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlLevel.query(on: req.db) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlLocation.swift b/Sources/App/Models/BaseTables/mdlLocation.swift index d385a68..d73ba8d 100644 --- a/Sources/App/Models/BaseTables/mdlLocation.swift +++ b/Sources/App/Models/BaseTables/mdlLocation.swift @@ -112,6 +112,40 @@ extension mdlLocation{ .update() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlLocation.query(on: req.db) + .with(\.$state) + .with(\.$unit) + .with(\.$users) + .with(\.$labsetting) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlNoteType.swift b/Sources/App/Models/BaseTables/mdlNoteType.swift index 1fa1088..5eec74d 100644 --- a/Sources/App/Models/BaseTables/mdlNoteType.swift +++ b/Sources/App/Models/BaseTables/mdlNoteType.swift @@ -59,6 +59,37 @@ extension mdlNoteType{ try await database.schema("noteType").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlNoteType.query(on: req.db) + .with(\.$notes) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlPart.swift b/Sources/App/Models/BaseTables/mdlPart.swift index 323157a..b334ffc 100644 --- a/Sources/App/Models/BaseTables/mdlPart.swift +++ b/Sources/App/Models/BaseTables/mdlPart.swift @@ -57,6 +57,37 @@ extension mdlPart{ try await database.schema("part").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlPart.query(on: req.db) +// .with(\.$<#parent/children#>) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlPriority.swift b/Sources/App/Models/BaseTables/mdlPriority.swift index b36159a..1e6b0a8 100644 --- a/Sources/App/Models/BaseTables/mdlPriority.swift +++ b/Sources/App/Models/BaseTables/mdlPriority.swift @@ -76,6 +76,37 @@ extension mdlPriority{ } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlPriority.query(on: req.db) + .with(\.$workorders) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlReason.swift b/Sources/App/Models/BaseTables/mdlReason.swift index 7faf0a5..102d9bd 100644 --- a/Sources/App/Models/BaseTables/mdlReason.swift +++ b/Sources/App/Models/BaseTables/mdlReason.swift @@ -59,6 +59,37 @@ extension mdlReason{ try await database.schema("reason").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlReason.query(on: req.db) + .with(\.$workorders) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlRepairType.swift b/Sources/App/Models/BaseTables/mdlRepairType.swift index 2717b79..9d8f5a2 100644 --- a/Sources/App/Models/BaseTables/mdlRepairType.swift +++ b/Sources/App/Models/BaseTables/mdlRepairType.swift @@ -79,6 +79,37 @@ extension mdlRepairType{ } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlRepairType.query(on: req.db) + .with(\.$units) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlSMSCCode.swift b/Sources/App/Models/BaseTables/mdlSMSCCode.swift index 8762925..1a1d132 100644 --- a/Sources/App/Models/BaseTables/mdlSMSCCode.swift +++ b/Sources/App/Models/BaseTables/mdlSMSCCode.swift @@ -57,6 +57,37 @@ extension mdlSMSCCode{ try await database.schema("smscCode").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlSMSCCode.query(on: req.db) +// .with(\.$<#parent/children#>) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlSignatureType.swift b/Sources/App/Models/BaseTables/mdlSignatureType.swift index 1816559..55132ad 100644 --- a/Sources/App/Models/BaseTables/mdlSignatureType.swift +++ b/Sources/App/Models/BaseTables/mdlSignatureType.swift @@ -72,6 +72,37 @@ extension mdlSignatureType{ .update() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlSignatureType.query(on: req.db) +// .with(\.$<#parent/children#>) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlState.swift b/Sources/App/Models/BaseTables/mdlState.swift index c0ece45..bd0f492 100644 --- a/Sources/App/Models/BaseTables/mdlState.swift +++ b/Sources/App/Models/BaseTables/mdlState.swift @@ -124,6 +124,37 @@ extension mdlState{ } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlState.query(on: req.db) + .with(\.$locations) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlStatus.swift b/Sources/App/Models/BaseTables/mdlStatus.swift index 39df050..e5c00df 100644 --- a/Sources/App/Models/BaseTables/mdlStatus.swift +++ b/Sources/App/Models/BaseTables/mdlStatus.swift @@ -80,6 +80,37 @@ extension mdlStatus{ } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlStatus.query(on: req.db) + .with(\.$workorders) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlValueType.swift b/Sources/App/Models/BaseTables/mdlValueType.swift index 8daab34..5e49006 100644 --- a/Sources/App/Models/BaseTables/mdlValueType.swift +++ b/Sources/App/Models/BaseTables/mdlValueType.swift @@ -74,6 +74,37 @@ extension mdlValueType{ } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlValueType.query(on: req.db) +// .with(\.$<#parent/children#>) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/BaseTables/mdlViscosity.swift b/Sources/App/Models/BaseTables/mdlViscosity.swift index 89ce6e0..068e105 100644 --- a/Sources/App/Models/BaseTables/mdlViscosity.swift +++ b/Sources/App/Models/BaseTables/mdlViscosity.swift @@ -57,6 +57,37 @@ extension mdlViscosity{ try await database.schema("viscosity").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlViscosity.query(on: req.db) +// .with(\.$<#parent/children#>) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/CompartmentModule/mdlCompartment.swift b/Sources/App/Models/CompartmentModule/mdlCompartment.swift index b782578..81e5737 100644 --- a/Sources/App/Models/CompartmentModule/mdlCompartment.swift +++ b/Sources/App/Models/CompartmentModule/mdlCompartment.swift @@ -62,4 +62,35 @@ extension mdlCompartment{ try await database.schema("compartment").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlCompartment.query(on: req.db) +// .with(\.$<#parent/children#>) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/CompartmentModule/mdlCompartmentLocation.swift b/Sources/App/Models/CompartmentModule/mdlCompartmentLocation.swift index 3337fb8..8ea2c1b 100644 --- a/Sources/App/Models/CompartmentModule/mdlCompartmentLocation.swift +++ b/Sources/App/Models/CompartmentModule/mdlCompartmentLocation.swift @@ -61,6 +61,36 @@ extension mdlCompartmentLocation{ try await database.schema("compartmentLocation").delete() } } - + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlCompartmentLocation.query(on: req.db) +// .with(\.$<#parent/children#>) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/CustomerTables/mdlContact.swift b/Sources/App/Models/CustomerTables/mdlContact.swift index 262586c..1007f86 100644 --- a/Sources/App/Models/CustomerTables/mdlContact.swift +++ b/Sources/App/Models/CustomerTables/mdlContact.swift @@ -87,6 +87,37 @@ extension mdlContact{ .update() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlContact.query(on: req.db) + .with(\.$customer) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/CustomerTables/mdlContactInfo.swift b/Sources/App/Models/CustomerTables/mdlContactInfo.swift index 7f21a39..500c3db 100644 --- a/Sources/App/Models/CustomerTables/mdlContactInfo.swift +++ b/Sources/App/Models/CustomerTables/mdlContactInfo.swift @@ -60,6 +60,37 @@ extension mdlContactInfo{ try await database.schema("contactInfo").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlContactInfo.query(on: req.db) + .with(\.$contacttype) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/CustomerTables/mdlCustomer.swift b/Sources/App/Models/CustomerTables/mdlCustomer.swift index da0e26c..bede82c 100644 --- a/Sources/App/Models/CustomerTables/mdlCustomer.swift +++ b/Sources/App/Models/CustomerTables/mdlCustomer.swift @@ -60,6 +60,39 @@ extension mdlCustomer{ try await database.schema("customer").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlCustomer.query(on: req.db) + .with(\.$contacts) + .with(\.$workorders) + .with(\.$templates) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/CustomerTables/mdlEquipment.swift b/Sources/App/Models/CustomerTables/mdlEquipment.swift index 48e1a1c..9c49b4b 100644 --- a/Sources/App/Models/CustomerTables/mdlEquipment.swift +++ b/Sources/App/Models/CustomerTables/mdlEquipment.swift @@ -83,6 +83,43 @@ extension mdlEquipment{ .update() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlEquipment.query(on: req.db) + .with(\.$customer) + .with(\.$model) + .with(\.$equipmenttype) + .with(\.$parent) + .with(\.$properties) + .with(\.$templates) + .with(\.$workorders) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/CustomerTables/mdlMake.swift b/Sources/App/Models/CustomerTables/mdlMake.swift index 3b63975..b09e22c 100644 --- a/Sources/App/Models/CustomerTables/mdlMake.swift +++ b/Sources/App/Models/CustomerTables/mdlMake.swift @@ -58,6 +58,37 @@ extension mdlMake{ try await database.schema("make").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlMake.query(on: req.db) + .with(\.$templates) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/CustomerTables/mdlModel.swift b/Sources/App/Models/CustomerTables/mdlModel.swift index 862ac83..2ab1895 100644 --- a/Sources/App/Models/CustomerTables/mdlModel.swift +++ b/Sources/App/Models/CustomerTables/mdlModel.swift @@ -67,6 +67,39 @@ extension mdlModel{ try await database.schema("model").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlModel.query(on: req.db) + .with(\.$product) + .with(\.$make) + .with(\.$templates) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/CustomerTables/mdlObjectProperty.swift b/Sources/App/Models/CustomerTables/mdlObjectProperty.swift index 4b478c8..6c57025 100644 --- a/Sources/App/Models/CustomerTables/mdlObjectProperty.swift +++ b/Sources/App/Models/CustomerTables/mdlObjectProperty.swift @@ -60,6 +60,37 @@ extension mdlObjProperty{ try await database.schema("objProperty").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlObjProperty.query(on: req.db) + .with(\.$equipment) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/CustomerTables/mdlProduct.swift b/Sources/App/Models/CustomerTables/mdlProduct.swift index cef929d..47f70c5 100644 --- a/Sources/App/Models/CustomerTables/mdlProduct.swift +++ b/Sources/App/Models/CustomerTables/mdlProduct.swift @@ -58,6 +58,37 @@ extension mdlProduct{ try await database.schema("product").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlProduct.query(on: req.db) + .with(\.$templates) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/ItemTables/mdlItem.swift b/Sources/App/Models/ItemTables/mdlItem.swift index 41aca42..a654443 100644 --- a/Sources/App/Models/ItemTables/mdlItem.swift +++ b/Sources/App/Models/ItemTables/mdlItem.swift @@ -59,6 +59,37 @@ extension mdlItem{ try await database.schema("item").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlItem.query(on: req.db) + .with(\.$templateitems) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/ItemTables/mdlItemResponseType.swift b/Sources/App/Models/ItemTables/mdlItemResponseType.swift index d7c9e7f..d5b4362 100644 --- a/Sources/App/Models/ItemTables/mdlItemResponseType.swift +++ b/Sources/App/Models/ItemTables/mdlItemResponseType.swift @@ -57,6 +57,38 @@ extension mdlItemResponseType{ try await database.schema("itemResponseType").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlItemResponseType.query(on: req.db) + .with(\.$item) + .with(\.$responsetype) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/LabTables/mdlLabSetting.swift b/Sources/App/Models/LabTables/mdlLabSetting.swift index d60204f..7dbf1b8 100644 --- a/Sources/App/Models/LabTables/mdlLabSetting.swift +++ b/Sources/App/Models/LabTables/mdlLabSetting.swift @@ -97,6 +97,37 @@ extension mdlLabSetting{ .update() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlLabSetting.query(on: req.db) + .with(\.$location) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/LinkingTables/XFluidViscosity.swift b/Sources/App/Models/LinkingTables/XFluidViscosity.swift index f58cef1..6b630f5 100644 --- a/Sources/App/Models/LinkingTables/XFluidViscosity.swift +++ b/Sources/App/Models/LinkingTables/XFluidViscosity.swift @@ -78,7 +78,38 @@ extension mdlXFluidViscosity{ .update() } } - + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlXFluidViscosity.query(on: req.db) + .with(\.$fluid) + .with(\.$viscosity) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/LinkingTables/XUserRole.swift b/Sources/App/Models/LinkingTables/XUserRole.swift index 3c34cb8..355aa8b 100644 --- a/Sources/App/Models/LinkingTables/XUserRole.swift +++ b/Sources/App/Models/LinkingTables/XUserRole.swift @@ -69,7 +69,38 @@ extension mdlXUserRole{ .update() } } - + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlXUserRole.query(on: req.db) + .with(\.$user) + .with(\.$role) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/LinkingTables/XWorkOrderSegment.swift b/Sources/App/Models/LinkingTables/XWorkOrderSegment.swift index 1e11016..205e4c5 100644 --- a/Sources/App/Models/LinkingTables/XWorkOrderSegment.swift +++ b/Sources/App/Models/LinkingTables/XWorkOrderSegment.swift @@ -73,7 +73,38 @@ extension mdlXWorkOrderSegment{ try await database.schema("xWorkOrderSegment").delete() } } - + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlWorkOrderSegment.query(on: req.db) + .with(\.$workorder) + .with(\.$segment) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/SpecTables/mdlSpec.swift b/Sources/App/Models/SpecTables/mdlSpec.swift index e4e9806..323ba80 100644 --- a/Sources/App/Models/SpecTables/mdlSpec.swift +++ b/Sources/App/Models/SpecTables/mdlSpec.swift @@ -63,6 +63,39 @@ extension mdlSpec{ try await database.schema("spec").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlSpec.query(on: req.db) + .with(\.$item) + .with(\.$specitems) + .with(\.$templatespecs) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/SpecTables/mdlSpecItem.swift b/Sources/App/Models/SpecTables/mdlSpecItem.swift index 77d397d..047071d 100644 --- a/Sources/App/Models/SpecTables/mdlSpecItem.swift +++ b/Sources/App/Models/SpecTables/mdlSpecItem.swift @@ -72,6 +72,40 @@ extension mdlSpecItem{ try await database.schema("specItem").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlSpecItem.query(on: req.db) + .with(\.$spec) + .with(\.$comparisontype) + .with(\.$unit) + .with(\.$values) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/SpecTables/mdlSpecItemValue.swift b/Sources/App/Models/SpecTables/mdlSpecItemValue.swift index 235269b..ede9cdc 100644 --- a/Sources/App/Models/SpecTables/mdlSpecItemValue.swift +++ b/Sources/App/Models/SpecTables/mdlSpecItemValue.swift @@ -90,6 +90,38 @@ extension mdlSpecItemValue{ .update() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlSpecItemValue.query(on: req.db) + .with(\.$specitem) + .with(\.$valuetype) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/TemplateTables/mdlTemplate.swift b/Sources/App/Models/TemplateTables/mdlTemplate.swift index ec37bd1..33b27aa 100644 --- a/Sources/App/Models/TemplateTables/mdlTemplate.swift +++ b/Sources/App/Models/TemplateTables/mdlTemplate.swift @@ -103,5 +103,42 @@ extension mdlTemplate{ .update() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlTemplate.query(on: req.db) + .with(\.$level) + .with(\.$product) + .with(\.$make) + .with(\.$model) + .with(\.$customer) + .with(\.$equipment) + .with(\.$categories) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/TemplateTables/mdlTemplateCategory.swift b/Sources/App/Models/TemplateTables/mdlTemplateCategory.swift index 8e27751..2ef342a 100644 --- a/Sources/App/Models/TemplateTables/mdlTemplateCategory.swift +++ b/Sources/App/Models/TemplateTables/mdlTemplateCategory.swift @@ -64,5 +64,38 @@ extension mdlTemplateCategory{ try await database.schema("templateCategory").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlTemplateCategory.query(on: req.db) + .with(\.$template) + .with(\.$category) + .with(\.$items) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/TemplateTables/mdlTemplateItemSpec.swift b/Sources/App/Models/TemplateTables/mdlTemplateItemSpec.swift index cff12dd..08a8cd4 100644 --- a/Sources/App/Models/TemplateTables/mdlTemplateItemSpec.swift +++ b/Sources/App/Models/TemplateTables/mdlTemplateItemSpec.swift @@ -66,5 +66,38 @@ extension mdlTemplateItemSpec{ try await database.schema("templateItemSpec").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlTemplateItemSpec.query(on: req.db) + .with(\.$templatecategory) + .with(\.$item) + .with(\.$spec) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/Attachments/mdlWorkOrderAttachment.swift b/Sources/App/Models/WorkOrderTables/Attachments/mdlWorkOrderAttachment.swift index 2c13715..438f33f 100644 --- a/Sources/App/Models/WorkOrderTables/Attachments/mdlWorkOrderAttachment.swift +++ b/Sources/App/Models/WorkOrderTables/Attachments/mdlWorkOrderAttachment.swift @@ -54,7 +54,39 @@ extension mdlWorkOrderAttachment{ } func revert(on database: Database) async throws { - try await database.schema("<#schema#>").delete() + try await database.schema("workOrderAttachment").delete() + } + } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlWorkOrderAttachment.query(on: req.db) + .with(\.$workorder) + .with(\.$equipment) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 } } } diff --git a/Sources/App/Models/WorkOrderTables/Consumptions/mdlConsumption.swift b/Sources/App/Models/WorkOrderTables/Consumptions/mdlConsumption.swift index 4c1f7c1..8bb72ef 100644 --- a/Sources/App/Models/WorkOrderTables/Consumptions/mdlConsumption.swift +++ b/Sources/App/Models/WorkOrderTables/Consumptions/mdlConsumption.swift @@ -16,7 +16,7 @@ final class mdlConsumption: Model, Content { @ID(custom: "id", generatedBy: .database) var id: Int? - @Parent(key: "workOrderSegmentId") var segmaent: mdlWorkOrderSegment + @Parent(key: "workOrderSegmentId") var segment: mdlWorkOrderSegment @Parent(key: "fluidId") var fluid: mdlFluid @Parent(key: "viscosityId") var viscosity: mdlViscosity @@ -40,7 +40,7 @@ final class mdlConsumption: Model, Content { updateuserid: Int? = nil ) { self.id = id - self.$segmaent.$id.value = segmentid + self.$segment.$id.value = segmentid self.$fluid.$id.value = fluidid self.$viscosity.$id.value = viscosityid self.quantity = quantity @@ -89,5 +89,38 @@ extension mdlConsumption{ .update() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlConsumption.query(on: req.db) + .with(\.$segment) + .with(\.$fluid) + .with(\.$viscosity) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspection.swift b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspection.swift index 818f832..f0756ff 100644 --- a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspection.swift +++ b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspection.swift @@ -69,5 +69,39 @@ extension mdlInspection{ try await database.schema("inspection").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlInspection.query(on: req.db) + .with(\.$segment) + .with(\.$categories) + .with(\.$level) + .with(\.$notes) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionCategory.swift b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionCategory.swift index aa692b4..699d385 100644 --- a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionCategory.swift +++ b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionCategory.swift @@ -63,5 +63,38 @@ extension mdlInspectionCategory{ try await database.schema("inspectionCategory").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlInspectionCategory.query(on: req.db) + .with(\.$inspection) + .with(\.$category) + .with(\.$inspectionitems) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItem.swift b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItem.swift index d7f3dd0..7496e53 100644 --- a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItem.swift +++ b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItem.swift @@ -109,6 +109,43 @@ extension mdlInspectionItem{ .update() } } - + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlInspectionItem.query(on: req.db) + .with(\.$category) + .with(\.$inputtype) + .with(\.$smsccode) + .with(\.$previousinspectionitem) + .with(\.$previousinspectionitemresponse) + .with(\.$responses) + .with(\.$specs) + .with(\.$notes) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemResponse.swift b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemResponse.swift index 9053453..3c2eaad 100644 --- a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemResponse.swift +++ b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemResponse.swift @@ -70,5 +70,37 @@ extension mdlInspectionItemResponse{ try await database.schema("inspectionItemResponse").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlInspectionItemResponse.query(on: req.db) + .with(\.$inspectionitem) + .with(\.$responsetype) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemSpec.swift b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemSpec.swift index 05b6363..dbee740 100644 --- a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemSpec.swift +++ b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemSpec.swift @@ -62,5 +62,37 @@ extension mdlInspectionItemSpec{ try await database.schema("inspectionItemSpec").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlInspectionItemSpec.query(on: req.db) + .with(\.$items) + .with(\.$inspectionitem) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemSpecItem.swift b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemSpecItem.swift index 2e1e94d..760befe 100644 --- a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemSpecItem.swift +++ b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemSpecItem.swift @@ -83,5 +83,40 @@ extension mdlInspectionItemSpecItem{ try await database.schema("inspectionItemSpecItem").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlInspectionItemSpecItem.query(on: req.db) + .with(\.$inspectionitemspec) + .with(\.$comparisontype) + .with(\.$unit) + .with(\.$tests) + .with(\.$values) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemSpecItemTest.swift b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemSpecItemTest.swift index 001cee0..2af4c1e 100644 --- a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemSpecItemTest.swift +++ b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemSpecItemTest.swift @@ -60,5 +60,36 @@ extension mdlInspectionItemSpecItemTest{ try await database.schema("inspectionItemSpecItemTest").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlInspectionItemSpecItemTest.query(on: req.db) + .with(\.$specitem) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemSpecItemValue.swift b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemSpecItemValue.swift index f82129a..949f33d 100644 --- a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemSpecItemValue.swift +++ b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionItemSpecItemValue.swift @@ -60,5 +60,37 @@ extension mdlInspectionItemSpecItemValue{ try await database.schema("inspectionItemSpecItemValue").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlInspectionItemSpecItemValue.query(on: req.db) + .with(\.$specitem) + .with(\.$valuetype) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionLevel.swift b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionLevel.swift index 6b26933..b7649c8 100644 --- a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionLevel.swift +++ b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionLevel.swift @@ -67,5 +67,38 @@ extension mdlInspectionLevel{ try await database.schema("inspectionLevel").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlInspectionLevel.query(on: req.db) + .with(\.$inspectiontype) + .with(\.$inspections) + .with(\.$templates) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionType.swift b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionType.swift index c8abf90..9c3cc3e 100644 --- a/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionType.swift +++ b/Sources/App/Models/WorkOrderTables/Inspections/mdlInspectionType.swift @@ -65,5 +65,36 @@ extension mdlInspectionType{ try await database.schema("inspectionType").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlInspectionType.query(on: req.db) + .with(\.$inspectionlevels) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/Notes/mdlNote.swift b/Sources/App/Models/WorkOrderTables/Notes/mdlNote.swift index c864c8b..175b714 100644 --- a/Sources/App/Models/WorkOrderTables/Notes/mdlNote.swift +++ b/Sources/App/Models/WorkOrderTables/Notes/mdlNote.swift @@ -89,5 +89,39 @@ extension mdlNote{ .update() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlNote.query(on: req.db) + .with(\.$type) + .with(\.$workorder) + .with(\.$inspection) + .with(\.$item) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/Parts/mdlWorkOrderPart.swift b/Sources/App/Models/WorkOrderTables/Parts/mdlWorkOrderPart.swift index 3ca0f55..258018b 100644 --- a/Sources/App/Models/WorkOrderTables/Parts/mdlWorkOrderPart.swift +++ b/Sources/App/Models/WorkOrderTables/Parts/mdlWorkOrderPart.swift @@ -100,5 +100,37 @@ extension mdlWorkOrderPart{ .update() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlWorkOrderPart.query(on: req.db) + .with(\.$part) + .with(\.$segment) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/Samples/mdlOilSample.swift b/Sources/App/Models/WorkOrderTables/Samples/mdlOilSample.swift index bd48de0..ae8dbac 100644 --- a/Sources/App/Models/WorkOrderTables/Samples/mdlOilSample.swift +++ b/Sources/App/Models/WorkOrderTables/Samples/mdlOilSample.swift @@ -136,4 +136,35 @@ extension mdlOilSample{ .update() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlOilSample.query(on: req.db) + .with(\.$segment) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/Signatures/mdlSignature.swift b/Sources/App/Models/WorkOrderTables/Signatures/mdlSignature.swift index 2718014..a8fda45 100644 --- a/Sources/App/Models/WorkOrderTables/Signatures/mdlSignature.swift +++ b/Sources/App/Models/WorkOrderTables/Signatures/mdlSignature.swift @@ -20,7 +20,7 @@ final class mdlSignature: Model, Content { @Field(key: "type") var type: String @Field(key: "data") var data: Data @Parent(key: "workOrderId") var workorder: mdlWorkOrder - + @Parent(key: "signatureTypeId") var signaturetype: mdlSignatureType @Timestamp(key: "createDate", on: .create) var createdate: Date? @Field(key: "createUserId") var createuserid: Int? @Timestamp(key: "updateDate", on: .update) var updatedate: Date? @@ -65,5 +65,49 @@ extension mdlSignature{ try await database.schema("signature").delete() } } + struct Mode1: AsyncMigration{ + func prepare(on database: Database) async throws { + try await database.schema("signature") + .field("signatureTypeId", .int, .references("signatureType", "id")) + .update() + } + func revert(on database: Database) async throws { + try await database.schema("signature") + .deleteField("signatureTypeId") + .update() + } + } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlSignature.query(on: req.db) + .with(\.$workorder) + .with(\.$signaturetype) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/mdlWorkOrder.swift b/Sources/App/Models/WorkOrderTables/mdlWorkOrder.swift index 0747204..dda9ae7 100644 --- a/Sources/App/Models/WorkOrderTables/mdlWorkOrder.swift +++ b/Sources/App/Models/WorkOrderTables/mdlWorkOrder.swift @@ -34,7 +34,7 @@ final class mdlWorkOrder: Model, Content { @OptionalParent(key: "fuelId") var fuel: mdlFuel? @OptionalParent(key: "workOrderFlowId") var workorderflow: mdlWorkOrderFlow? - @Siblings(through: mdlWorkOrderAttachment.self, from: \.$workorder, to: \.$equipment) var equipments: [mdlEquipment] + @Siblings(through: mdlWorkOrderAttachment.self, from: \.$workorder, to: \.$equipment) var attachments: [mdlEquipment] @Children(for: \.$workorder) var signatures: [mdlSignature] @Children(for: \.$workorder) var notes: [mdlNote] @@ -135,6 +135,48 @@ extension mdlWorkOrder{ .update() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlWorkOrder.query(on: req.db) + .with(\.$customer) + .with(\.$equipment) + .with(\.$status) + .with(\.$priority) + .with(\.$technician) + .with(\.$reason) + .with(\.$incompletereason) + .with(\.$fuel) + .with(\.$workorderflow) + .with(\.$attachments) + .with(\.$signatures) + .with(\.$notes) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/mdlWorkOrderFlow.swift b/Sources/App/Models/WorkOrderTables/mdlWorkOrderFlow.swift index 49262e1..2c09751 100644 --- a/Sources/App/Models/WorkOrderTables/mdlWorkOrderFlow.swift +++ b/Sources/App/Models/WorkOrderTables/mdlWorkOrderFlow.swift @@ -65,5 +65,36 @@ extension mdlWorkOrderFlow{ try await database.schema("workOrderFlow").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlWorkOrderFlow.query(on: req.db) +// .with(\.$<#parent/children#>) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } } diff --git a/Sources/App/Models/WorkOrderTables/mdlWorkOrderSegment.swift b/Sources/App/Models/WorkOrderTables/mdlWorkOrderSegment.swift index f24df34..7887339 100644 --- a/Sources/App/Models/WorkOrderTables/mdlWorkOrderSegment.swift +++ b/Sources/App/Models/WorkOrderTables/mdlWorkOrderSegment.swift @@ -22,6 +22,7 @@ final class mdlWorkOrderSegment: Model, Content { @Children(for: \.$segment) var parts: [mdlWorkOrderPart] @Children(for: \.$segment) var inspections: [mdlInspection] @Children(for: \.$segment) var samples: [mdlOilSample] + @Children(for: \.$segment) var consumptions: [mdlConsumption] @Timestamp(key: "createDate", on: .create) var createdate: Date? @Field(key: "createUserId") var createuserid: Int? @@ -61,5 +62,39 @@ extension mdlWorkOrderSegment{ try await database.schema("workOrderSegment").delete() } } + public static func ObjQuery(req: Request) async throws -> QueryBuilder{ + + let query = mdlWorkOrderSegment.query(on: req.db) + .with(\.$parts) + .with(\.$inspections) + .with(\.$samples) + .with(\.$consumptions) + + if let x = req.parameters.get("x"){ + let dataQuery = req.parameters.get("x") + let decryptedString = try CustomCrypto.DecryptString(input: dataQuery!) + let x = decryptedString.components(separatedBy: ":") + ///This call is the standard get by id call + if (x.count == 1){ + let id = Int(x[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 + } + } }