| @@ -2,8 +2,9 @@ window.onload = function() { | |||
| //<editor-fold desc="Changeable Configuration Block"> | |||
| // the following lines will be replaced by docker/configurator, when it runs in a docker-container | |||
| window.ui = SwaggerUIBundle({ | |||
| url: "https://petstore.swagger.io/v2/swagger.json", | |||
| var jsonURL = document.location.origin + "/Swagger/swagger.json"; | |||
| window.ui = SwaggerUIBundle({ | |||
| url: "http://localhost:3003/api/v2.0/swagger.json", | |||
| dom_id: '#swagger-ui', | |||
| deepLinking: true, | |||
| presets: [ | |||
| @@ -8,6 +8,8 @@ | |||
| import Fluent | |||
| import Vapor | |||
| import Crypto | |||
| import SwiftOpenAPI | |||
| import VaporToOpenAPI | |||
| @@ -16,7 +18,13 @@ struct cntrlUser: RouteCollection { | |||
| let rts = routes.grouped("users") | |||
| rts.get(use: index) | |||
| rts.get("login", ":x", use: login) | |||
| rts.get(":x", use: read) | |||
| rts.get(":x", use: read).openAPI( | |||
| summary: "Create User", | |||
| description: "Create a new user with the provided data", | |||
| body: .type(mdlUser.self), | |||
| response: .type(mdlUser.self) | |||
| ) | |||
| rts.post(use: create) | |||
| rts.delete(":x", use: delete) | |||
| } | |||
| @@ -40,6 +48,7 @@ struct cntrlUser: RouteCollection { | |||
| } | |||
| return response | |||
| } | |||
| func read(req:Request) async throws -> Response{ | |||
| guard let obj = try? await mdlUser.ObjQuery(req: req).first() else{ | |||
| @@ -22,7 +22,7 @@ struct cntrlEquipment: RouteCollection { | |||
| } | |||
| func index(req: Request) async throws -> Response { | |||
| guard let obj = try? await mdlEquipment.ObjQuery(req: req).all() else { | |||
| guard let obj = try? await mdlEquipment.ObjQuery(req: req).paginate(for: req) else { | |||
| throw Abort(.badGateway, reason: "Something went wrong with this api.") | |||
| } | |||
| guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{ | |||
| @@ -22,7 +22,9 @@ struct cntrlWorkOrder: RouteCollection { | |||
| } | |||
| func index(req: Request) async throws -> Response { | |||
| guard let obj = try? await mdlWorkOrder.ObjQuery(req: req).all() else { | |||
| //let obj = try await mdlWorkOrder.query(on: req.db).all() | |||
| //let obj = try await mdlWorkOrder.ObjQuery(req: req).paginate(for: req) | |||
| guard let obj = try? await mdlWorkOrder.ObjQuery(req: req).paginate(for: req) else { | |||
| throw Abort(.badGateway, reason: "Something went wrong with this api.") | |||
| } | |||
| guard let response = try? await obj.encodeResponse(status: .ok, for: req) else{ | |||
| @@ -20,6 +20,8 @@ final class mdlSegment: Model, Content { | |||
| @Field(key: "description") var description: String? | |||
| @Field(key: "isActive") var isactive: Bool? | |||
| @Children(for: \.$segment) var workordersegments: [mdlWorkOrderSegment] | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @Field(key: "createUserId") var createuserid: Int? | |||
| @Timestamp(key: "updateDate", on: .update) var updatedate: Date? | |||
| @@ -19,6 +19,8 @@ final class mdlContactType: Model, Content { | |||
| @Field(key: "description") var description: String? | |||
| @Field(key: "isActive") var isactive: Bool? | |||
| @Children(for: \.$contacttype) var info: [mdlContactInfo] | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @Field(key: "createUserId") var createuserid: Int? | |||
| @Timestamp(key: "updateDate", on: .update) var updatedate: Date? | |||
| @@ -18,6 +18,9 @@ | |||
| @Field(key: "name") var name: String? | |||
| @Field(key: "description") var description: String? | |||
| @Field(key: "isActive") var isactive: Bool? | |||
| @Field(key: "sortOrder") var sortorder: Int? | |||
| @Parent(key: "locationId") var location: mdlLocation | |||
| @Children(for: \.$gate) var users: [mdlUser] | |||
| @@ -28,12 +31,15 @@ | |||
| init() { } | |||
| init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { | |||
| init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = nil, sortorder: Int? = 0, createuserid: Int? = nil, updateuserid: Int? = nil, locationid: Int) { | |||
| self.id = id | |||
| self.name = name | |||
| self.description = description | |||
| self.isactive = isactive | |||
| self.sortorder = sortorder | |||
| self.$location.$id.value = locationid | |||
| self.createuserid = createuserid | |||
| self.updateuserid = updateuserid | |||
| @@ -59,6 +65,20 @@ | |||
| try await database.schema("gate").delete() | |||
| } | |||
| } | |||
| struct Mod1: AsyncMigration{ | |||
| func prepare(on database: Database) async throws { | |||
| try await database.schema("gate") | |||
| .field("locationId", .int, .references("location", "id")) | |||
| .field("sortOrder", .int) | |||
| .update() | |||
| } | |||
| func revert(on database: Database) async throws { | |||
| try await database.schema("gate") | |||
| .deleteField("locationId") | |||
| .deleteField("sortOrder") | |||
| .update() | |||
| } | |||
| } | |||
| public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlGate>{ | |||
| let query = mdlGate.query(on: req.db) | |||
| @@ -57,6 +57,18 @@ extension mdlPart{ | |||
| try await database.schema("part").delete() | |||
| } | |||
| } | |||
| struct Mod1: AsyncMigration{ | |||
| func prepare(on database: Database) async throws { | |||
| try await database.schema("part") | |||
| .field("number", .string) | |||
| .update() | |||
| } | |||
| func revert(on database: Database) async throws { | |||
| try await database.schema("part") | |||
| .deleteField("number") | |||
| .update() | |||
| } | |||
| } | |||
| public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlPart>{ | |||
| let query = mdlPart.query(on: req.db) | |||
| @@ -58,6 +58,24 @@ extension mdlSignatureType{ | |||
| func revert(on database: Database) async throws { | |||
| try await database.schema("signatureType").delete() | |||
| } | |||
| } | |||
| struct Seed: Migration{ | |||
| func prepare(on database: Database) -> EventLoopFuture<Void> { | |||
| let mdls: [mdlSignatureType] = [ | |||
| .init(id: 1, name: "Technician", description: nil, isactive: true, isrequired: true, createuserid: -1, updateuserid: -1), | |||
| .init(id: 2, name: "Customer", description: nil, isactive: true, isrequired: false, createuserid: -1, updateuserid: -1) | |||
| ] | |||
| return mdls.map { mdl in | |||
| mdl.save(on: database) | |||
| } | |||
| .flatten(on: database.eventLoop) | |||
| } | |||
| func revert(on database: Database) -> EventLoopFuture<Void> { | |||
| mdlSignatureType.query(on: database).delete() | |||
| } | |||
| } | |||
| struct Mod1: AsyncMigration { | |||
| func prepare(on database: Database) async throws { | |||
| @@ -18,6 +18,7 @@ final class mdlViscosity: Model, Content { | |||
| @Field(key: "name") var name: String? | |||
| @Field(key: "description") var description: String? | |||
| @Field(key: "isActive") var isactive: Bool? | |||
| @Field(key: "sortOrder") var sortorder: Int? | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @Field(key: "createUserId") var createuserid: Int? | |||
| @@ -26,12 +27,13 @@ final class mdlViscosity: Model, Content { | |||
| init() { } | |||
| init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil) { | |||
| init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = true, sortorder: Int? = 0, createuserid: Int? = nil, updateuserid: Int? = nil) { | |||
| self.id = id | |||
| self.name = name | |||
| self.description = description | |||
| self.isactive = isactive | |||
| self.sortorder = sortorder | |||
| self.createuserid = createuserid | |||
| self.updateuserid = updateuserid | |||
| @@ -57,6 +59,18 @@ extension mdlViscosity{ | |||
| try await database.schema("viscosity").delete() | |||
| } | |||
| } | |||
| struct Mod1: AsyncMigration{ | |||
| func prepare(on database: Database) async throws { | |||
| try await database.schema("viscosity") | |||
| .field("sortOrder", .int) | |||
| .update() | |||
| } | |||
| func revert(on database: Database) async throws { | |||
| try await database.schema("viscosity") | |||
| .deleteField("sortOrder") | |||
| .update() | |||
| } | |||
| } | |||
| public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlViscosity>{ | |||
| let query = mdlViscosity.query(on: req.db) | |||
| @@ -22,6 +22,8 @@ final class mdlContact: Model, Content { | |||
| @Parent(key: "customerId") var customer: mdlCustomer | |||
| @Children(for: \.$contact) var info: [mdlContactInfo] | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @Field(key: "createUserId") var createuserid: Int? | |||
| @Timestamp(key: "updateDate", on: .update) var updatedate: Date? | |||
| @@ -14,11 +14,12 @@ final class mdlContactInfo: Model, Content { | |||
| static let schema = "contactInfo" | |||
| @ID(custom: "id", generatedBy: .database) var id: Int? | |||
| @Field(key: "label") var label: String? | |||
| @Field(key: "value") var value: String? | |||
| @Field(key: "isActive") var isactive: Bool? | |||
| @Parent(key: "contactTypeId") var contacttype: mdlContactType | |||
| @OptionalParent(key: "contact") var contact: mdlContact? | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @@ -28,13 +29,15 @@ final class mdlContactInfo: Model, Content { | |||
| init() { } | |||
| init(id: Int? = nil, value: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil, contacttypeid: Int) { | |||
| init(id: Int? = nil, label: String? = nil, value: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil, contacttypeid: Int, contactid: Int? = nil) { | |||
| self.id = id | |||
| self.label = label | |||
| self.value = value | |||
| self.isactive = isactive | |||
| self.$contacttype.$id.value = contacttypeid | |||
| if(contactid != nil) { self.$contact.$id.value = contactid } | |||
| self.createuserid = createuserid | |||
| self.updateuserid = updateuserid | |||
| @@ -60,6 +63,20 @@ extension mdlContactInfo{ | |||
| try await database.schema("contactInfo").delete() | |||
| } | |||
| } | |||
| struct Mod1: AsyncMigration{ | |||
| func prepare(on database: Database) async throws { | |||
| try await database.schema("contactInfo") | |||
| .field("label", .string) | |||
| .field("contactId", .int, .references("contact", "id")) | |||
| .update() | |||
| } | |||
| func revert(on database: Database) async throws { | |||
| try await database.schema("contactInfo") | |||
| .deleteField("label") | |||
| .deleteField("contactId") | |||
| .update() | |||
| } | |||
| } | |||
| public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlContactInfo>{ | |||
| let query = mdlContactInfo.query(on: req.db) | |||
| @@ -17,6 +17,7 @@ final class mdlEquipment: Model, Content { | |||
| @Field(key: "number") var number: String? | |||
| @Field(key: "isActive") var isactive: Bool? | |||
| @Field(key: "meterReading") var meterreading: String? | |||
| @OptionalParent(key: "customerId") var customer: mdlCustomer? | |||
| @Parent(key: "modelId") var model: mdlModel | |||
| @@ -84,11 +85,24 @@ extension mdlEquipment{ | |||
| .update() | |||
| } | |||
| } | |||
| struct Mod1: AsyncMigration { | |||
| func prepare(on database: Database) async throws { | |||
| try await database.schema("equipment") | |||
| .field("meterReading", .string) | |||
| .update() | |||
| } | |||
| func revert(on database: Database) async throws { | |||
| try await database.schema("equipment") | |||
| .deleteField("meterReading") | |||
| .update() | |||
| } | |||
| } | |||
| public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlEquipment>{ | |||
| let query = mdlEquipment.query(on: req.db) | |||
| .with(\.$customer) | |||
| .with(\.$model) | |||
| .with(\.$model){model in model.with(\.$product).with(\.$make)} | |||
| .with(\.$equipmenttype) | |||
| .with(\.$parent) | |||
| .with(\.$properties) | |||
| @@ -18,6 +18,7 @@ final class mdlProduct: Model, Content { | |||
| @Field(key: "name") var name: String? | |||
| @Field(key: "description") var description: String? | |||
| @Field(key: "isActive") var isactive: Bool? | |||
| @Field(key: "code") var code: String? | |||
| @Children(for: \.$product) var templates: [mdlTemplate] | |||
| @@ -28,11 +29,12 @@ final class mdlProduct: Model, Content { | |||
| init() { } | |||
| init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { | |||
| init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = nil, code: String? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { | |||
| self.id = id | |||
| self.description = description | |||
| self.isactive = isactive | |||
| self.code = code | |||
| self.createuserid = createuserid | |||
| self.updateuserid = updateuserid | |||
| @@ -58,6 +60,18 @@ extension mdlProduct{ | |||
| try await database.schema("product").delete() | |||
| } | |||
| } | |||
| struct Mod1: AsyncMigration{ | |||
| func prepare(on database: Database) async throws { | |||
| try await database.schema("product") | |||
| .field("code", .string) | |||
| .update() | |||
| } | |||
| func revert(on database: Database) async throws { | |||
| try await database.schema("product") | |||
| .deleteField("code") | |||
| .update() | |||
| } | |||
| } | |||
| public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlProduct>{ | |||
| let query = mdlProduct.query(on: req.db) | |||
| @@ -19,6 +19,10 @@ final class mdlItem: Model, Content { | |||
| @Field(key: "description") var description: String? | |||
| @Field(key: "isActive") var isactive: Bool? | |||
| @Parent(key: "categoryId") var category: mdlCategory | |||
| @OptionalParent(key: "smscCodeId") var smsccode: mdlSMSCCode? | |||
| @Parent(key: "inputTypeId") var inputtype: mdlInputType | |||
| @Children(for: \.$item) var templateitems: [mdlTemplateItemSpec] | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @@ -28,12 +32,15 @@ final class mdlItem: Model, Content { | |||
| init() { } | |||
| init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil) { | |||
| init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil, categoryid: Int, smsccodeid: Int? = nil, inputtypeid: Int) { | |||
| self.id = id | |||
| self.name = name | |||
| self.description = description | |||
| self.isactive = isactive | |||
| self.$category.$id.value = categoryid | |||
| if(smsccodeid != nil){ self.$smsccode.$id.value = smsccodeid } | |||
| self.$inputtype.$id.value = inputtypeid | |||
| self.createuserid = createuserid | |||
| self.updateuserid = updateuserid | |||
| @@ -59,6 +66,23 @@ extension mdlItem{ | |||
| try await database.schema("item").delete() | |||
| } | |||
| } | |||
| struct Mod1: AsyncMigration { | |||
| func prepare(on database: Database) async throws { | |||
| try await database.schema("item") | |||
| .field("categoryId", .int, .references("category", "id")) | |||
| .field("smscCodeId", .int, .references("smscCode", "id")) | |||
| .field("inputTypeId", .int, .references("inputType", "id")) | |||
| .update() | |||
| } | |||
| func revert(on database: Database) async throws { | |||
| try await database.schema("item") | |||
| .deleteField("categoryId") | |||
| .deleteField("smscCodeId") | |||
| .deleteField("inputTypeId") | |||
| .update() | |||
| } | |||
| } | |||
| public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlItem>{ | |||
| let query = mdlItem.query(on: req.db) | |||
| @@ -17,6 +17,7 @@ final class mdlItemResponseType: Model, Content { | |||
| @Parent(key: "itemId") var item: mdlItem | |||
| @Parent(key: "responseTypeId") var responsetype: mdlResponseType | |||
| @Field(key: "sortOrder") var sortrder: Int? | |||
| @Field(key: "isActive") var isactive: Bool? | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @@ -26,11 +27,12 @@ final class mdlItemResponseType: Model, Content { | |||
| init() { } | |||
| init(id: Int? = nil, itemid: Int, responsetypeid: Int, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil) { | |||
| init(id: Int? = nil, itemid: Int, responsetypeid: Int, sortorder: Int? = 0, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil) { | |||
| self.id = id | |||
| self.$item.$id.value = itemid | |||
| self.$responsetype.$id.value = responsetypeid | |||
| self.sortrder = sortorder | |||
| self.isactive = isactive | |||
| self.createuserid = createuserid | |||
| @@ -57,6 +59,19 @@ extension mdlItemResponseType{ | |||
| try await database.schema("itemResponseType").delete() | |||
| } | |||
| } | |||
| struct Mod1: AsyncMigration { | |||
| func prepare(on database: Database) async throws { | |||
| try await database.schema("itemResponseType") | |||
| .field("sortOrder", .int) | |||
| .update() | |||
| } | |||
| func revert(on database: Database) async throws { | |||
| try await database.schema("itemResponseType") | |||
| .deleteField("sortOrder") | |||
| .update() | |||
| } | |||
| } | |||
| public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlItemResponseType>{ | |||
| let query = mdlItemResponseType.query(on: req.db) | |||
| @@ -19,7 +19,7 @@ final class mdlInspection: Model, Content { | |||
| @Parent(key: "workOrderSegmentId") var segment: mdlWorkOrderSegment | |||
| @Parent(key: "inspectionLevelId") var level: mdlInspectionLevel | |||
| @Field(key: "name") var name: String? | |||
| @Field(key: "description") var description: String? | |||
| @Field(key: "segment") var seg: String? | |||
| @Field(key: "interval") var interval: String? | |||
| @Children(for: \.$inspection) var categories: [mdlInspectionCategory] | |||
| @@ -34,7 +34,8 @@ final class mdlInspection: Model, Content { | |||
| init(id: Int? = nil, | |||
| name: String? = nil, | |||
| description: String? = nil, | |||
| interval: String? = nil, | |||
| seg: String? = nil, | |||
| segmentid: Int, | |||
| levelid: Int, | |||
| createuserid: Int? = nil, | |||
| @@ -42,7 +43,8 @@ final class mdlInspection: Model, Content { | |||
| ) { | |||
| self.id = id | |||
| self.name = name | |||
| self.description = description | |||
| self.interval = interval | |||
| self.seg = seg | |||
| self.$segment.$id.value = segmentid | |||
| self.$level.$id.value = levelid | |||
| self.createuserid = createuserid | |||
| @@ -69,6 +71,22 @@ extension mdlInspection{ | |||
| try await database.schema("inspection").delete() | |||
| } | |||
| } | |||
| struct Mod1: AsyncMigration{ | |||
| func prepare(on database: Database) async throws { | |||
| try await database.schema("inspection") | |||
| .deleteField("description") | |||
| .field("segment", .string) | |||
| .field("interval", .string) | |||
| .update() | |||
| } | |||
| func revert(on database: Database) async throws { | |||
| try await database.schema("inspection") | |||
| .deleteField("segment") | |||
| .deleteField("interval") | |||
| .field("description", .string) | |||
| .update() | |||
| } | |||
| } | |||
| public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlInspection>{ | |||
| let query = mdlInspection.query(on: req.db) | |||
| @@ -16,7 +16,7 @@ final class mdlWorkOrder: Model, Content { | |||
| @ID(custom: "id", generatedBy: .database) var id: Int? | |||
| @Field(key: "number") var number: String? | |||
| @Field(key: "meterReading") var meterreading: Decimal? | |||
| @Field(key: "meterReading") var meterreading: String? | |||
| @Field(key: "specialInstructions") var specialinstructions: String? | |||
| @Field(key: "scheduledStartDate") var scheduledstartdate: Date? | |||
| @Field(key: "scheduledEndDate") var scheduledenddate: Date? | |||
| @@ -38,6 +38,7 @@ final class mdlWorkOrder: Model, Content { | |||
| @Children(for: \.$workorder) var signatures: [mdlSignature] | |||
| @Children(for: \.$workorder) var notes: [mdlNote] | |||
| @Children(for: \.$workorder) var segments: [mdlWorkOrderSegment] | |||
| @Timestamp(key: "createDate", on: .create) var createdate: Date? | |||
| @Field(key: "createUserId") var createuserid: Int? | |||
| @@ -48,7 +49,7 @@ final class mdlWorkOrder: Model, Content { | |||
| init(id: Int? = nil | |||
| , number: String? = nil | |||
| , meterreading: Decimal? = nil | |||
| , meterreading: String? = nil | |||
| , specialinstructions: String? = nil | |||
| , scheduledstartdate: Date? = nil | |||
| , scheduledenddate: Date? = nil | |||
| @@ -76,15 +77,15 @@ final class mdlWorkOrder: Model, Content { | |||
| self.startdate = startdate | |||
| self.enddate = enddate | |||
| self.approveddate = approveddate | |||
| self.$customer.$id.value = customerid! | |||
| self.$equipment.$id.value = equipmentid! | |||
| self.$status.$id.value = statusid! | |||
| self.$priority.$id.value = priorityid! | |||
| self.$technician.$id.value = technicianuserid! | |||
| self.$reason.$id.value = reasonid! | |||
| self.$incompletereason.$id.value = incompletereasonid! | |||
| self.$fuel.$id.value = fuelid! | |||
| self.$workorderflow.$id.value = workorderflowid! | |||
| if(customerid != nil) { self.$customer.$id.value = customerid! } | |||
| if(equipmentid != nil) { self.$equipment.$id.value = equipmentid! } | |||
| if(statusid != nil) { self.$status.$id.value = statusid! } | |||
| if(priorityid != nil) { self.$priority.$id.value = priorityid! } | |||
| if(technicianuserid != nil) { self.$technician.$id.value = technicianuserid! } | |||
| if(reasonid != nil) { self.$reason.$id.value = reasonid! } | |||
| if(incompletereasonid != nil) { self.$incompletereason.$id.value = incompletereasonid! } | |||
| if(fuelid != nil) {self.$fuel.$id.value = fuelid! } | |||
| if(workorderflowid != nil) {self.$workorderflow.$id.value = workorderflowid! } | |||
| self.createuserid = createuserid ?? -1 | |||
| self.updateuserid = updateuserid ?? -1 | |||
| } | |||
| @@ -135,6 +136,21 @@ extension mdlWorkOrder{ | |||
| .update() | |||
| } | |||
| } | |||
| struct Mod2: AsyncMigration { | |||
| func prepare(on database: Database) async throws { | |||
| try await database.schema("workOrder") | |||
| .deleteField("meterReading") | |||
| .field("meterReading", .string) | |||
| .update() | |||
| } | |||
| func revert(on database: Database) async throws { | |||
| try await database.schema("workOrder") | |||
| .deleteField("meterReading") | |||
| .update() | |||
| } | |||
| } | |||
| public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlWorkOrder>{ | |||
| let query = mdlWorkOrder.query(on: req.db) | |||
| @@ -150,6 +166,7 @@ extension mdlWorkOrder{ | |||
| .with(\.$attachments) | |||
| .with(\.$signatures) | |||
| .with(\.$notes) | |||
| .with(\.$segments){ segment in segment.with(\.$inspections)} | |||
| if let x = req.parameters.get("x"){ | |||
| let decryptedString = try CustomCrypto.DecryptString(input: x) | |||
| @@ -62,6 +62,24 @@ extension mdlWorkOrderSegment{ | |||
| try await database.schema("workOrderSegment").delete() | |||
| } | |||
| } | |||
| struct Mod1: AsyncMigration { | |||
| func prepare(on database: Database) async throws { | |||
| try await database.schema("workOrderSegment") | |||
| .deleteField("workOrderId") | |||
| .deleteField("segmentId") | |||
| .field("workOrderId", .int, .references("workOrder", "id")) | |||
| .field("segmentId", .int, .references("segment", "id")) | |||
| .update() | |||
| } | |||
| func revert(on database: Database) async throws { | |||
| try await database.schema("workOrderSegment") | |||
| .deleteField("workOrderId") | |||
| .deleteField("segmentId") | |||
| .field("workOrderId", .int) | |||
| .field("segmentId", .int) | |||
| .update() | |||
| } | |||
| } | |||
| public static func ObjQuery(req: Request) async throws -> QueryBuilder<mdlWorkOrderSegment>{ | |||
| let query = mdlWorkOrderSegment.query(on: req.db) | |||
| @@ -16,6 +16,7 @@ public func configure(_ app: Application) async throws { | |||
| let cors = CORSMiddleware(configuration: corsConfiguration) | |||
| // cors middleware should come before default error middleware using `at: .beginning` | |||
| app.middleware.use(cors, at: .beginning) | |||
| //FileMiddleware(publicDirectory: app.directory.publicDirectory, defaultFile: "index.html") | |||
| app.http.server.configuration.port = 3003 | |||
| @@ -56,8 +57,8 @@ public func configure(_ app: Application) async throws { | |||
| app.migrations.add(mdlStatus.Create()) | |||
| app.migrations.add(mdlStatus.Seed()) | |||
| app.migrations.add(mdlDivision.Create()) | |||
| app.migrations.add(mdlLabSetting.Create()) | |||
| app.migrations.add(mdlLocation.Create()) | |||
| app.migrations.add(mdlLabSetting.Create()) | |||
| app.migrations.add(mdlFluid.Create()) | |||
| app.migrations.add(mdlFuel.Create()) | |||
| app.migrations.add(mdlIncompleteReason.Create()) | |||
| @@ -92,7 +93,8 @@ public func configure(_ app: Application) async throws { | |||
| app.migrations.add(mdlSpec.Create()) | |||
| app.migrations.add(mdlSpecItem.Create()) | |||
| app.migrations.add(mdlSpecItemValue.Create()) | |||
| app.migrations.add(mdlWorkOrder.Create()) | |||
| app.migrations.add(mdlWorkOrderFlow.Create()) | |||
| app.migrations.add(mdlWorkOrder.Create())//Done to here | |||
| app.migrations.add(mdlSegment.Create()) | |||
| app.migrations.add(mdlSegment.Seed()) | |||
| app.migrations.add(mdlOilSample.Create()) | |||
| @@ -108,7 +110,6 @@ public func configure(_ app: Application) async throws { | |||
| app.migrations.add(mdlLabSetting.Mod2()) | |||
| app.migrations.add(mdlLocation.Mod1()) | |||
| app.migrations.add(mdlWorkOrderAttachment.Create()) | |||
| app.migrations.add(mdlWorkOrderFlow.Create()) | |||
| app.migrations.add(mdlWorkOrder.Mod1()) | |||
| app.migrations.add(mdlWorkOrderPart.Create()) | |||
| app.migrations.add(mdlWorkOrderPart.Mod1()) | |||
| @@ -140,6 +141,20 @@ public func configure(_ app: Application) async throws { | |||
| app.migrations.add(mdlTemplateItemSpec.Create()) | |||
| app.migrations.add(Token.Create()) | |||
| app.migrations.add(mdlLicense.Create()) | |||
| app.migrations.add(mdlWorkOrderSegment.Mod1()) | |||
| app.migrations.add(mdlPart.Mod1()) | |||
| app.migrations.add(mdlSignatureType.Seed()) | |||
| app.migrations.add(mdlViscosity.Mod1()) | |||
| app.migrations.add(mdlGate.Mod1()) | |||
| app.migrations.add(mdlContactInfo.Mod1()) | |||
| app.migrations.add(mdlProduct.Mod1()) | |||
| app.migrations.add(mdlEquipment.Mod1()) | |||
| app.migrations.add(mdlWorkOrder.Mod1()) | |||
| app.migrations.add(mdlItem.Mod1()) | |||
| app.migrations.add(mdlItemResponseType.Mod1()) | |||
| app.migrations.add(mdlInspection.Mod1()) | |||
| app.migrations.add(mdlWorkOrder.Mod2()) | |||
| app.migrations.add(mdlSignature.Mode1()) | |||
| app.logger.logLevel = .debug | |||
| @@ -1,6 +1,8 @@ | |||
| import Fluent | |||
| import Vapor | |||
| import Crypto | |||
| import SwiftOpenAPI | |||
| import VaporToOpenAPI | |||
| let | |||
| @@ -13,6 +15,29 @@ func routes(_ app: Application) throws { | |||
| baseApp.get { req async in | |||
| "Connexion Mobile Services Version 2.0" | |||
| } | |||
| baseApp.get("Swagger", "swagger.json") { req async in | |||
| req.application.routes.openAPI( | |||
| info: InfoObject( | |||
| title: "Example API", | |||
| description: "Example API Description", | |||
| version: "2.0" | |||
| ) | |||
| ) | |||
| }.excludeFromOpenAPI() | |||
| // baseApp.get("Swagger", "swagger.json"){ | |||
| // baseApp.openAPI( | |||
| // info: InfoObject( | |||
| // title: "Example API", | |||
| // description: "Example API Description", | |||
| // version: "2.0" | |||
| // ) | |||
| // ) | |||
| // } | |||
| try baseApp.register(collection: cntrlCategory()) | |||
| try baseApp.register(collection: cntrlValueType()) | |||
| try baseApp.register(collection: cntrlDataType()) | |||
| @@ -12,10 +12,10 @@ final class RoleTests: XCTestCase { | |||
| let description = "Testing Role methods" | |||
| let cuserid = -1 | |||
| let uuserid = -1 | |||
| let input = mdlRole(id: nil, name: name, description: description, createuserid: cuserid, updateuserid: uuserid) | |||
| //Insert object | |||
| try app.test(.POST, basepath, beforeRequest: { | |||
| req in | |||
| let input = mdlRole(id: nil, name: name, description: description, createuserid: cuserid, updateuserid: uuserid) | |||
| try req.content.encode(input) | |||
| }, afterResponse: { | |||
| res in | |||
| @@ -27,7 +27,8 @@ final class RoleTests: XCTestCase { | |||
| //Update object just created | |||
| try app.test(.POST, basepath, beforeRequest:{ | |||
| req in | |||
| let input = mdlRole(id: nil, name: name, description: "Test Update", createuserid: cuserid, updateuserid: uuserid) | |||
| input.name = "TestUpdate" | |||
| try req.content.encode(input) | |||
| }, afterResponse: { | |||
| res in | |||
| XCTAssertEqual(res.status, .accepted) | |||
| @@ -43,7 +44,7 @@ final class RoleTests: XCTestCase { | |||
| }) | |||
| //Read the object just inserted | |||
| var parameter = try CustomCrypto.EncryptString(input: String(id!)) | |||
| let parameter = try CustomCrypto.EncryptString(input: String(id!)) | |||
| var path = "\(basepath)\(parameter)" | |||
| try app.test(.GET, path, afterResponse: { res in | |||
| @@ -99,6 +99,23 @@ final class UserTests: XCTestCase { | |||
| XCTAssertEqual(res.status, .unauthorized) | |||
| XCTAssertEqual(res.headers.contentType, .json) | |||
| }) | |||
| //null values | |||
| combo = ":\(goodpwd)" | |||
| parameter = try CustomCrypto.EncryptString(input: combo) | |||
| path = "\(basepath)login/\(parameter)" | |||
| try app.test(.GET, path, afterResponse: { | |||
| res in | |||
| XCTAssertEqual(res.status, .unauthorized) | |||
| XCTAssertEqual(res.headers.contentType, .json) | |||
| }) | |||
| combo = "\(baduser):" | |||
| parameter = try CustomCrypto.EncryptString(input: combo) | |||
| path = "\(basepath)login/\(parameter)" | |||
| try app.test(.GET, path, afterResponse: { | |||
| res in | |||
| XCTAssertEqual(res.status, .unauthorized) | |||
| XCTAssertEqual(res.headers.contentType, .json) | |||
| }) | |||
| //delete user | |||
| let encryptedid = try CustomCrypto.EncryptString(input: String(id!)) | |||