feat(pagination): Adds MVP pagination to orders and products for admin routes

This commit is contained in:
Oliver Windall Juhl
2020-08-27 17:51:23 +02:00
committed by GitHub
parent d8aac759cf
commit 9dc6999a9a
9 changed files with 70 additions and 27 deletions
@@ -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")}`
)
})