fix(medusa): add total count for list queries in product (#710)

This commit is contained in:
Sebastian Rindom
2021-11-03 13:15:11 +01:00
committed by GitHub
parent 075864f24c
commit 109d400720
5 changed files with 259 additions and 99 deletions
@@ -21,14 +21,12 @@ describe("GET /admin/products", () => {
it("returns 200 and decorated products", () => {
expect(subject.status).toEqual(200)
expect(subject.body.products[0]._id).toEqual(products.product1._id)
expect(subject.body.products[0].decorated).toEqual(true)
expect(subject.body.products[1]._id).toEqual(products.product2._id)
expect(subject.body.products[1].decorated).toEqual(true)
expect(subject.body.products[0].id).toEqual(products.product1.id)
expect(subject.body.products[1].id).toEqual(products.product2.id)
})
it("calls update", () => {
expect(ProductServiceMock.list).toHaveBeenCalledTimes(1)
expect(ProductServiceMock.listAndCount).toHaveBeenCalledTimes(1)
})
})
})
@@ -82,7 +82,10 @@ export default async (req, res) => {
take: limit,
}
const products = await productService.list(selector, listConfig)
const [products, count] = await productService.listAndCount(
selector,
listConfig
)
res.json({ products, count: products.length, offset, limit })
res.json({ products, count, offset, limit })
}