77 more search options (#78)
* added search for copyright * added search by reference
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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 +
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user