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>> {
|
async getRelatedProducts(id: number): Promise<Array<Product>> {
|
||||||
const ids = await this.knex
|
const ids = await this.knex
|
||||||
.raw(
|
.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) {
|
export function keywordProducts(keywordId: number) {
|
||||||
return (
|
return (
|
||||||
baseQuery +
|
baseQuery +
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ async function getProductsSearchResult(
|
|||||||
const prods = Promise.all([
|
const prods = Promise.all([
|
||||||
prodApi.searchByName(q),
|
prodApi.searchByName(q),
|
||||||
prodApi.searchByArtNo(q),
|
prodApi.searchByArtNo(q),
|
||||||
|
prodApi.searchByCopyright(q),
|
||||||
|
prodApi.searchByReferences(q),
|
||||||
]).then((d) => d.flat());
|
]).then((d) => d.flat());
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user