feat: Begins vendor views, working form, and table. Styles need some updates.

This commit is contained in:
2025-01-08 17:01:33 -05:00
parent 2b6e92a5c6
commit f5dbd7e121
12 changed files with 240 additions and 29 deletions

View File

@@ -31,7 +31,7 @@ struct ApiController: RouteCollection {
purchaseOrders.post(use: createPurchaseOrder(req:))
users.get(use: usersIndex(req:))
users.post(use: createUser(req:))
api.post("users", use: createUser(req:))
users.group("login") {
$0.get(use: self.login(req:))
}
@@ -83,7 +83,7 @@ struct ApiController: RouteCollection {
throw Abort(.notFound)
}
try await employee.delete(on: req.db)
return .noContent
return .ok
}
@Sendable
@@ -150,6 +150,13 @@ struct ApiController: RouteCollection {
@Sendable
func createUser(req: Request) async throws -> User.DTO {
let count = try await User.query(on: req.db).count()
if count > 0 {
guard req.auth.get(User.self) != nil else {
throw Abort(.unauthorized)
}
}
try User.Create.validate(content: req)
let create = try req.content.decode(User.Create.self)
guard create.password == create.confirmPassword else {
@@ -184,7 +191,7 @@ struct ApiController: RouteCollection {
}
try await user.delete(on: req.db)
return .noContent
return .ok
}
// MARK: - Vendors
@@ -198,7 +205,10 @@ struct ApiController: RouteCollection {
dbQuery = dbQuery.with(\.$branches)
}
return try await dbQuery.all().map { $0.toDTO(includeBranches: params.branches) }
return try await dbQuery
.sort(\.$name, .ascending)
.all()
.map { $0.toDTO(includeBranches: params.branches) }
}
@Sendable
@@ -228,7 +238,7 @@ struct ApiController: RouteCollection {
}
try await vendor.delete(on: req.db)
return .noContent
return .ok
}
// MARK: - VendorBranch
@@ -258,7 +268,7 @@ struct ApiController: RouteCollection {
throw Abort(.notFound)
}
try await branch.delete(on: req.db)
return .noContent
return .ok
}
@Sendable