77 more search options (#78)

* added search for copyright

* added search by reference
This commit is contained in:
Arwid Thornström
2021-10-22 14:39:46 +02:00
committed by GitHub
parent 8d9477d85b
commit ac5be19649
3 changed files with 26 additions and 0 deletions
+16
View File
@@ -259,6 +259,22 @@ export class ProductAPI extends BaseSQLDataSource {
});
}
async searchByCopyright(name: string): Promise<Array<Product>> {
const query = sql.searchByFieldValue(25); // copyright
return this.knex
.raw(query, name)
.then((data) => data.rows.map((row) => this.createProductFromRow(row)));
}
async searchByReferences(name: string): Promise<Array<Product>> {
const query = sql.referenceProducts(); // ref1, ref2, ref3
return this.knex
.raw(query, [name, name, name])
.then((data) => data.rows.map((row) => this.createProductFromRow(row)));
}
async getRelatedProducts(id: number): Promise<Array<Product>> {
const ids = await this.knex
.raw(
+8
View File
@@ -161,6 +161,14 @@ export function designerProducts() {
);
}
export function referenceProducts() {
return (
baseQuery +
/* sql */ `
WHERE LOWER(products.ref1) LIKE ? OR LOWER(products.ref2) LIKE ? OR LOWER(products.ref3) LIKE ? ORDER BY products.inserted DESC`
);
}
export function keywordProducts(keywordId: number) {
return (
baseQuery +
+2
View File
@@ -84,6 +84,8 @@ async function getProductsSearchResult(
const prods = Promise.all([
prodApi.searchByName(q),
prodApi.searchByArtNo(q),
prodApi.searchByCopyright(q),
prodApi.searchByReferences(q),
]).then((d) => d.flat());
return {