Added categories to products
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
ProductGroup,
|
||||
PrintProduct,
|
||||
ProductBlacklist,
|
||||
Category,
|
||||
} from './product-types';
|
||||
import { Maybe } from './types';
|
||||
|
||||
@@ -15,6 +16,24 @@ export class ProductAPI extends SQLDataSource {
|
||||
super(config);
|
||||
}
|
||||
|
||||
async getCategories(productId: number): Promise<Array<Category>> {
|
||||
const query = /* sql */ `
|
||||
SELECT product_category.category_id, categories.name
|
||||
FROM product_category JOIN categories ON product_category.category_id = categories.id
|
||||
WHERE product_category.product_id = ?
|
||||
`;
|
||||
|
||||
const res = await this.knex.raw(query, productId).then((data) =>
|
||||
data.rows.map((o) => {
|
||||
return {
|
||||
...o,
|
||||
id: o.category_id,
|
||||
};
|
||||
}),
|
||||
);
|
||||
return res;
|
||||
}
|
||||
|
||||
getBlacklisting(row: any): Array<ProductBlacklist> {
|
||||
if (!row.blacklisting) {
|
||||
return [];
|
||||
|
||||
@@ -8,6 +8,10 @@ export enum ProductGroup {
|
||||
FRAMED_PRINT = 8,
|
||||
}
|
||||
|
||||
export interface Category {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
export interface ProductBlacklist {
|
||||
id: number;
|
||||
groupId: number;
|
||||
|
||||
Reference in New Issue
Block a user