Add keywords and product types
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
Product,
|
||||
ProductGroup,
|
||||
PrintProduct,
|
||||
ProductType,
|
||||
ProductBlacklist,
|
||||
} from '../types/product-types';
|
||||
import { Maybe } from '../types/types';
|
||||
@@ -40,9 +41,25 @@ export class ProductAPI extends SQLDataSource {
|
||||
});
|
||||
}
|
||||
|
||||
getProductTypes(row: any): Array<ProductType> {
|
||||
if (!row.types) {
|
||||
return [];
|
||||
}
|
||||
return row.types.map((type: any) => {
|
||||
if (type === 'typeillustration') {
|
||||
return ProductType[ProductType.ILLUSTRATION];
|
||||
}
|
||||
if (type === 'typephotography') {
|
||||
return ProductType[ProductType.PHOTO];
|
||||
}
|
||||
return ProductType[ProductType.UNKNOWN];
|
||||
});
|
||||
}
|
||||
|
||||
createProductFromRow(row: any) {
|
||||
row.blacklisting = this.getBlacklisting(row);
|
||||
row.printProducts = this.getPrintProducts(row);
|
||||
row.type = this.getProductTypes(row);
|
||||
row.designerId = row.designerid;
|
||||
row.fields_json = row.fields;
|
||||
return row;
|
||||
@@ -80,32 +97,12 @@ export class ProductAPI extends SQLDataSource {
|
||||
.raw(query)
|
||||
.then((data) => data.rows.map((row) => this.createProductFromRow(row)));
|
||||
}
|
||||
|
||||
async getKeywordProducts(keywordId: number): Promise<Array<Product>> {
|
||||
const query = sql.keywordProducts(keywordId);
|
||||
|
||||
return await this.knex
|
||||
.raw(query)
|
||||
.then((data) => data.rows.map((row) => this.createProductFromRow(row)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* SELECT product_keyword.product_id, keywords.value
|
||||
FROM product_keyword
|
||||
JOIN keywords ON product_keyword.keyword_id = keywords.id;
|
||||
*
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
keywords
|
||||
id, value
|
||||
|
||||
|
||||
keyword_type:
|
||||
keyword_id, type_id
|
||||
|
||||
keywordstypes
|
||||
id, name (color)
|
||||
|
||||
|
||||
keywords_i18n NOT used it seems and misses some languages
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user