feat: Updates views to use new api controllers and db items.
This commit is contained in:
@@ -2,6 +2,8 @@ import Fluent
|
||||
import Vapor
|
||||
|
||||
struct PurchaseOrderViewController: RouteCollection {
|
||||
private let employeesApi = EmployeeApiController()
|
||||
private let branches = VendorBranchDB()
|
||||
private let api = ApiController()
|
||||
private let api2 = PurchaseOrderDB()
|
||||
|
||||
@@ -16,8 +18,8 @@ struct PurchaseOrderViewController: RouteCollection {
|
||||
@Sendable
|
||||
func index(req: Request) async throws -> View {
|
||||
let purchaseOrders = try await api2.fetchAll(on: req.db)
|
||||
let branches = try await api.getBranches(req: req)
|
||||
let employees = try await api.employeesIndex(req: req)
|
||||
let branches = try await self.branches.getBranches(req: req)
|
||||
let employees = try await employeesApi.index(req: req)
|
||||
req.logger.debug("Branches: \(branches)")
|
||||
return try await req.view.render(
|
||||
"purchaseOrders/index",
|
||||
@@ -74,7 +76,7 @@ extension VendorBranch {
|
||||
let vendor: Vendor.DTO
|
||||
}
|
||||
|
||||
func toFormDTO() throws -> FormDTO {
|
||||
func toFormDTO() throws -> VendorBranch.FormDTO {
|
||||
try .init(
|
||||
id: requireID(),
|
||||
name: name,
|
||||
@@ -123,12 +125,11 @@ private extension PurchaseOrder {
|
||||
}
|
||||
}
|
||||
|
||||
private extension ApiController {
|
||||
private extension VendorBranchDB {
|
||||
|
||||
func getBranches(req: Request) async throws -> [VendorBranch.FormDTO] {
|
||||
try await VendorBranch.query(on: req.db)
|
||||
.with(\.$vendor)
|
||||
// .sort(Vendor.self, \.$name)
|
||||
.all()
|
||||
.map { try $0.toFormDTO() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user