feat(pagination): Adds MVP pagination to orders and products for admin routes
This commit is contained in:
@@ -13,13 +13,18 @@ export default async (req, res) => {
|
||||
"payment_status",
|
||||
])
|
||||
|
||||
let orders = await orderService.list(query)
|
||||
const limit = parseInt(req.query.limit) || 0
|
||||
const offset = parseInt(req.query.offset) || 0
|
||||
|
||||
let orders = await orderService.list(query, offset, limit)
|
||||
|
||||
orders = await Promise.all(
|
||||
orders.map(order => orderService.decorate(order))
|
||||
)
|
||||
|
||||
res.json({ orders })
|
||||
let numOrders = await orderService.count()
|
||||
|
||||
res.json({ orders, total_count: numOrders })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
|
||||
@@ -10,7 +10,10 @@ export default async (req, res) => {
|
||||
"description",
|
||||
])
|
||||
|
||||
let products = await productService.list(query)
|
||||
const limit = parseInt(req.query.limit) || 0
|
||||
const offset = parseInt(req.query.offset) || 0
|
||||
|
||||
let products = await productService.list(query, offset, limit)
|
||||
|
||||
products = await Promise.all(
|
||||
products.map(
|
||||
@@ -32,7 +35,10 @@ export default async (req, res) => {
|
||||
)
|
||||
)
|
||||
)
|
||||
res.json({ products })
|
||||
|
||||
const numProducts = await productService.count()
|
||||
|
||||
res.json({ products, total_count: numProducts })
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
throw error
|
||||
|
||||
@@ -10,14 +10,7 @@ describe("Get product by id", () => {
|
||||
beforeAll(async () => {
|
||||
subject = await request(
|
||||
"GET",
|
||||
`/admin/products/${IdMap.getId("product1")}`,
|
||||
{
|
||||
adminSession: {
|
||||
jwt: {
|
||||
userId: IdMap.getId("admin_user"),
|
||||
},
|
||||
},
|
||||
}
|
||||
`/store/products/${IdMap.getId("product1")}`
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user