From 7b18729eaef3c65ba086d0f3dada40d977b52101 Mon Sep 17 00:00:00 2001 From: rpm-mcarman <65228808+rpm-mcarman@users.noreply.github.com> Date: Mon, 1 Apr 2024 13:08:21 -0400 Subject: [PATCH] add all files --- Package.resolved | 248 ++++++++++++++++++ Sources/App/Controllers/cntrlDataType.swift | 59 ++++- Sources/App/Controllers/cntrlRole.swift | 44 +++- Sources/App/Controllers/cntrlUser.swift | 48 +++- Sources/App/Controllers/cntrlValueType.swift | 59 ++++- Sources/App/Models/AuthTables/mdlRole.swift | 90 ++++++- Sources/App/Models/AuthTables/mdlUser.swift | 89 ++++++- .../ChildTables/mdlResponseType.swift | 65 ++++- .../App/Models/BaseTables/mdlCategory.swift | 25 +- .../Models/BaseTables/mdlComparisonType.swift | 48 +++- .../Models/BaseTables/mdlContactType.swift | 79 +++++- .../App/Models/BaseTables/mdlDataType.swift | 77 +++++- .../App/Models/BaseTables/mdlDivision.swift | 3 + .../Models/BaseTables/mdlEquipmentType.swift | 72 ++++- Sources/App/Models/BaseTables/mdlFuel.swift | 2 + Sources/App/Models/BaseTables/mdlGate.swift | 70 ++++- .../BaseTables/mdlIncompleteReason.swift | 2 + .../App/Models/BaseTables/mdlInputType.swift | 74 +++++- .../App/Models/BaseTables/mdlJobSite.swift | 76 +++++- .../App/Models/BaseTables/mdlLocation.swift | 3 + .../App/Models/BaseTables/mdlPriority.swift | 79 +++++- Sources/App/Models/BaseTables/mdlReason.swift | 63 ++++- .../App/Models/BaseTables/mdlRepairType.swift | 83 +++++- .../App/Models/BaseTables/mdlSMSCCode.swift | 61 ++++- .../Models/BaseTables/mdlSignatureType.swift | 61 ++++- Sources/App/Models/BaseTables/mdlState.swift | 131 ++++++++- Sources/App/Models/BaseTables/mdlStatus.swift | 84 +++++- .../App/Models/BaseTables/mdlValueType.swift | 78 +++++- .../App/Models/BaseTables/mdlViscosity.swift | 61 ++++- .../CompartmentModule/mdlCompartment.swift | 26 +- .../mdlCompartmentLocation.swift | 29 +- .../Models/CustomerTables/mdlContact.swift | 78 +++++- .../CustomerTables/mdlContactInfo.swift | 64 ++++- .../Models/CustomerTables/mdlCustomer.swift | 63 ++++- .../Models/CustomerTables/mdlEquipment.swift | 85 +++++- .../App/Models/CustomerTables/mdlMake.swift | 61 ++++- .../App/Models/CustomerTables/mdlModel.swift | 69 ++++- .../CustomerTables/mdlObjectProperty.swift | 64 ++++- .../Models/CustomerTables/mdlProduct.swift | 61 ++++- Sources/App/Models/ItemTables/mdlItem.swift | 61 ++++- .../ItemTables/mdlItemResponseType.swift | 61 ++++- .../App/Models/LabTables/mdlLabSetting.swift | 71 ++++- .../LinkingTables/XFluidViscosity.swift | 63 ++++- .../App/Models/LinkingTables/XUserRole.swift | 71 ++++- .../LinkingTables/XWorkOrderSegment.swift | 61 ++++- .../Models/OilSampleTables/mdlOilSample.swift | 108 +++++++- Sources/App/Models/SpecTables/mdlSpec.swift | 66 ++++- .../App/Models/SpecTables/mdlSpecItem.swift | 76 +++++- .../Models/SpecTables/mdlSpecItemValue.swift | 66 ++++- .../Models/WorkOrderTables/mdlWorkOrder.swift | 120 ++++++++- Sources/App/configure.swift | 95 ++++++- Sources/App/routes.swift | 17 +- 52 files changed, 3321 insertions(+), 149 deletions(-) create mode 100644 Package.resolved diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..0289bc7 --- /dev/null +++ b/Package.resolved @@ -0,0 +1,248 @@ +{ + "pins" : [ + { + "identity" : "async-http-client", + "kind" : "remoteSourceControl", + "location" : "https://github.com/swift-server/async-http-client.git", + "state" : { + "revision" : "291438696abdd48d2a83b52465c176efbd94512b", + "version" : "1.20.1" + } + }, + { + "identity" : "async-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/async-kit.git", + "state" : { + "revision" : "7ece208cd401687641c88367a00e3ea2b04311f1", + "version" : "1.19.0" + } + }, + { + "identity" : "console-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/console-kit.git", + "state" : { + "revision" : "a31f44ebfbd15a2cc0fda705279676773ac16355", + "version" : "4.14.1" + } + }, + { + "identity" : "fluent", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/fluent.git", + "state" : { + "revision" : "a586a5d4164f23a0ee4e02e1f467b9bbef0c9f1c", + "version" : "4.9.0" + } + }, + { + "identity" : "fluent-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/fluent-kit.git", + "state" : { + "revision" : "6cef8533c9ab87865de58fa3c6e6317e3e09857a", + "version" : "1.45.1" + } + }, + { + "identity" : "fluent-postgres-driver", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/fluent-postgres-driver.git", + "state" : { + "revision" : "a538fc647f82d915eb84e0a12ca9b08c513e57c4", + "version" : "2.8.0" + } + }, + { + "identity" : "multipart-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/multipart-kit.git", + "state" : { + "revision" : "12ee56f25bd3fc4c2d09c2aa16e69de61dc786e8", + "version" : "4.6.0" + } + }, + { + "identity" : "postgres-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/postgres-kit.git", + "state" : { + "revision" : "80ab7737dac4fccd4a8ad38743828dcb71ba7ac8", + "version" : "2.12.2" + } + }, + { + "identity" : "postgres-nio", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/postgres-nio.git", + "state" : { + "revision" : "fa3137d39bca84843739db1c5a3db2d7f4ae65e6", + "version" : "1.20.0" + } + }, + { + "identity" : "routing-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/routing-kit.git", + "state" : { + "revision" : "2a92a7eac411a82fb3a03731be5e76773ebe1b3e", + "version" : "4.9.0" + } + }, + { + "identity" : "sql-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/sql-kit.git", + "state" : { + "revision" : "b2f128cb62a3abfbb1e3b2893ff3ee69e70f4f0f", + "version" : "3.28.0" + } + }, + { + "identity" : "swift-algorithms", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-algorithms.git", + "state" : { + "revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42", + "version" : "1.2.0" + } + }, + { + "identity" : "swift-atomics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-atomics.git", + "state" : { + "revision" : "cd142fd2f64be2100422d658e7411e39489da985", + "version" : "1.2.0" + } + }, + { + "identity" : "swift-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-collections.git", + "state" : { + "revision" : "d029d9d39c87bed85b1c50adee7c41795261a192", + "version" : "1.0.6" + } + }, + { + "identity" : "swift-crypto", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-crypto.git", + "state" : { + "revision" : "cc76b894169a3c86b71bac10c78a4db6beb7a9ad", + "version" : "3.2.0" + } + }, + { + "identity" : "swift-http-types", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-http-types", + "state" : { + "revision" : "12358d55a3824bd5fed310b999ea8cf83a9a1a65", + "version" : "1.0.3" + } + }, + { + "identity" : "swift-log", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-log.git", + "state" : { + "revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5", + "version" : "1.5.4" + } + }, + { + "identity" : "swift-metrics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-metrics.git", + "state" : { + "revision" : "971ba26378ab69c43737ee7ba967a896cb74c0d1", + "version" : "2.4.1" + } + }, + { + "identity" : "swift-nio", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio.git", + "state" : { + "revision" : "635b2589494c97e48c62514bc8b37ced762e0a62", + "version" : "2.63.0" + } + }, + { + "identity" : "swift-nio-extras", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-extras.git", + "state" : { + "revision" : "363da63c1966405764f380c627409b2f9d9e710b", + "version" : "1.21.0" + } + }, + { + "identity" : "swift-nio-http2", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-http2.git", + "state" : { + "revision" : "0904bf0feb5122b7e5c3f15db7df0eabe623dd87", + "version" : "1.30.0" + } + }, + { + "identity" : "swift-nio-ssl", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-ssl.git", + "state" : { + "revision" : "7c381eb6083542b124a6c18fae742f55001dc2b5", + "version" : "2.26.0" + } + }, + { + "identity" : "swift-nio-transport-services", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-transport-services.git", + "state" : { + "revision" : "6cbe0ed2b394f21ab0d46b9f0c50c6be964968ce", + "version" : "1.20.1" + } + }, + { + "identity" : "swift-numerics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-numerics.git", + "state" : { + "revision" : "0a5bc04095a675662cf24757cc0640aa2204253b", + "version" : "1.0.2" + } + }, + { + "identity" : "swift-system", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-system.git", + "state" : { + "revision" : "025bcb1165deab2e20d4eaba79967ce73013f496", + "version" : "1.2.1" + } + }, + { + "identity" : "vapor", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/vapor.git", + "state" : { + "revision" : "4942d74e8493fc918ed6144c835c8a0e6affd4f4", + "version" : "4.92.1" + } + }, + { + "identity" : "websocket-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/websocket-kit.git", + "state" : { + "revision" : "53fe0639a98903858d0196b699720decb42aee7b", + "version" : "2.14.0" + } + } + ], + "version" : 2 +} diff --git a/Sources/App/Controllers/cntrlDataType.swift b/Sources/App/Controllers/cntrlDataType.swift index a2029e5..eb7c437 100644 --- a/Sources/App/Controllers/cntrlDataType.swift +++ b/Sources/App/Controllers/cntrlDataType.swift @@ -1,8 +1,51 @@ -// -// File.swift -// -// -// Created by Michiel Carman on 1/25/24. -// - -import Foundation +import Fluent +import Vapor + +struct cntrlDataTypes: RouteCollection { + func boot(routes: RoutesBuilder) throws { + let rts = routes.grouped("dataTypes") + rts.get(use: index) + rts.get(":id", use: search) + rts.post(use: create) + rts.put(use: update) + rts.group(":id") { rt in + rt.delete(use: delete) + } + } + + func index(req: Request) async throws -> [mdlDataType] { + try await mdlDataType.query(on: req.db).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 create(req: Request) async throws -> mdlDataType { + let obj = try req.content.decode(mdlDataType.self) + 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 { + throw Abort(.notFound) + } + try await obj.delete(on: req.db) + return .noContent + } +} diff --git a/Sources/App/Controllers/cntrlRole.swift b/Sources/App/Controllers/cntrlRole.swift index 98ce263..2099689 100644 --- a/Sources/App/Controllers/cntrlRole.swift +++ b/Sources/App/Controllers/cntrlRole.swift @@ -5,4 +5,46 @@ // Created by Michiel Carman on 4/1/24. // -import Foundation +import Fluent +import Vapor + +struct cntrlRole: RouteCollection { + func boot(routes: RoutesBuilder) throws { + let rts = routes.grouped("roles") + rts.get(use: index) + rts.post(use: create) + rts.put(use: update) + rts.group(":id") { todo in + rts.delete(use: delete) + } + } + + func index(req: Request) async throws -> [mdlRole] { + try await mdlRole.query(on: req.db).with(\.$users).all() + } + + func create(req: Request) async throws -> mdlRole { + let obj = try req.content.decode(mdlRole.self) + 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 { + throw Abort(.notFound) + } + try await obj.delete(on: req.db) + return .noContent + } +} diff --git a/Sources/App/Controllers/cntrlUser.swift b/Sources/App/Controllers/cntrlUser.swift index 98ce263..bc0d923 100644 --- a/Sources/App/Controllers/cntrlUser.swift +++ b/Sources/App/Controllers/cntrlUser.swift @@ -1,8 +1,52 @@ // // File.swift -// +// // // Created by Michiel Carman on 4/1/24. // -import Foundation +import Fluent +import Vapor + +struct cntrlUser: RouteCollection { + func boot(routes: RoutesBuilder) throws { + let rts = routes.grouped("users") + rts.get(use: index) + rts.post(use: create) + rts.put(use: update) + rts.group(":id") { todo in + rts.delete(use: delete) + } + } + + func index(req: Request) async throws -> [mdlUser] { + try await mdlUser.query(on: req.db).with(\.$roles).all() + } + + func create(req: Request) async throws -> mdlUser { + let obj = try req.content.decode(mdlUser.self) + 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 { + throw Abort(.notFound) + } + try await obj.delete(on: req.db) + return .noContent + } +} diff --git a/Sources/App/Controllers/cntrlValueType.swift b/Sources/App/Controllers/cntrlValueType.swift index a2029e5..d7d6e6c 100644 --- a/Sources/App/Controllers/cntrlValueType.swift +++ b/Sources/App/Controllers/cntrlValueType.swift @@ -1,8 +1,51 @@ -// -// File.swift -// -// -// Created by Michiel Carman on 1/25/24. -// - -import Foundation +import Fluent +import Vapor + +struct cntrlValueType: RouteCollection { + func boot(routes: RoutesBuilder) throws { + let rts = routes.grouped("valueTypes") + rts.get(use: index) + rts.get(":id", use: search) + rts.post(use: create) + rts.put(use: update) + rts.group(":id") { rt in + rt.delete(use: delete) + } + } + + func index(req: Request) async throws -> [mdlValueType] { + try await mdlValueType.query(on: req.db).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 create(req: Request) async throws -> mdlValueType { + let obj = try req.content.decode(mdlValueType.self) + 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 { + throw Abort(.notFound) + } + try await obj.delete(on: req.db) + return .noContent + } +} diff --git a/Sources/App/Models/AuthTables/mdlRole.swift b/Sources/App/Models/AuthTables/mdlRole.swift index a2029e5..b01c592 100644 --- a/Sources/App/Models/AuthTables/mdlRole.swift +++ b/Sources/App/Models/AuthTables/mdlRole.swift @@ -1,8 +1,92 @@ // -// File.swift -// +// mdlRole.swift // -// Created by Michiel Carman on 1/25/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlRole: Model, Content { + static let schema = "role" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + + @Siblings(through: mdlXUserRole.self, from: \.$role, to: \.$user) var users: [mdlUser] + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.description = description + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlRole{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("role") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("role").delete() + } + } + struct Seed: Migration{ + func prepare(on database: Database) -> EventLoopFuture { + let mdls: [mdlRole] = [ + .init(id: 1, name: "Administrator", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 2, name: "Gate Keeper", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 3, name: "Preventative Maintenance", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 4, name: "Technician", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 5, name: "Yard Person", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 6, name: "Inspector", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 7, name: "Operator", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 8, name: "Customer", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 9, name: "Sales Person", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 10, name: "Sales Manager", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 11, name: "Parts Manager", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 12, name: "Foreman", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 13, name: "General Admin", description: nil, createuserid: -1, updateuserid: -1) + + ] + return mdls.map { mdl in + mdl.save(on: database) + } + .flatten(on: database.eventLoop) + } + + func revert(on database: Database) -> EventLoopFuture { + mdlRole.query(on: database).delete() + } + + + } +} + + + diff --git a/Sources/App/Models/AuthTables/mdlUser.swift b/Sources/App/Models/AuthTables/mdlUser.swift index a843f95..811e590 100644 --- a/Sources/App/Models/AuthTables/mdlUser.swift +++ b/Sources/App/Models/AuthTables/mdlUser.swift @@ -1,8 +1,91 @@ // -// File.swift -// +// mdlUser.swift // -// Created by Michiel Carman on 1/31/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlUser: Model, Content { + static let schema = "user" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "number") var number: String? + @Field(key: "firstName") var firstname: String? + @Field(key: "lastName") var lastname: String? + @Field(key: "username") var username: String? + @Field(key: "password") var password: String? + @Field(key: "email") var email: String? + @Field(key: "isActive") var isactive: Bool? + + @OptionalParent(key: "divisionId") var division: mdlDivision? + @OptionalParent(key: "locationId") var location: mdlLocation? + @OptionalParent(key: "gateId") var gate: mdlGate? + + @Siblings(through: mdlXUserRole.self, from: \.$user, to: \.$role) var roles: [mdlRole] + + @Children(for: \.$technician) var workorders: [mdlWorkOrder] + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, number: String? = nil, firstname: String? = nil, lastname: String? = nil, username: String? = nil, password: String? = nil, email: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil, divisionid: Int? = nil, locationid: Int? = nil, gateid: Int? = nil) { + self.id = id + + self.number = number + self.firstname = firstname + self.lastname = lastname + self.username = username + self.password = password + self.email = email + self.isactive = isactive + + self.$division.$id.value = divisionid! + self.$location.$id.value = locationid! + self.$gate.$id.value = gateid! + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlUser{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("user") + .field("id", .int, .identifier(auto: true)) + .field("number", .string) + .field("firstName", .string) + .field("lastName", .string) + .field("username", .string) + .field("password", .string) + .field("email", .string) + .field("isActive", .bool) + .field("divisionId", .int, .references("division", "id")) + .field("locationId", .int, .references("location", "id")) + .field("gateId", .int, .references("gate", "id")) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("user").delete() + } + } + +} + + + diff --git a/Sources/App/Models/BaseTables/ChildTables/mdlResponseType.swift b/Sources/App/Models/BaseTables/ChildTables/mdlResponseType.swift index a843f95..996f762 100644 --- a/Sources/App/Models/BaseTables/ChildTables/mdlResponseType.swift +++ b/Sources/App/Models/BaseTables/ChildTables/mdlResponseType.swift @@ -1,8 +1,67 @@ // -// File.swift -// +// mdlResponseType.swift // -// Created by Michiel Carman on 1/31/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlResponseType: Model, Content { + static let schema = "responseType" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "color") var color: String? + @Field(key: "isActive") var isactive: Bool? + + @Parent(key: "repairTypeId") var repairtype: mdlRepairType + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, color: String? = nil, isactive: Bool? = nil, repairtypeid: Int? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.color = color + self.isactive = isactive + self.$repairtype.$id.value = repairtypeid! + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlResponseType{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("responseType") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("color", .string) + .field("isActive", .bool) + .field("responseTypeId", .int) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("responseType").delete() + } + } +} + + + diff --git a/Sources/App/Models/BaseTables/mdlCategory.swift b/Sources/App/Models/BaseTables/mdlCategory.swift index 9c2b3ae..d77d592 100644 --- a/Sources/App/Models/BaseTables/mdlCategory.swift +++ b/Sources/App/Models/BaseTables/mdlCategory.swift @@ -7,8 +7,10 @@ import Fluent import Vapor +import Foundation +import FluentKit -final class Category: Model, Content { +final class mdlCategory: Model, Content { static let schema = "category" @ID(custom: "id", generatedBy: .database) var id: Int? @@ -33,3 +35,24 @@ final class Category: Model, Content { self.updateuserid = updateuserid } } + +extension mdlCategory{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("category") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("category").delete() + } + } +} diff --git a/Sources/App/Models/BaseTables/mdlComparisonType.swift b/Sources/App/Models/BaseTables/mdlComparisonType.swift index 5003818..7faa68c 100644 --- a/Sources/App/Models/BaseTables/mdlComparisonType.swift +++ b/Sources/App/Models/BaseTables/mdlComparisonType.swift @@ -7,8 +7,10 @@ import Fluent import Vapor +import Foundation +import FluentKit -final class ComparisonType: Model, Content { +final class mdlComparisonType: Model, Content { static let schema = "comparisonType" @ID(custom: "id", generatedBy: .database) var id: Int? @@ -17,7 +19,7 @@ final class ComparisonType: Model, Content { @Field(key: "description") var description: String? @Timestamp(key: "createDate", on: .create) var createdate: Date? - @Field(key: "creteUserId") var createuserid: Int? + @Field(key: "createUserId") var createuserid: Int? @Timestamp(key: "updateDate", on: .update) var updatedate: Date? @Field(key: "updateUserId") var updateuserid: Int? @@ -33,3 +35,45 @@ final class ComparisonType: Model, Content { self.updateuserid = updateuserid } } + +extension mdlComparisonType{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("comparisonType") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("comparisonType").delete() + } + } + struct Seed: Migration{ + func prepare(on database: Database) -> EventLoopFuture { + let cts: [mdlComparisonType] = [ + .init(id: 1, name: "Range", description: "must be between a maximum and minimum", createuserid: -1, updateuserid: -1), + .init(id: 2, name: "Min", description: "must be greater than or equal", createuserid: -1, updateuserid: -1), + .init(id: 3, name: "Max", description: "must be less than or equal", createuserid: -1, updateuserid: -1), + .init(id: 4, name: "Equals", description: "must be equal", createuserid: -1, updateuserid: -1), + .init(id: 5, name: "Variance", description: "must be between the base plus or minus a variance", createuserid: -1, updateuserid: -1) + ] + return cts.map { ct in + ct.save(on: database) + } + .flatten(on: database.eventLoop) + } + + func revert(on database: Database) -> EventLoopFuture { + mdlComparisonType.query(on: database).delete() + } + + + } +} + diff --git a/Sources/App/Models/BaseTables/mdlContactType.swift b/Sources/App/Models/BaseTables/mdlContactType.swift index 6f0e740..7bcfb77 100644 --- a/Sources/App/Models/BaseTables/mdlContactType.swift +++ b/Sources/App/Models/BaseTables/mdlContactType.swift @@ -1,8 +1,81 @@ // -// File.swift -// +// mdlContactType.swift // -// Created by Michiel Carman on 1/26/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlContactType: Model, Content { + static let schema = "contactType" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + @Field(key: "isActive") var isactive: Bool? + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.description = description + self.isactive = isactive + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlContactType{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("contactType") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("contactType").delete() + } + } + struct Seed: Migration{ + func prepare(on database: Database) -> EventLoopFuture { + let mdls: [mdlContactType] = [ + .init(id: nil, name: "Address", description: nil, isactive: true, createuserid: -1, updateuserid: -1), + .init(id: nil, name: "Email", description: nil, isactive: true, createuserid: -1, updateuserid: -1), + .init(id: nil, name: "Phone", description: nil, isactive: true, createuserid: -1, updateuserid: -1), + .init(id: nil, name: "Fax", description: nil, isactive: true, createuserid: -1, updateuserid: -1) + ] + return mdls.map { mdl in + mdl.save(on: database) + } + .flatten(on: database.eventLoop) + } + + func revert(on database: Database) -> EventLoopFuture { + mdlContactType.query(on: database).delete() + } + } +} + + + diff --git a/Sources/App/Models/BaseTables/mdlDataType.swift b/Sources/App/Models/BaseTables/mdlDataType.swift index a2029e5..c14a174 100644 --- a/Sources/App/Models/BaseTables/mdlDataType.swift +++ b/Sources/App/Models/BaseTables/mdlDataType.swift @@ -1,8 +1,79 @@ // -// File.swift -// +// ComparisonType.swift // -// Created by Michiel Carman on 1/25/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlDataType: Model, Content { + static let schema = "dataType" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + + @Children(for: \.$datatype) var units: [mdlUnit] + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.description = description + + + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} +extension mdlDataType{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("dataType") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("dataType").delete() + } + } + struct Seed: Migration{ + func prepare(on database: Database) -> EventLoopFuture { + let mdls: [mdlDataType] = [ + .init(id: 1, name: "String", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 2, name: "Integer", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 3, name: "Decimal", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 4, name: "Date Time", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 5, name: "Boolean", description: nil, createuserid: -1, updateuserid: -1) + ] + return mdls.map { mdl in + mdl.save(on: database) + } + .flatten(on: database.eventLoop) + } + + func revert(on database: Database) -> EventLoopFuture { + mdlDataType.query(on: database).delete() + } + } +} diff --git a/Sources/App/Models/BaseTables/mdlDivision.swift b/Sources/App/Models/BaseTables/mdlDivision.swift index 93ed217..d626fb6 100644 --- a/Sources/App/Models/BaseTables/mdlDivision.swift +++ b/Sources/App/Models/BaseTables/mdlDivision.swift @@ -19,6 +19,9 @@ final class mdlDivision: Model, Content { @Field(key: "description") var description: String? @Field(key: "isActive") var isactive: Bool? + @Children(for: \.$division) var users: [mdlUser] + + @Timestamp(key: "createDate", on: .create) var createdate: Date? @Field(key: "createUserId") var createuserid: Int? @Timestamp(key: "updateDate", on: .update) var updatedate: Date? diff --git a/Sources/App/Models/BaseTables/mdlEquipmentType.swift b/Sources/App/Models/BaseTables/mdlEquipmentType.swift index a843f95..87aaade 100644 --- a/Sources/App/Models/BaseTables/mdlEquipmentType.swift +++ b/Sources/App/Models/BaseTables/mdlEquipmentType.swift @@ -1,8 +1,74 @@ // -// File.swift -// +// EquipmentType.swift // -// Created by Michiel Carman on 1/31/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlEquipmentType: Model, Content { + static let schema = "equipmentType" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + @Field(key: "isActive") var isactive: Bool? + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + self.name = name + self.description = description + self.isactive = isactive + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlEquipmentType{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("equipmentType") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("equipmentType").delete() + } + } + struct Seed: Migration{ + func prepare(on database: Database) -> EventLoopFuture { + let mdls: [mdlEquipmentType] = [ + .init(id: nil, name: "Prime", description: nil, createuserid: -1, updateuserid: -1), + .init(id: nil, name: "Attachment", description: nil, createuserid: -1, updateuserid: -1) + ] + return mdls.map { mdl in + mdl.save(on: database) + } + .flatten(on: database.eventLoop) + } + + func revert(on database: Database) -> EventLoopFuture { + mdlEquipmentType.query(on: database).delete() + } + } +} diff --git a/Sources/App/Models/BaseTables/mdlFuel.swift b/Sources/App/Models/BaseTables/mdlFuel.swift index 4b56074..67e8a90 100644 --- a/Sources/App/Models/BaseTables/mdlFuel.swift +++ b/Sources/App/Models/BaseTables/mdlFuel.swift @@ -20,6 +20,8 @@ final class mdlFuel: Model, Content { @Field(key: "sortOrder") var sortorder: Int? @Field(key: "isActive") var isactive: Bool? + @Children(for: \.$fuel) var workorders: [mdlWorkOrder] + @Timestamp(key: "createDate", on: .create) var createdate: Date? @Field(key: "createUserId") var createuserid: Int? @Timestamp(key: "updateDate", on: .update) var updatedate: Date? diff --git a/Sources/App/Models/BaseTables/mdlGate.swift b/Sources/App/Models/BaseTables/mdlGate.swift index 6f0e740..c07ec71 100644 --- a/Sources/App/Models/BaseTables/mdlGate.swift +++ b/Sources/App/Models/BaseTables/mdlGate.swift @@ -1,8 +1,66 @@ // -// File.swift -// -// -// Created by Michiel Carman on 1/26/24. -// + // mdlGate.swift + // + // + // Created by Michiel Carman on 1/24/24. + // + + import Fluent + import Vapor + import Foundation + import FluentKit + + final class mdlGate: Model, Content { + static let schema = "gate" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + @Field(key: "isActive") var isactive: Bool? + + @Children(for: \.$gate) var users: [mdlUser] + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.description = description + self.isactive = isactive + + self.createuserid = createuserid + self.updateuserid = updateuserid + } + } + + extension mdlGate{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("gate") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("gate").delete() + } + } + } + + + -import Foundation diff --git a/Sources/App/Models/BaseTables/mdlIncompleteReason.swift b/Sources/App/Models/BaseTables/mdlIncompleteReason.swift index 8364f18..d959135 100644 --- a/Sources/App/Models/BaseTables/mdlIncompleteReason.swift +++ b/Sources/App/Models/BaseTables/mdlIncompleteReason.swift @@ -19,6 +19,8 @@ final class mdlIncompleteReason: Model, Content { @Field(key: "description") var description: String? @Field(key: "isActive") var isactive: Bool? + @Children(for: \.$incompletereason) var workorders: [mdlWorkOrder] + @Timestamp(key: "createDate", on: .create) var createdate: Date? @Field(key: "createUserId") var createuserid: Int? @Timestamp(key: "updateDate", on: .update) var updatedate: Date? diff --git a/Sources/App/Models/BaseTables/mdlInputType.swift b/Sources/App/Models/BaseTables/mdlInputType.swift index a2029e5..7432016 100644 --- a/Sources/App/Models/BaseTables/mdlInputType.swift +++ b/Sources/App/Models/BaseTables/mdlInputType.swift @@ -1,8 +1,76 @@ // -// File.swift -// +// mdlInputType.swift // -// Created by Michiel Carman on 1/25/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlInputType: Model, Content { + static let schema = "inputType" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.description = description + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} +extension mdlInputType{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("inputType") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("inputType").delete() + } + } + struct Seed: Migration{ + func prepare(on database: Database) -> EventLoopFuture { + let mdls: [mdlInputType] = [ + .init(id: 1, name: "None", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 2, name: "Radio Button List", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 3, name: "Dropdown List", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 4, name: "Freeform", description: nil, createuserid: -1, updateuserid: -1) + ] + return mdls.map { mdl in + mdl.save(on: database) + } + .flatten(on: database.eventLoop) + } + + func revert(on database: Database) -> EventLoopFuture { + mdlInputType.query(on: database).delete() + } + + + } +} diff --git a/Sources/App/Models/BaseTables/mdlJobSite.swift b/Sources/App/Models/BaseTables/mdlJobSite.swift index a2029e5..0f496ff 100644 --- a/Sources/App/Models/BaseTables/mdlJobSite.swift +++ b/Sources/App/Models/BaseTables/mdlJobSite.swift @@ -1,8 +1,78 @@ // -// File.swift -// +// mdlJobSite.swift // -// Created by Michiel Carman on 1/25/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlJobSite: Model, Content { + static let schema = "jobSite" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + @Field(key: "sortOrder") var sortorder: Int? + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, sortorder: Int? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.description = description + self.sortorder = sortorder + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlJobSite{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("jobSite") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("sortOrder", .int) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("jobSite").delete() + } + } + struct Seed: Migration{ + func prepare(on database: Database) -> EventLoopFuture { + let mdls: [mdlJobSite] = [ + .init(id: 1, name: "HEAVY", description: "Heavy usage, difficult terrain/material", sortorder: 1, createuserid: -1, updateuserid: -1), + .init(id: 2, name: "MEDIUM", description: "Average usage, terrain/material", sortorder: 2, createuserid: -1, updateuserid: -1), + .init(id: 3, name: "LIGHT", description: "Light usage, easy terrain/material", sortorder: 3, createuserid: -1, updateuserid: -1) + ] + return mdls.map { mdl in + mdl.save(on: database) + } + .flatten(on: database.eventLoop) + } + + func revert(on database: Database) -> EventLoopFuture { + mdlJobSite.query(on: database).delete() + } + } +} + diff --git a/Sources/App/Models/BaseTables/mdlLocation.swift b/Sources/App/Models/BaseTables/mdlLocation.swift index 9a012d5..e5334ef 100644 --- a/Sources/App/Models/BaseTables/mdlLocation.swift +++ b/Sources/App/Models/BaseTables/mdlLocation.swift @@ -24,9 +24,12 @@ final class mdlLocation: Model, Content { @Field(key: "fileLocation") var filelocation: String? @Field(key: "isAcrtive") var isactive: Bool? @Parent(key: "stateId") var state: mdlState + @OptionalParent(key: "unitId") var unit: mdlUnit? @OptionalParent(key: "labSettingId") var labsetting: mdlLabSetting? + @Children(for: \.$location) var users: [mdlUser] + @Timestamp(key: "createDate", on: .create) var createdate: Date? @Field(key: "createUserId") var createuserid: Int? diff --git a/Sources/App/Models/BaseTables/mdlPriority.swift b/Sources/App/Models/BaseTables/mdlPriority.swift index a2029e5..b36159a 100644 --- a/Sources/App/Models/BaseTables/mdlPriority.swift +++ b/Sources/App/Models/BaseTables/mdlPriority.swift @@ -1,8 +1,81 @@ // -// File.swift -// +// mdlPriority.swift // -// Created by Michiel Carman on 1/25/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlPriority: Model, Content { + static let schema = "priority" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + + @Children(for: \.$priority) var workorders: [mdlWorkOrder] + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.description = description + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlPriority{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("priority") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("priority").delete() + } + } + struct Seed: Migration{ + func prepare(on database: Database) -> EventLoopFuture { + let mdls: [mdlPriority] = [ + .init(id: 1, name: "Urgent", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 2, name: "High", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 3, name: "Medium", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 4, name: "Low", description: nil, createuserid: -1, updateuserid: -1) + ] + return mdls.map { mdl in + mdl.save(on: database) + } + .flatten(on: database.eventLoop) + } + + func revert(on database: Database) -> EventLoopFuture { + mdlPriority.query(on: database).delete() + } + + + } +} + + diff --git a/Sources/App/Models/BaseTables/mdlReason.swift b/Sources/App/Models/BaseTables/mdlReason.swift index 6f0e740..7faf0a5 100644 --- a/Sources/App/Models/BaseTables/mdlReason.swift +++ b/Sources/App/Models/BaseTables/mdlReason.swift @@ -1,8 +1,65 @@ // -// File.swift -// +// mdlReason.swift // -// Created by Michiel Carman on 1/26/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlReason: Model, Content { + static let schema = "reason" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + @Field(key: "isActive") var isactive: Bool? + + @Children(for: \.$reason) var workorders: [mdlWorkOrder] + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.description = description + self.isactive = isactive + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlReason{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("reason") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("reason").delete() + } + } +} + + + diff --git a/Sources/App/Models/BaseTables/mdlRepairType.swift b/Sources/App/Models/BaseTables/mdlRepairType.swift index a2029e5..2717b79 100644 --- a/Sources/App/Models/BaseTables/mdlRepairType.swift +++ b/Sources/App/Models/BaseTables/mdlRepairType.swift @@ -1,8 +1,85 @@ // -// File.swift -// +// mdlRepairType.swift // -// Created by Michiel Carman on 1/25/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlRepairType: Model, Content { + static let schema = "repairType" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + @Field(key: "color") var color: String? + + @Children(for: \.$repairtype) var units: [mdlResponseType] + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, color: String? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.description = description + self.color = color + + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} +extension mdlRepairType{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("repairType") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("color", .string) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("repairType").delete() + } + } + struct Seed: Migration{ + func prepare(on database: Database) -> EventLoopFuture { + let mdls: [mdlRepairType] = [ + .init(id: 1, name: "None", description: nil, color: "#000000", createuserid: -1, updateuserid: -1), + .init(id: 2, name: "Recommended", description: nil, color: "#FFCC00", createuserid: -1, updateuserid: -1), + .init(id: 3, name: "Urgent", description: nil, color: "#FF0000", createuserid: -1, updateuserid: -1), + .init(id: 4, name: "NA", description: nil, color: "#000000", createuserid: -1, updateuserid: -1) + ] + return mdls.map { mdl in + mdl.save(on: database) + } + .flatten(on: database.eventLoop) + } + + func revert(on database: Database) -> EventLoopFuture { + mdlRepairType.query(on: database).delete() + } + + + } +} + + + diff --git a/Sources/App/Models/BaseTables/mdlSMSCCode.swift b/Sources/App/Models/BaseTables/mdlSMSCCode.swift index a843f95..8762925 100644 --- a/Sources/App/Models/BaseTables/mdlSMSCCode.swift +++ b/Sources/App/Models/BaseTables/mdlSMSCCode.swift @@ -1,8 +1,63 @@ // -// File.swift -// +// mdlSMSCCode.swift // -// Created by Michiel Carman on 1/31/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlSMSCCode: Model, Content { + static let schema = "smscCode" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + @Field(key: "isActive") var isactive: Bool? + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.description = description + self.isactive = isactive + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlSMSCCode{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("smscCode") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("smscCode").delete() + } + } +} + + + diff --git a/Sources/App/Models/BaseTables/mdlSignatureType.swift b/Sources/App/Models/BaseTables/mdlSignatureType.swift index 6f0e740..6d7c5cc 100644 --- a/Sources/App/Models/BaseTables/mdlSignatureType.swift +++ b/Sources/App/Models/BaseTables/mdlSignatureType.swift @@ -1,8 +1,63 @@ // -// File.swift -// +// mdlSignatureType.swift // -// Created by Michiel Carman on 1/26/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlSignatureType: Model, Content { + static let schema = "signatureType" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + @Field(key: "isActive") var isactive: Bool? + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.description = description + self.isactive = isactive + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlSignatureType{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("signatureType") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("signatureType").delete() + } + } +} + + + diff --git a/Sources/App/Models/BaseTables/mdlState.swift b/Sources/App/Models/BaseTables/mdlState.swift index a2029e5..c0ece45 100644 --- a/Sources/App/Models/BaseTables/mdlState.swift +++ b/Sources/App/Models/BaseTables/mdlState.swift @@ -1,8 +1,133 @@ // -// File.swift -// +// mdlState.swift // -// Created by Michiel Carman on 1/25/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlState: Model, Content { + static let schema = "state" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "abreviation") var abreviation: String? + + @Children(for: \.$state) var locations: [mdlLocation] + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + + + init() { } + + init(id: Int? = nil, name: String? = nil, abreviation: String? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.abreviation = abreviation + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlState{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("state") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("abreviation", .string) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("state").delete() + } + } + struct Seed: Migration{ + func prepare(on database: Database) -> EventLoopFuture { + let mdls: [mdlState] = [ + .init(id: 1, name: "Alabama", abreviation: "AL", createuserid: -1, updateuserid: -1), + .init(id: 2, name: "Alaska", abreviation: "AK", createuserid: -1, updateuserid: -1), + .init(id: 3, name: "Arizona", abreviation: "AZ", createuserid: -1, updateuserid: -1), + .init(id: 4, name: "Arkansas", abreviation: "AR", createuserid: -1, updateuserid: -1), + .init(id: 5, name: "California", abreviation: "CA", createuserid: -1, updateuserid: -1), + .init(id: 6, name: "Colorado", abreviation: "CO", createuserid: -1, updateuserid: -1), + .init(id: 7, name: "Connecticut", abreviation: "CT", createuserid: -1, updateuserid: -1), + .init(id: 8, name: "Deleware", abreviation: "DE", createuserid: -1, updateuserid: -1), + .init(id: 9, name: "Florida", abreviation: "FL", createuserid: -1, updateuserid: -1), + .init(id: 10, name: "Georgia", abreviation: "GA", createuserid: -1, updateuserid: -1), + .init(id: 11, name: "Hawaii", abreviation: "HI", createuserid: -1, updateuserid: -1), + .init(id: 12, name: "Idaho", abreviation: "ID", createuserid: -1, updateuserid: -1), + .init(id: 13, name: "Illinois", abreviation: "IL", createuserid: -1, updateuserid: -1), + .init(id: 14, name: "Indiana", abreviation: "IN", createuserid: -1, updateuserid: -1), + .init(id: 15, name: "Iowa", abreviation: "IA", createuserid: -1, updateuserid: -1), + .init(id: 16, name: "Kansas", abreviation: "KS", createuserid: -1, updateuserid: -1), + .init(id: 17, name: "Kentucky", abreviation: "KY", createuserid: -1, updateuserid: -1), + .init(id: 18, name: "Louisiana", abreviation: "LA", createuserid: -1, updateuserid: -1), + .init(id: 19, name: "Maine", abreviation: "ME", createuserid: -1, updateuserid: -1), + .init(id: 20, name: "Maryland", abreviation: "MD", createuserid: -1, updateuserid: -1), + .init(id: 21, name: "Massachusetts", abreviation: "MA", createuserid: -1, updateuserid: -1), + .init(id: 22, name: "Michigan", abreviation: "MI", createuserid: -1, updateuserid: -1), + .init(id: 23, name: "Minnesota", abreviation: "MN", createuserid: -1, updateuserid: -1), + .init(id: 24, name: "Mississippi", abreviation: "MS", createuserid: -1, updateuserid: -1), + .init(id: 25, name: "Missouri", abreviation: "MO", createuserid: -1, updateuserid: -1), + .init(id: 26, name: "Montana", abreviation: "MT", createuserid: -1, updateuserid: -1), + .init(id: 27, name: "Nebraska", abreviation: "NE", createuserid: -1, updateuserid: -1), + .init(id: 28, name: "Nevada", abreviation: "NV", createuserid: -1, updateuserid: -1), + .init(id: 29, name: "New Hampshire", abreviation: "NH", createuserid: -1, updateuserid: -1), + .init(id: 30, name: "New Jersey", abreviation: "NJ", createuserid: -1, updateuserid: -1), + .init(id: 31, name: "New Mexico", abreviation: "NM", createuserid: -1, updateuserid: -1), + .init(id: 32, name: "New York", abreviation: "NY", createuserid: -1, updateuserid: -1), + .init(id: 33, name: "North Carolina", abreviation: "NC", createuserid: -1, updateuserid: -1), + .init(id: 34, name: "North Dakota", abreviation: "ND", createuserid: -1, updateuserid: -1), + .init(id: 35, name: "Ohio", abreviation: "OH", createuserid: -1, updateuserid: -1), + .init(id: 36, name: "Oklahoma", abreviation: "OK", createuserid: -1, updateuserid: -1), + .init(id: 37, name: "Oregon", abreviation: "OR", createuserid: -1, updateuserid: -1), + .init(id: 38, name: "Pennsylvania", abreviation: "PA", createuserid: -1, updateuserid: -1), + .init(id: 39, name: "Rhode Island", abreviation: "RI", createuserid: -1, updateuserid: -1), + .init(id: 40, name: "South Carolina", abreviation: "SC", createuserid: -1, updateuserid: -1), + .init(id: 41, name: "South Dakota", abreviation: "SD", createuserid: -1, updateuserid: -1), + .init(id: 42, name: "Tennessee", abreviation: "TN", createuserid: -1, updateuserid: -1), + .init(id: 43, name: "Texas", abreviation: "TX", createuserid: -1, updateuserid: -1), + .init(id: 44, name: "Utah", abreviation: "UT", createuserid: -1, updateuserid: -1), + .init(id: 45, name: "Vermont", abreviation: "VT", createuserid: -1, updateuserid: -1), + .init(id: 46, name: "Virginia", abreviation: "VA", createuserid: -1, updateuserid: -1), + .init(id: 47, name: "Washington", abreviation: "WA", createuserid: -1, updateuserid: -1), + .init(id: 48, name: "West Virginia", abreviation: "WV", createuserid: -1, updateuserid: -1), + .init(id: 49, name: "Wisconsin", abreviation: "WI", createuserid: -1, updateuserid: -1), + .init(id: 50, name: "Wyoming", abreviation: "WY", createuserid: -1, updateuserid: -1) + ] + return mdls.map { mdl in + mdl.save(on: database) + } + .flatten(on: database.eventLoop) + } + + func revert(on database: Database) -> EventLoopFuture { + mdlState.query(on: database).delete() + } + + + } +} + + + + + + diff --git a/Sources/App/Models/BaseTables/mdlStatus.swift b/Sources/App/Models/BaseTables/mdlStatus.swift index a2029e5..39df050 100644 --- a/Sources/App/Models/BaseTables/mdlStatus.swift +++ b/Sources/App/Models/BaseTables/mdlStatus.swift @@ -1,8 +1,86 @@ // -// File.swift -// +// mdlStatus.swift // -// Created by Michiel Carman on 1/25/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlStatus: Model, Content { + static let schema = "status" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + + @Children(for: \.$status) var workorders: [mdlWorkOrder] + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.description = description + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlStatus{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("status") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("status").delete() + } + } + struct Seed: Migration{ + func prepare(on database: Database) -> EventLoopFuture { + let mdls: [mdlStatus] = [ + .init(id: 1, name: "Open", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 2, name: "Synced", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 3, name: "Completed", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 4, name: "Approved", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 5, name: "Incomplete", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 6, name: "Reassigned", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 7, name: "Pending", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 8, name: "Deleted", description: nil, createuserid: -1, updateuserid: -1) + ] + return mdls.map { mdl in + mdl.save(on: database) + } + .flatten(on: database.eventLoop) + } + + func revert(on database: Database) -> EventLoopFuture { + mdlStatus.query(on: database).delete() + } + + + } +} + + + diff --git a/Sources/App/Models/BaseTables/mdlValueType.swift b/Sources/App/Models/BaseTables/mdlValueType.swift index a2029e5..8daab34 100644 --- a/Sources/App/Models/BaseTables/mdlValueType.swift +++ b/Sources/App/Models/BaseTables/mdlValueType.swift @@ -1,8 +1,80 @@ // -// File.swift -// +// mdlValueType.swift // -// Created by Michiel Carman on 1/25/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlValueType: Model, Content { + static let schema = "valueType" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.description = description + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlValueType{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("valueType") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("valueType").delete() + } + } + struct Seed: Migration{ + func prepare(on database: Database) -> EventLoopFuture { + let mdls: [mdlValueType] = [ + .init(id: 1, name: "Base", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 2, name: "Max", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 3, name: "Min", description: nil, createuserid: -1, updateuserid: -1), + .init(id: 4, name: "Variance", description: nil, createuserid: -1, updateuserid: -1) + ] + return mdls.map { mdl in + mdl.save(on: database) + } + .flatten(on: database.eventLoop) + } + + func revert(on database: Database) -> EventLoopFuture { + mdlValueType.query(on: database).delete() + } + + + } +} + + + diff --git a/Sources/App/Models/BaseTables/mdlViscosity.swift b/Sources/App/Models/BaseTables/mdlViscosity.swift index 6f0e740..89ce6e0 100644 --- a/Sources/App/Models/BaseTables/mdlViscosity.swift +++ b/Sources/App/Models/BaseTables/mdlViscosity.swift @@ -1,8 +1,63 @@ // -// File.swift -// +// mdlViscosity.swift // -// Created by Michiel Carman on 1/26/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlViscosity: Model, Content { + static let schema = "viscosity" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + @Field(key: "isActive") var isactive: Bool? + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.description = description + self.isactive = isactive + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlViscosity{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("viscosity") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("viscosity").delete() + } + } +} + + + diff --git a/Sources/App/Models/CompartmentModule/mdlCompartment.swift b/Sources/App/Models/CompartmentModule/mdlCompartment.swift index 2db5a50..b782578 100644 --- a/Sources/App/Models/CompartmentModule/mdlCompartment.swift +++ b/Sources/App/Models/CompartmentModule/mdlCompartment.swift @@ -7,8 +7,10 @@ import Fluent import Vapor +import Foundation +import FluentKit -final class Compartment: Model, Content { +final class mdlCompartment: Model, Content { static let schema = "compartment" @ID(custom: "id", generatedBy: .database) var id: Int? @@ -39,3 +41,25 @@ final class Compartment: Model, Content { self.updateuserid = updateuserid } } +extension mdlCompartment{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("compartment") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("code", .string) + .field("sortOrder", .int) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("compartment").delete() + } + } +} diff --git a/Sources/App/Models/CompartmentModule/mdlCompartmentLocation.swift b/Sources/App/Models/CompartmentModule/mdlCompartmentLocation.swift index 9a43532..3337fb8 100644 --- a/Sources/App/Models/CompartmentModule/mdlCompartmentLocation.swift +++ b/Sources/App/Models/CompartmentModule/mdlCompartmentLocation.swift @@ -4,11 +4,12 @@ // // Created by Michiel Carman on 1/24/24. // - import Fluent import Vapor +import Foundation +import FluentKit -final class CompartmentLocation: Model, Content { +final class mdlCompartmentLocation: Model, Content { static let schema = "compartmentLocation" @ID(custom: "id", generatedBy: .database) var id: Int? @@ -39,3 +40,27 @@ final class CompartmentLocation: Model, Content { self.updateuserid = updateuserid } } +extension mdlCompartmentLocation{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("compartmentLocation") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("code", .string) + .field("sortOrder", .int) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("compartmentLocation").delete() + } + } + + +} diff --git a/Sources/App/Models/CustomerTables/mdlContact.swift b/Sources/App/Models/CustomerTables/mdlContact.swift index 6f0e740..279d1ae 100644 --- a/Sources/App/Models/CustomerTables/mdlContact.swift +++ b/Sources/App/Models/CustomerTables/mdlContact.swift @@ -1,8 +1,80 @@ // -// File.swift -// +// mdlContact.swift // -// Created by Michiel Carman on 1/26/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlContact: Model, Content { + static let schema = "contact" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "firstName") var firstname: String? + @Field(key: "lastName") var lastname: String? + @Field(key: "description") var description: String? + @Field(key: "isActive") var isactive: Bool? + + @Parent(key: "customerId") var customer: mdlCustomer + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, firstname: String? = nil, lastname: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil, customerid: Int? = nil) { + self.id = id + + self.firstname = firstname + self.lastname = lastname + self.isactive = isactive + self.$customer.$id.value = customerid! + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlContact{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("contact") + .field("id", .int, .identifier(auto: true)) + .field("firstName", .string) + .field("lastName", .string) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("contact").delete() + } + } + struct makeParentCustomer: AsyncMigration{ + func prepare(on database: Database) async throws { + try await database.schema("contact") + .field("customerId", .int, .references("customer", "id")) + .update() + } + + func revert(on database: Database) async throws { + try await database.schema("contact") + .deleteField("customerId" ) + .update() + } + } +} + + + diff --git a/Sources/App/Models/CustomerTables/mdlContactInfo.swift b/Sources/App/Models/CustomerTables/mdlContactInfo.swift index 6f0e740..7f21a39 100644 --- a/Sources/App/Models/CustomerTables/mdlContactInfo.swift +++ b/Sources/App/Models/CustomerTables/mdlContactInfo.swift @@ -1,8 +1,66 @@ // -// File.swift -// +// mdlContactInfo.swift // -// Created by Michiel Carman on 1/26/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlContactInfo: Model, Content { + static let schema = "contactInfo" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "value") var value: String? + @Field(key: "isActive") var isactive: Bool? + + @Parent(key: "contactTypeId") var contacttype: mdlContactType + + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, value: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil, contacttypeid: Int? = nil) { + self.id = id + + self.value = value + self.isactive = isactive + + self.$contacttype.$id.value = contacttypeid! + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlContactInfo{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("contactInfo") + .field("id", .int, .identifier(auto: true)) + .field("value", .string) + .field("isActive", .bool) + .field("contactTypeId", .int, .references("contactType", "id")) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("contactInfo").delete() + } + } +} + + + diff --git a/Sources/App/Models/CustomerTables/mdlCustomer.swift b/Sources/App/Models/CustomerTables/mdlCustomer.swift index 6f0e740..55e7612 100644 --- a/Sources/App/Models/CustomerTables/mdlCustomer.swift +++ b/Sources/App/Models/CustomerTables/mdlCustomer.swift @@ -1,8 +1,65 @@ // -// File.swift -// +// mdlCustomer.swift // -// Created by Michiel Carman on 1/26/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlCustomer: Model, Content { + static let schema = "customer" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "number") var number: String? + @Field(key: "isActive") var isactive: Bool? + + @Children(for: \.$customer) var contacts: [mdlContact] + @Children(for: \.$customer) var workorders: [mdlWorkOrder] + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, number: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.number = number + self.isactive = isactive + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlCustomer{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("customer") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("number", .string) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("customer").delete() + } + } +} + + + diff --git a/Sources/App/Models/CustomerTables/mdlEquipment.swift b/Sources/App/Models/CustomerTables/mdlEquipment.swift index a843f95..d3ce37e 100644 --- a/Sources/App/Models/CustomerTables/mdlEquipment.swift +++ b/Sources/App/Models/CustomerTables/mdlEquipment.swift @@ -1,8 +1,87 @@ // -// File.swift -// +// mdlEquipment.swift // -// Created by Michiel Carman on 1/31/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlEquipment: Model, Content { + static let schema = "equipment" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "number") var number: String? + @Field(key: "isActive") var isactive: Bool? + + @OptionalParent(key: "customerId") var customer: mdlCustomer? + @Parent(key: "modelId") var model: mdlModel + @Parent(key: "equipmentTypeId") var equipmenttype: mdlEquipmentType + @OptionalParent(key: "parentId") var parent: mdlEquipment? + + @Children(for: \.$equipment) var properties: [mdlObjProperty] + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, number: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil, customerid: Int? = nil, modelid: Int? = nil, equipmenttypeid: Int? = nil, parentid: Int? = nil) { + self.id = id + + self.number = number + self.isactive = isactive + self.$customer.$id.value = customerid! + self.$model.$id.value = modelid! + self.$equipmenttype.$id.value = equipmenttypeid! + self.$parent.$id.value = parentid + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlEquipment{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("equipment") + .field("id", .int, .identifier(auto: true)) + .field("number", .string) + .field("isActive", .bool) + .field("customerId", .int, .references("customer", "id")) + .field("modelId", .int, .references("model", "id")) + .field("equipmentTypeId", .int, .references("equipmentType", "id")) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("equipment").delete() + } + } + struct AddParent: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("equipment") + .field("parentId", .int, .references("equipment", "id")) + .update() + } + + func revert(on database: Database) async throws { + try await database.schema("equipment") + .deleteField("parentId") + .update() + } + } +} + + + diff --git a/Sources/App/Models/CustomerTables/mdlMake.swift b/Sources/App/Models/CustomerTables/mdlMake.swift index a843f95..1bdc4e4 100644 --- a/Sources/App/Models/CustomerTables/mdlMake.swift +++ b/Sources/App/Models/CustomerTables/mdlMake.swift @@ -1,8 +1,63 @@ // -// File.swift -// +// mdlMake.swift // -// Created by Michiel Carman on 1/31/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlMake: Model, Content { + static let schema = "make" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + @Field(key: "isActive") var isactive: Bool? + + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.description = description + self.isactive = isactive + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlMake{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("make") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("make").delete() + } + } +} + + + diff --git a/Sources/App/Models/CustomerTables/mdlModel.swift b/Sources/App/Models/CustomerTables/mdlModel.swift index a843f95..35b4ab0 100644 --- a/Sources/App/Models/CustomerTables/mdlModel.swift +++ b/Sources/App/Models/CustomerTables/mdlModel.swift @@ -1,8 +1,71 @@ // -// File.swift -// +// mdlModel.swift // -// Created by Michiel Carman on 1/31/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlModel: Model, Content { + static let schema = "model" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + @Field(key: "isActive") var isactive: Bool? + + @Parent(key: "productId") var product: mdlProduct + @Parent(key: "makeId") var make: mdlMake + + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil, productid: Int? = nil, makeid: Int? = nil) { + self.id = id + self.name = name + self.description = description + self.isactive = isactive + + self.$product.$id.value = productid! + self.$make.$id.value = makeid! + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlModel{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("model") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("productId", .int, .references("product", "id")) + .field("makeId", .int, .references("make", "id")) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("model").delete() + } + } +} + + + diff --git a/Sources/App/Models/CustomerTables/mdlObjectProperty.swift b/Sources/App/Models/CustomerTables/mdlObjectProperty.swift index a843f95..4b478c8 100644 --- a/Sources/App/Models/CustomerTables/mdlObjectProperty.swift +++ b/Sources/App/Models/CustomerTables/mdlObjectProperty.swift @@ -1,8 +1,66 @@ // -// File.swift -// +// mdlObjProperty.swift // -// Created by Michiel Carman on 1/31/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlObjProperty: Model, Content { + static let schema = "objProperty" + + @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: "equipmentId") var equipment: mdlEquipment + + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, label: String? = nil, value: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil, equipmentid: Int? = nil) { + self.id = id + self.label = label + self.value = value + self.isactive = isactive + self.$equipment.$id.value = equipmentid + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlObjProperty{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("objProperty") + .field("id", .int, .identifier(auto: true)) + .field("label", .string) + .field("value", .string) + .field("isActive", .bool) + .field("equipmentId", .int, .references("equipment", "id")) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("objProperty").delete() + } + } +} + + + diff --git a/Sources/App/Models/CustomerTables/mdlProduct.swift b/Sources/App/Models/CustomerTables/mdlProduct.swift index a843f95..e4db74e 100644 --- a/Sources/App/Models/CustomerTables/mdlProduct.swift +++ b/Sources/App/Models/CustomerTables/mdlProduct.swift @@ -1,8 +1,63 @@ // -// File.swift -// +// mdlProduct.swift // -// Created by Michiel Carman on 1/31/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlProduct: Model, Content { + static let schema = "product" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + @Field(key: "isActive") var isactive: Bool? + + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.description = description + self.isactive = isactive + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlProduct{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("product") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("product").delete() + } + } +} + + + diff --git a/Sources/App/Models/ItemTables/mdlItem.swift b/Sources/App/Models/ItemTables/mdlItem.swift index a843f95..accb038 100644 --- a/Sources/App/Models/ItemTables/mdlItem.swift +++ b/Sources/App/Models/ItemTables/mdlItem.swift @@ -1,8 +1,63 @@ // -// File.swift -// +// mdlItem.swift // -// Created by Michiel Carman on 1/31/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlItem: Model, Content { + static let schema = "item" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + @Field(key: "isActive") var isactive: Bool? + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.description = description + self.isactive = isactive + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlItem{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("item") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("item").delete() + } + } +} + + + diff --git a/Sources/App/Models/ItemTables/mdlItemResponseType.swift b/Sources/App/Models/ItemTables/mdlItemResponseType.swift index a843f95..d7c9e7f 100644 --- a/Sources/App/Models/ItemTables/mdlItemResponseType.swift +++ b/Sources/App/Models/ItemTables/mdlItemResponseType.swift @@ -1,8 +1,63 @@ // -// File.swift -// +// mdlItemResponseType.swift // -// Created by Michiel Carman on 1/31/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlItemResponseType: Model, Content { + static let schema = "itemResponseType" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Parent(key: "itemId") var item: mdlItem + @Parent(key: "responseTypeId") var responsetype: mdlResponseType + @Field(key: "isActive") var isactive: Bool? + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, itemid: Int? = nil, responsetypeid: Int? = nil, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.$item.$id.value = itemid! + self.$responsetype.$id.value = responsetypeid! + self.isactive = isactive + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlItemResponseType{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("itemResponseType") + .field("id", .int, .identifier(auto: true)) + .field("itemId", .int, .references("item", "id")) + .field("responseTypeId", .int, .references("responseType", "id")) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("itemResponseType").delete() + } + } +} + + + diff --git a/Sources/App/Models/LabTables/mdlLabSetting.swift b/Sources/App/Models/LabTables/mdlLabSetting.swift index 6f0e740..f9aee6d 100644 --- a/Sources/App/Models/LabTables/mdlLabSetting.swift +++ b/Sources/App/Models/LabTables/mdlLabSetting.swift @@ -1,8 +1,73 @@ // -// File.swift -// +// mdlLabSetting.swift // -// Created by Michiel Carman on 1/26/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlLabSetting: Model, Content { + static let schema = "labSetting" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "description") var description: String? + @Field(key: "barcodeDelimeter") var barcodedelimeter: String? + @Field(key: "barcodeActive") var barcodeactive: Bool? + @Field(key: "textActive") var textactive: Bool? + @Field(key: "logoActive") var logoactive: Bool? + + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, description: String? = nil, barcodedelimeter: String? = nil, barcodeactive: Bool? = nil, textactive: Bool? = nil, logoactive: Bool? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + + self.name = name + self.description = description + self.barcodedelimeter = barcodedelimeter + self.barcodeactive = barcodeactive + self.textactive = textactive + self.logoactive = logoactive + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlLabSetting{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("labSetting") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("description", .string) + .field("barcodeDelimeter", .string) + .field("barcodeActive", .bool) + .field("textActive", .bool) + .field("logoActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("labSetting").delete() + } + } +} + + + diff --git a/Sources/App/Models/LinkingTables/XFluidViscosity.swift b/Sources/App/Models/LinkingTables/XFluidViscosity.swift index a843f95..7ee419c 100644 --- a/Sources/App/Models/LinkingTables/XFluidViscosity.swift +++ b/Sources/App/Models/LinkingTables/XFluidViscosity.swift @@ -1,8 +1,67 @@ // -// File.swift -// +// XFluidViscosity.swift +// // // Created by Michiel Carman on 1/31/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlXFluidViscosity: Model, Content { + static let schema = "xFluidViscosity" + + @ID(custom: "id", generatedBy: .database) var id: Int? + @Parent(key: "userId") var user: mdlUser + @Parent(key: "roleId") var role: mdlRole + + @Field(key: "sortOrder") var sortorder: Int? + + + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init(){} + + init(id: Int? = nil, userid: Int, roleid: Int, sortorder: Int? = nil, createdate: Date? = nil, createuserid: Int? = nil, updatedate: Date? = nil, updateuserid: Int? = nil) { + self.id = id + self.user.$id.value = userid + self.role.$id.value = roleid + self.sortorder = sortorder + self.createdate = createdate + self.createuserid = createuserid + self.updatedate = updatedate + self.updateuserid = updateuserid + } + +} +extension mdlXFluidViscosity{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("xFluidViscosity") + .field("id", .int, .identifier(auto: true)) + .field("userId", .int, .references("user", "id")) + .field("roleid", .int, .references("role", "id")) + .field("sortOrder", .int) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("user").delete() + } + } + +} + + + + diff --git a/Sources/App/Models/LinkingTables/XUserRole.swift b/Sources/App/Models/LinkingTables/XUserRole.swift index a843f95..3c34cb8 100644 --- a/Sources/App/Models/LinkingTables/XUserRole.swift +++ b/Sources/App/Models/LinkingTables/XUserRole.swift @@ -1,8 +1,77 @@ // -// File.swift +// XUserRole.swift // // // Created by Michiel Carman on 1/31/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlXUserRole: Model, Content { + static let schema = "xUserRole" + + @ID(custom: "id", generatedBy: .database) var id: Int? + @Parent(key: "userId") var user: mdlUser + @Parent(key: "roleId") var role: mdlRole + + + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init(){} + + init(id: Int? = nil, userid: Int, roleid: Int, createdate: Date? = nil, createuserid: Int? = nil, updatedate: Date? = nil, updateuserid: Int? = nil) { + self.id = id + self.user.$id.value = userid + self.role.$id.value = roleid + self.createdate = createdate + self.createuserid = createuserid + self.updatedate = updatedate + self.updateuserid = updateuserid + } + +} +extension mdlXUserRole{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("xUserRole") + .field("id", .int, .identifier(auto: true)) + .field("userId", .int, .references("user", "id")) + .field("roleid", .int, .references("role", "id")) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("user").delete() + } + } + struct FixRoleId: AsyncMigration{ + func prepare(on database: Database) async throws{ + try await database.schema("xUserRole") + .deleteField("roleid") + .field("roleId", .int, .references("role", "id")) + .update() + } + func revert(on database: Database) async throws { + try await database.schema("xUserRole") + .deleteField("roleId") + .field("roleid", .int, .references("role", "id")) + .update() + } + } + +} + + + + diff --git a/Sources/App/Models/LinkingTables/XWorkOrderSegment.swift b/Sources/App/Models/LinkingTables/XWorkOrderSegment.swift index 676152d..9ef6735 100644 --- a/Sources/App/Models/LinkingTables/XWorkOrderSegment.swift +++ b/Sources/App/Models/LinkingTables/XWorkOrderSegment.swift @@ -1,8 +1,63 @@ // -// File.swift -// +// XWorkOrderSegment.swift // -// Created by Michiel Carman on 2/1/24. +// +// Created by Michiel Carman on 1/31/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlXWorkOrderSegment: Model, Content { + static let schema = "xWorkOrderSegment" + + @ID(custom: "id", generatedBy: .database) var id: Int? + @Parent(key: "workOrderId") var workorder: mdlWorkOrder + @Parent(key: "segmentId") var segment: mdlSegment + + + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init(){} + + init(id: Int? = nil, workorderid: Int, segmentid: Int, createdate: Date? = nil, createuserid: Int? = nil, updatedate: Date? = nil, updateuserid: Int? = nil) { + self.id = id + self.$workorder.$id.value = workorderid + self.$segment.$id.value = segmentid + self.createdate = createdate + self.createuserid = createuserid + self.updatedate = updatedate + self.updateuserid = updateuserid + } + +} +extension mdlXWorkOrderSegment{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("xWorkOrderSegment") + .field("id", .int, .identifier(auto: true)) + .field("workOrderId", .int, .references("workOrder", "id")) + .field("segmentId", .int, .references("segment", "id")) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("user").delete() + } + } + +} + + + + diff --git a/Sources/App/Models/OilSampleTables/mdlOilSample.swift b/Sources/App/Models/OilSampleTables/mdlOilSample.swift index 676152d..c5fb0c0 100644 --- a/Sources/App/Models/OilSampleTables/mdlOilSample.swift +++ b/Sources/App/Models/OilSampleTables/mdlOilSample.swift @@ -1,8 +1,110 @@ // -// File.swift -// +// OilSample.swift // -// Created by Michiel Carman on 2/1/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlOilSample: Model, Content { + static let schema = "oilSample" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Parent(key: "segmentId") var segment: mdlSegment + + @Field(key: "name") var name: String? + @Field(key: "code") var code: String? + @Field(key: "l1Name") var l1name: String? + @Field(key: "l1Code") var l1code: String? + @Field(key: "l2Name") var l2name: String? + @Field(key: "l2Code") var l2code: String? + @Field(key: "meterReading") var meterreading: Decimal? + @Field(key: "previousMeterReading") var previousmeterreading: Decimal? + @Field(key: "hoursOnOil") var hoursonoil: Decimal? + @Field(key: "oilAdded") var oiladded: Decimal? + @Field(key: "unit") var unit: String? + @Field(key: "jobSite") var jobsite: String? + @Field(key: "fluid") var fluid: String? + @Field(key: "viscosity") var viscosity: String? + @Field(key: "oilChanged") var oilchanged: Bool? + @Field(key: "filterChanged") var filterchanged: Bool? + @Field(key: "level") var level: String? + @Field(key: "comment") var comment: String? + @Field(key: "sortOrder") var sortorder: Int? + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, segmentid: Int? = nil, name: String? = nil, code: String? = nil, l1name: String? = nil, l1code: String? = nil, l2name: String? = nil, l2code: String? = nil, meterreading: Decimal? = nil, previousmeterreading: Decimal? = nil, hoursonoil: Decimal? = nil, oiladded: Decimal? = nil, unit: String? = nil, jobsite: String? = nil, fluid: String? = nil, viscosity: String? = nil, oilchanged: Bool? = nil, filterchanged: Bool? = nil, level: String? = nil, comment: String? = nil, sortorder: Int? = nil, createuserid: Int? = nil, updateuserid: Int? = nil) { + self.id = id + self.$segment.$id.value = segmentid! + self.name = name + self.code = code + self.l1name = l1name + self.l1code = l1code + self.l2name = l2name + self.l2code = l2code + self.meterreading = meterreading + self.previousmeterreading = previousmeterreading + self.hoursonoil = hoursonoil + self.oiladded = oiladded + self.unit = unit + self.jobsite = jobsite + self.fluid = fluid + self.viscosity = viscosity + self.oilchanged = oilchanged + self.filterchanged = filterchanged + self.level = level + self.comment = comment + self.sortorder = sortorder + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlOilSample{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("oilSample") + .field("id", .int, .identifier(auto: true)) + .field("segmentId", .int, .references("segment", "id")) + .field("name", .string) + .field("code", .string) + .field("l1Name", .string) + .field("l1Code", .string) + .field("l2Name", .string) + .field("l2Code", .string) + .field("meterReading", .float) + .field("previousMeterReading", .float) + .field("hoursOnOil", .float) + .field("oilAdded", .float) + .field("unit", .string) + .field("jobSite", .string) + .field("fluid", .string) + .field("viscosity", .string) + .field("oilChanged", .bool) + .field("filterChanged", .bool) + .field("level", .string) + .field("comment", .string) + + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("oilSample").delete() + } + } +} diff --git a/Sources/App/Models/SpecTables/mdlSpec.swift b/Sources/App/Models/SpecTables/mdlSpec.swift index a843f95..627e686 100644 --- a/Sources/App/Models/SpecTables/mdlSpec.swift +++ b/Sources/App/Models/SpecTables/mdlSpec.swift @@ -1,8 +1,68 @@ // -// File.swift -// +// mdlSpec.swift // -// Created by Michiel Carman on 1/31/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlSpec: Model, Content { + static let schema = "spec" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "numberOfTests") var numberoftests: Int? + @Field(key: "isActive") var isactive: Bool? + @Parent(key: "itemId") var item: mdlItem + + @Children(for: \.$spec) var specitems: [mdlSpecItem] + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, numberoftests: Int? = nil, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil, itemid: Int? = nil) { + self.id = id + + self.name = name + self.numberoftests = numberoftests + self.$item.$id.value = itemid! + self.isactive = isactive + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlSpec{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("spec") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("numberOfTests", .int) + .field("itemId", .int, .references("item", "id")) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("spec").delete() + } + } +} + + + diff --git a/Sources/App/Models/SpecTables/mdlSpecItem.swift b/Sources/App/Models/SpecTables/mdlSpecItem.swift index a843f95..77d397d 100644 --- a/Sources/App/Models/SpecTables/mdlSpecItem.swift +++ b/Sources/App/Models/SpecTables/mdlSpecItem.swift @@ -1,8 +1,78 @@ // -// File.swift -// +// mdlSpecItem.swift // -// Created by Michiel Carman on 1/31/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlSpecItem: Model, Content { + static let schema = "specItem" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "name") var name: String? + @Field(key: "qualifier") var qualifier: String? + @Field(key: "sortOrder") var sortorder: Int? + @Field(key: "isActive") var isactive: Bool? + @Parent(key: "specId") var spec: mdlSpec + @Parent(key: "comparisonTypeId") var comparisontype: mdlComparisonType + @Parent(key: "unitId") var unit: mdlUnit + + @Children(for: \.$specitem) var values: [mdlSpecItemValue] + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, name: String? = nil, qualifier: String? = nil, isactive: Bool? = true, createuserid: Int? = nil, sortorder: Int? = nil, updateuserid: Int? = nil, specid: Int? = nil, comparisontypeid: Int? = nil, unitid: Int? = nil) { + self.id = id + + self.name = name + self.qualifier = qualifier + self.sortorder = sortorder + self.$spec.$id.value = specid! + self.$comparisontype.$id.value = comparisontypeid! + self.$unit.$id.value = unitid! + + self.isactive = isactive + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlSpecItem{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("specItem") + .field("id", .int, .identifier(auto: true)) + .field("name", .string) + .field("qualifier", .string) + .field("sortOrder", .int) + .field("specId", .int, .references("spec", "id")) + .field("comparisonTypeId", .int, .references("comparisonType", "id")) + .field("unitId", .int, .references("unit", "id")) + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("specItem").delete() + } + } +} + + + diff --git a/Sources/App/Models/SpecTables/mdlSpecItemValue.swift b/Sources/App/Models/SpecTables/mdlSpecItemValue.swift index a843f95..3bb7322 100644 --- a/Sources/App/Models/SpecTables/mdlSpecItemValue.swift +++ b/Sources/App/Models/SpecTables/mdlSpecItemValue.swift @@ -1,8 +1,68 @@ // -// File.swift -// +// mdlSpecItemValue.swift // -// Created by Michiel Carman on 1/31/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlSpecItemValue: Model, Content { + static let schema = "specItemValue" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "value") var value: String? + @Field(key: "sortOrder") var sortorder: Int? + @Field(key: "isActive") var isactive: Bool? + @Parent(key: "specItemId") var specitem: mdlSpecItem + @Parent(key: "valueTypeId") var valuetype: mdlValueType + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil, value: String? = nil, sortorder: Int? = nil, isactive: Bool? = true, createuserid: Int? = nil, updateuserid: Int? = nil, specitemid: Int? = nil, valuetypeid: Int? = nil) { + self.id = id + + self.value = value + self.sortorder = sortorder + self.$specitem.$id.value = specitemid! + self.$valuetype.$id.value = valuetypeid! + self.isactive = isactive + + self.createuserid = createuserid + self.updateuserid = updateuserid + } +} + +extension mdlSpecItemValue{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("specItemValue") + .field("id", .int, .identifier(auto: true)) + .field("value", .string) + .field("sortOrder", .int) + .field("itemId", .int, .references("item", "id"))//need to fix + .field("isActive", .bool) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("specItemValue").delete() + } + } +} + + + diff --git a/Sources/App/Models/WorkOrderTables/mdlWorkOrder.swift b/Sources/App/Models/WorkOrderTables/mdlWorkOrder.swift index a843f95..88f281d 100644 --- a/Sources/App/Models/WorkOrderTables/mdlWorkOrder.swift +++ b/Sources/App/Models/WorkOrderTables/mdlWorkOrder.swift @@ -1,8 +1,122 @@ // -// File.swift -// +// mdlWorkOrder.swift // -// Created by Michiel Carman on 1/31/24. +// +// Created by Michiel Carman on 1/24/24. // +import Fluent +import Vapor import Foundation +import FluentKit + +final class mdlWorkOrder: Model, Content { + static let schema = "workOrder" + + @ID(custom: "id", generatedBy: .database) var id: Int? + + @Field(key: "number") var number: String? + @Field(key: "meterReading") var meterreading: Decimal? + @Field(key: "specialInstructions") var specialinstructions: String? + @Field(key: "scheduledStartDate") var scheduledstartdate: Date? + @Field(key: "scheduledEndDate") var scheduledenddate: Date? + @Field(key: "startDate") var startdate: Date? + @Field(key: "endDate") var enddate: Date? + @Field(key: "approvedDate") var approveddate: Date? + + @OptionalParent(key: "customerId") var customer: mdlCustomer? + @OptionalParent(key: "equipmentId") var equipment: mdlEquipment? + @OptionalParent(key: "statusId") var status: mdlStatus? + @OptionalParent(key: "priorityId") var priority: mdlPriority? + @OptionalParent(key: "technicianUserId") var technician: mdlUser? + @OptionalParent(key: "reasonId") var reason: mdlReason? + @OptionalParent(key: "incompleteReasonId") var incompletereason: mdlIncompleteReason? + @OptionalParent(key: "fuelId") var fuel: mdlFuel? + + @Siblings(through: mdlXWorkOrderSegment.self, from: \.$workorder, to: \.$segment) var segments: [mdlSegment] + + @Timestamp(key: "createDate", on: .create) var createdate: Date? + @Field(key: "createUserId") var createuserid: Int? + @Timestamp(key: "updateDate", on: .update) var updatedate: Date? + @Field(key: "updateUserId") var updateuserid: Int? + + init() { } + + init(id: Int? = nil + , number: String? = nil + , meterreading: Decimal? = nil + , specialinstructions: String? = nil + , scheduledstartdate: Date? = nil + , scheduledenddate: Date? = nil + , startdate: Date? = nil + , enddate: Date? = nil + , approveddate: Date? = nil + , customerid: Int? = nil + , equipmentid: Int? = nil + , statusid: Int? = nil + , priorityid: Int? = nil + , technicianuserid: Int? = nil + , reasonid: Int? = nil + , incompletereasonid: Int? = nil + , fuelid: Int? = nil + , createuserid: Int? = nil + , updateuserid: Int? = nil + ) { + self.id = id + self.number = number + self.meterreading = meterreading + self.specialinstructions = specialinstructions + self.scheduledenddate = scheduledstartdate + self.scheduledenddate = scheduledenddate + 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.createuserid = createuserid ?? -1 + self.updateuserid = updateuserid ?? -1 + } +} + +extension mdlWorkOrder{ + struct Create: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("workOrder") + .field("id", .int, .identifier(auto: true)) + .field("number", .string) + .field("meterReading", .float) + .field("specialInstructions", .string) + .field("scheduledStartDate", .datetime) + .field("scheduledEndDate", .datetime) + .field("startDate", .datetime) + .field("endDate", .datetime) + .field("approvedDate", .datetime) + .field("customerId", .int) + .field("equipmentId", .int) + .field("statusId", .int) + .field("priorityId", .int) + .field("technicianUserId", .int) + .field("reasonId", .int) + .field("incompleteReasonId", .int) + .field("fuelId", .int) + .field("createDate", .datetime) + .field("createUserId", .int) + .field("updateDate", .datetime) + .field("updateUserId", .int) + .create() + } + + func revert(on database: Database) async throws { + try await database.schema("workOrder").delete() + } + } +} + + + diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index 3b43411..11d23d6 100644 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -6,18 +6,101 @@ import Vapor // configures your application public func configure(_ app: Application) async throws { // uncomment to serve files from /Public folder - // app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory)) - + app.middleware.use(CORSMiddleware()) + let corsConfiguration = CORSMiddleware.Configuration( + allowedOrigin: .all, + allowedMethods: [.GET, .POST, .PUT, .OPTIONS, .DELETE, .PATCH], + allowedHeaders: [.accept, .authorization, .contentType, .origin, .xRequestedWith, .userAgent, .accessControlAllowOrigin] + ) + let cors = CORSMiddleware(configuration: corsConfiguration) + // cors middleware should come before default error middleware using `at: .beginning` + app.middleware.use(cors, at: .beginning) + + app.http.server.configuration.port = 3003 + app.databases.use(DatabaseConfigurationFactory.postgres(configuration: .init( hostname: Environment.get("DATABASE_HOST") ?? "localhost", port: Environment.get("DATABASE_PORT").flatMap(Int.init(_:)) ?? SQLPostgresConfiguration.ianaPortNumber, - username: Environment.get("DATABASE_USERNAME") ?? "vapor_username", - password: Environment.get("DATABASE_PASSWORD") ?? "vapor_password", - database: Environment.get("DATABASE_NAME") ?? "vapor_database", + username: Environment.get("DATABASE_USERNAME") ?? "mcarman", + password: Environment.get("DATABASE_PASSWORD") ?? "@ng31F@rm0823262", + database: Environment.get("DATABASE_NAME") ?? "cm", tls: .prefer(try .init(configuration: .clientDefault))) ), as: .psql) + + let timeout = HTTPClient.Configuration.Timeout(connect: .seconds(300), read: .seconds(300) ) + app.http.client.configuration.timeout = timeout - app.migrations.add(CreateTodo()) + app.migrations.add(mdlCategory.Create()) + app.migrations.add(mdlComparisonType.Create()) + app.migrations.add(mdlComparisonType.Seed()) + app.migrations.add(mdlCompartment.Create()) + app.migrations.add(mdlCompartmentLocation.Create()) + app.migrations.add(mdlDataType.Create()) + app.migrations.add(mdlDataType.Seed()) + app.migrations.add(mdlUnit.Create()) + app.migrations.add(mdlValueType.Create()) + app.migrations.add(mdlValueType.Seed()) + app.migrations.add(mdlInputType.Create()) + app.migrations.add(mdlInputType.Seed()) + app.migrations.add(mdlJobSite.Create()) + app.migrations.add(mdlJobSite.Seed()) + app.migrations.add(mdlPriority.Create()) + app.migrations.add(mdlPriority.Seed()) + app.migrations.add(mdlRepairType.Create()) + app.migrations.add(mdlRepairType.Seed()) + app.migrations.add(mdlRole.Create()) + app.migrations.add(mdlRole.Seed()) + app.migrations.add(mdlState.Create()) + app.migrations.add(mdlState.Seed()) + 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(mdlFluid.Create()) + app.migrations.add(mdlFuel.Create()) + app.migrations.add(mdlIncompleteReason.Create()) + app.migrations.add(mdlLevel.Create()) + app.migrations.add(mdlNoteType.Create()) + app.migrations.add(mdlPart.Create()) + app.migrations.add(mdlSignatureType.Create()) + app.migrations.add(mdlReason.Create()) + app.migrations.add(mdlViscosity.Create()) + app.migrations.add(mdlGate.Create()) + app.migrations.add(mdlCustomer.Create()) + app.migrations.add(mdlContactType.Create()) + app.migrations.add(mdlContactType.Seed()) + app.migrations.add(mdlContact.Create()) + app.migrations.add(mdlContactInfo.Create()) + app.migrations.add(mdlContact.makeParentCustomer()) + app.migrations.add(mdlResponseType.Create()) + app.migrations.add(mdlSMSCCode.Create()) + app.migrations.add(mdlUser.Create()) + app.migrations.add(mdlXUserRole.Create()) + app.migrations.add(mdlXFluidViscosity.Create()) + app.migrations.add(mdlEquipmentType.Create()) + app.migrations.add(mdlEquipmentType.Seed()) + app.migrations.add(mdlProduct.Create()) + app.migrations.add(mdlMake.Create()) + app.migrations.add(mdlModel.Create()) + app.migrations.add(mdlEquipment.Create()) + app.migrations.add(mdlObjProperty.Create()) + app.migrations.add(mdlEquipment.AddParent()) + app.migrations.add(mdlItem.Create()) + app.migrations.add(mdlItemResponseType.Create()) + app.migrations.add(mdlSpec.Create()) + app.migrations.add(mdlSpecItem.Create()) + app.migrations.add(mdlSpecItemValue.Create()) + app.migrations.add(mdlWorkOrder.Create()) + app.migrations.add(mdlSegment.Create()) + app.migrations.add(mdlSegment.Seed()) + app.migrations.add(mdlOilSample.Create()) + app.migrations.add(mdlXWorkOrderSegment.Create()) + app.migrations.add(mdlXUserRole.FixRoleId()) + + app.logger.logLevel = .debug + + try await app.autoMigrate() // register routes try routes(app) diff --git a/Sources/App/routes.swift b/Sources/App/routes.swift index f958df1..70dd69e 100644 --- a/Sources/App/routes.swift +++ b/Sources/App/routes.swift @@ -2,13 +2,16 @@ import Fluent import Vapor func routes(_ app: Application) throws { - app.get { req async in - "It works!" + app.routes.caseInsensitive = true + app.routes.defaultMaxBodySize = "64mb"; + let baseApp = app.grouped("api").grouped("v2.0") + baseApp.get { req async in + "Connexion Mobile Services Version 2.0" } + try baseApp.register(collection: cntrlCategory()) + try baseApp.register(collection: cntrlValueType()) + try baseApp.register(collection: cntrlDataTypes()) + try baseApp.register(collection: cntrlRole()) + try baseApp.register(collection: cntrlUser()) - app.get("hello") { req async -> String in - "Hello, world!" - } - - try app.register(collection: TodoController()) }