Add product search (#64)

This commit is contained in:
Niklas Fondberg
2021-10-11 11:20:48 +02:00
committed by GitHub
parent 8b03ab8246
commit 08149c4a87
10 changed files with 168 additions and 4 deletions
+22 -3
View File
@@ -77,17 +77,18 @@ FROM "product-products" products
export function products(input: ProductsFilterInput) {
const limit = input.pagination.limit ?? 100;
const filter = input.filter;
const filter = input.filter ?? null;
return (
baseQuery +
/* sql */ `
${
filter.visible != null
filter?.visible != null
? /* sql */ `
WHERE products.visible = ${filter?.visible ? '1' : '0'}
AND products.browsable = ${filter?.browsable ? '1' : '0'}`
: ``
}
ORDER BY products.inserted DESC
LIMIT ${limit}
`
);
@@ -98,7 +99,7 @@ export function productsTotal(input: ProductsFilterInput) {
return /*sql */ `
SELECT count(*) FROM "product-products" products
${
filter.visible != null
filter?.visible != null
? /* sql */ `
WHERE products.visible = ${filter?.visible ? '1' : '0'}
AND products.browsable = ${filter?.browsable ? '1' : '0'}`
@@ -125,6 +126,15 @@ export function categoryProducts(categoryId: number) {
);
}
export function designerProducts() {
return (
baseQuery +
/* sql */ `
WHERE products.designerid = ?;
`
);
}
export function keywordProducts(keywordId: number) {
return (
baseQuery +
@@ -133,3 +143,12 @@ export function keywordProducts(keywordId: number) {
`
);
}
export function searchByFieldValue(fieldid: number) {
return (
baseQuery +
/* sql */ `
WHERE products.productid IN (SELECT productid FROM "product-products_fields" WHERE fieldid = ${fieldid} AND LOWER(value) LIKE ? LIMIT 5000); -- limit to 5000 results
`
);
}