feat working on vendor views.

This commit is contained in:
2025-01-16 08:02:13 -05:00
parent 6f2e87e886
commit d4a8444700
8 changed files with 239 additions and 132 deletions

View File

@@ -37,13 +37,20 @@ public extension DatabaseClient.Vendors {
query = query.with(\.$branches)
}
return try await query.first().map { try $0.toDTO(includeBranches: withBranches) }
} update: { id, updates in
} update: { id, updates, withBranches in
guard let model = try await VendorModel.find(id, on: db) else {
throw NotFoundError()
}
try model.applyUpdates(updates)
try await model.save(on: db)
return try model.toDTO()
if withBranches != .withBranches {
return try model.toDTO()
}
return try await VendorModel.query(on: db)
.filter(\.$id == id)
.with(\.$branches)
.first()!
.toDTO()
}
}
}