Fix scopes and promise handling (#152)
This commit is contained in:
@@ -114,8 +114,11 @@ async function getProductsResult(
|
||||
extensions: { code: 'BAD_USER_INPUT' },
|
||||
});
|
||||
}
|
||||
const total = (<ProductAPI>dataSources.productApi).getProductsTotal(input);
|
||||
const items = (<ProductAPI>dataSources.productApi).getProducts(input);
|
||||
const totalPromise = (<ProductAPI>dataSources.productApi).getProductsTotal(
|
||||
input,
|
||||
);
|
||||
const itemsPromise = (<ProductAPI>dataSources.productApi).getProducts(input);
|
||||
const [total, items] = await Promise.all([totalPromise, itemsPromise]);
|
||||
const offset = input.pagination?.offset ?? 0;
|
||||
return {
|
||||
pagination: {
|
||||
@@ -136,7 +139,7 @@ async function getProductsSearchResult(
|
||||
const catApi = <CategoryAPI>dataSources.categoryApi;
|
||||
const keywApi = <KeywordAPI>dataSources.keywordApi;
|
||||
const designerApi = <DesignerAPI>dataSources.designerApi;
|
||||
const prods = Promise.all([
|
||||
const products = await Promise.all([
|
||||
prodApi.searchByName(q),
|
||||
prodApi.searchByArtNo(q),
|
||||
prodApi.searchByCompleteProductId(q),
|
||||
@@ -152,15 +155,25 @@ async function getProductsSearchResult(
|
||||
return Object.values(products);
|
||||
});
|
||||
|
||||
const [batches, keywords, categories, designers, copyrights, references] =
|
||||
await Promise.all([
|
||||
prodApi.searchByBatch(q),
|
||||
keywApi.searchKeywords(q),
|
||||
catApi.searchCategories(q),
|
||||
designerApi.searchDesigners(q),
|
||||
prodApi.searchByCopyright(q),
|
||||
prodApi.searchByReferences(q),
|
||||
]);
|
||||
|
||||
return {
|
||||
q: q,
|
||||
products: prods,
|
||||
batches: prodApi.searchByBatch(q),
|
||||
keywords: keywApi.searchKeywords(q),
|
||||
categories: catApi.searchCategories(q),
|
||||
designers: designerApi.searchDesigners(q),
|
||||
copyrights: prodApi.searchByCopyright(q),
|
||||
references: prodApi.searchByReferences(q),
|
||||
products: products,
|
||||
batches: batches,
|
||||
keywords: keywords,
|
||||
categories: categories,
|
||||
designers: designers,
|
||||
copyrights: copyrights,
|
||||
references: references,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user