fix: allow offset and limit in products free text search (#1082)

This commit is contained in:
Zakaria El Asri
2022-02-18 11:39:32 +01:00
committed by olivermrbl
parent 3b878bc5dd
commit a81def2f75
2 changed files with 36 additions and 0 deletions

View File

@@ -238,6 +238,40 @@ describe("/admin/products", () => {
])
})
it("returns a list of products with free text query and limit", async () => {
const api = useApi()
const response = await api
.get("/admin/products?q=t&limit=2", {
headers: {
Authorization: "Bearer test_token",
},
})
.catch((err) => {
console.log(err)
})
expect(response.status).toEqual(200)
expect(response.data.products.length).toEqual(2)
})
it("returns a list of products with free text query and offset", async () => {
const api = useApi()
const response = await api
.get("/admin/products?q=t&offset=1", {
headers: {
Authorization: "Bearer test_token",
},
})
.catch((err) => {
console.log(err)
})
expect(response.status).toEqual(200)
expect(response.data.products.length).toEqual(4)
})
it("returns a list of deleted products", async () => {
const api = useApi()

View File

@@ -890,6 +890,8 @@ class ProductService extends BaseService {
.orWhere(`collection.title ILIKE :q`, { q: `%${q}%` })
})
)
.skip(query.skip)
.take(query.take)
if (query.withDeleted) {
qb = qb.withDeleted()