Add product search (#64)
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
Product,
|
||||
ProductListResult,
|
||||
ProductsFilterInput,
|
||||
ProductsSearchResult,
|
||||
} from '../types/product-types';
|
||||
import * as CONFIG from '../config';
|
||||
import { CategoryAPI } from '../datasources/category-api';
|
||||
@@ -14,6 +15,7 @@ import { InteriorAPI } from '../datasources/interior-api';
|
||||
import { InteriorsLambdaAPI } from '../datasources/interiors-lambda-api';
|
||||
import { IdNumberResult } from '../types/types';
|
||||
import { moveS3File } from '../s3';
|
||||
import { DesignerAPI } from '../datasources/designer-api';
|
||||
|
||||
const ProductBlacklist = {
|
||||
async market(parent, _args, { dataSources }) {
|
||||
@@ -66,6 +68,30 @@ async function getProductsResult(
|
||||
};
|
||||
}
|
||||
|
||||
async function getProductsSearchResult(
|
||||
_,
|
||||
{ q },
|
||||
{ dataSources },
|
||||
): Promise<ProductsSearchResult> {
|
||||
const prodApi = <ProductAPI>dataSources.productApi;
|
||||
const catApi = <CategoryAPI>dataSources.categoryApi;
|
||||
const keywApi = <KeywordAPI>dataSources.keywordApi;
|
||||
const designerApi = <DesignerAPI>dataSources.designerApi;
|
||||
const prods = Promise.all([
|
||||
prodApi.searchByName(q),
|
||||
prodApi.searchByArtNo(q),
|
||||
]).then((d) => d.flat());
|
||||
|
||||
return {
|
||||
q: q,
|
||||
products: prods,
|
||||
batches: prodApi.searchByBatch(q),
|
||||
keywords: keywApi.searchKeywords(q),
|
||||
categories: catApi.searchCategories(q),
|
||||
designers: designerApi.searchDesigners(q),
|
||||
};
|
||||
}
|
||||
|
||||
async function getProduct(_, { id }, { dataSources }): Promise<Product> {
|
||||
return (<ProductAPI>dataSources.productApi).getProduct(id);
|
||||
}
|
||||
@@ -79,6 +105,7 @@ export const productTypeDefs = {
|
||||
export const productQueryTypeDefs = {
|
||||
products: getProductsResult,
|
||||
product: getProduct,
|
||||
productsSearch: getProductsSearchResult,
|
||||
};
|
||||
|
||||
///////////////////
|
||||
|
||||
Reference in New Issue
Block a user