3367 add facets subquery to product (#146)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { ProductAPI } from '../datasources/product-api';
|
||||
import {
|
||||
Orientation,
|
||||
PrintProduct,
|
||||
Product,
|
||||
ProductListResult,
|
||||
@@ -20,6 +21,7 @@ import { DesignerAPI } from '../datasources/designer-api';
|
||||
import { PrintProductDefaultsAPI } from '../datasources/printproduct-defaults-api';
|
||||
import { PrintProductDefaults } from '../types/printproduct-defaults-types';
|
||||
import { GraphQLError } from 'graphql';
|
||||
import { getOrientationString, isRepeatingPattern } from '../datasources/utils';
|
||||
|
||||
const ProductBlacklist = {
|
||||
async market(parent, _args, { dataSources }) {
|
||||
@@ -45,6 +47,41 @@ const Product = {
|
||||
async related({ id }, _args, { dataSources }) {
|
||||
return (<ProductAPI>dataSources.productApi).getRelatedProducts(id);
|
||||
},
|
||||
async facets(product: Product, _args, { dataSources }) {
|
||||
const keywords = await (<KeywordAPI>(
|
||||
dataSources.keywordApi
|
||||
)).getProductKeywords(product.id);
|
||||
const colors = [];
|
||||
const types = [];
|
||||
keywords.forEach((keyword) => {
|
||||
if (keyword.type === 'COLOR') {
|
||||
colors.push(keyword.value);
|
||||
} else if (keyword.value === 'typeillustration') {
|
||||
types.push('illustration');
|
||||
} else if (keyword.value === 'typephotography') {
|
||||
types.push('photograph');
|
||||
}
|
||||
});
|
||||
|
||||
const isRepeating = isRepeatingPattern(product);
|
||||
if (isRepeating) {
|
||||
types.push('repeating-pattern');
|
||||
}
|
||||
|
||||
const orientations = isRepeating
|
||||
? [
|
||||
Orientation[Orientation.LANDSCAPE],
|
||||
Orientation[Orientation.STANDING],
|
||||
Orientation[Orientation.SQUARE],
|
||||
]
|
||||
: [getOrientationString(product.fields)];
|
||||
|
||||
return [
|
||||
{ attribute: 'color', values: colors },
|
||||
{ attribute: 'orientation', values: orientations },
|
||||
{ attribute: 'type', values: types },
|
||||
];
|
||||
},
|
||||
};
|
||||
|
||||
const PrintProduct = {
|
||||
|
||||
Reference in New Issue
Block a user