|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- //
- // mdlUser.swift
- //
- //
- // 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()
- }
- }
-
- }
-
-
-
|