|
|
|
@@ -12,12 +12,24 @@ struct cntrlUser: RouteCollection { |
|
|
|
func boot(routes: RoutesBuilder) throws { |
|
|
|
let rts = routes.grouped("users") |
|
|
|
rts.get(use: index) |
|
|
|
rts.get(":userid", ":password", use: login) |
|
|
|
rts.post(use: create) |
|
|
|
rts.put(use: update) |
|
|
|
rts.group(":id") { todo in |
|
|
|
rts.delete(use: delete) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func login(req: Request) async throws -> mdlUser{ |
|
|
|
try await mdlUser.query(on: req.db) |
|
|
|
.with(\.$roles) |
|
|
|
.with(\.$division) |
|
|
|
.with(\.$gate) |
|
|
|
.with(\.$location) |
|
|
|
.filter(\.$username == req.parameters.get("userid")) |
|
|
|
.filter( \.$password == req.parameters.get("password")) |
|
|
|
.first()! |
|
|
|
} |
|
|
|
|
|
|
|
func index(req: Request) async throws -> [mdlUser] { |
|
|
|
try await mdlUser.query(on: req.db).with(\.$roles).all() |
|
|
|
|