fix: add product count to storefront (#719)

This commit is contained in:
Sebastian Rindom
2021-11-04 15:32:48 +01:00
committed by GitHub
parent 0a65eca3de
commit 45b344fbe1
6 changed files with 49 additions and 46 deletions
@@ -16,8 +16,8 @@ describe("GET /store/products", () => {
})
it("calls get product from productSerice", () => {
expect(ProductServiceMock.list).toHaveBeenCalledTimes(1)
expect(ProductServiceMock.list).toHaveBeenCalledWith(
expect(ProductServiceMock.listAndCount).toHaveBeenCalledTimes(1)
expect(ProductServiceMock.listAndCount).toHaveBeenCalledWith(
{ status: ["published"] },
{ relations: defaultRelations, skip: 0, take: 100 }
)
@@ -41,8 +41,8 @@ describe("GET /store/products", () => {
})
it("calls list from productSerice", () => {
expect(ProductServiceMock.list).toHaveBeenCalledTimes(1)
expect(ProductServiceMock.list).toHaveBeenCalledWith(
expect(ProductServiceMock.listAndCount).toHaveBeenCalledTimes(1)
expect(ProductServiceMock.listAndCount).toHaveBeenCalledWith(
{ is_giftcard: true, status: ["published"] },
{ relations: defaultRelations, skip: 0, take: 100 }
)
@@ -48,7 +48,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 })
}