P5 7619 refactor products to return list (#11)
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { IResolverObject } from 'graphql-tools';
|
||||
import { ProductAPI } from '../datasources/product-api';
|
||||
import { Product } from '../types/product-types';
|
||||
import {
|
||||
Product,
|
||||
ProductListResult,
|
||||
ProductsFilterInput,
|
||||
} from '../types/product-types';
|
||||
import { CategoryAPI } from '../datasources/category-api';
|
||||
import { Category } from '../types/category-types';
|
||||
import { KeywordAPI } from '../datasources/keyword-api';
|
||||
@@ -21,7 +25,7 @@ const Product: IResolverObject = {
|
||||
async categories({ id }, _args, { dataSources }): Promise<Array<Category>> {
|
||||
return (<CategoryAPI>dataSources.categoryApi).getProductCategories(id);
|
||||
},
|
||||
async designer({ designerId }, args, { dataSources }) {
|
||||
async designer({ designerId }, _args, { dataSources }) {
|
||||
if (!designerId) {
|
||||
return null;
|
||||
}
|
||||
@@ -41,16 +45,22 @@ const PrintProduct: IResolverObject = {
|
||||
},
|
||||
};
|
||||
|
||||
async function getProducts(
|
||||
async function getProductsResult(
|
||||
_,
|
||||
{ limit, visible, browsable },
|
||||
input: ProductsFilterInput,
|
||||
{ dataSources },
|
||||
): Promise<Array<Product>> {
|
||||
return (<ProductAPI>dataSources.productApi).getProducts(
|
||||
limit,
|
||||
visible,
|
||||
browsable,
|
||||
);
|
||||
): Promise<ProductListResult> {
|
||||
const total = (<ProductAPI>dataSources.productApi).getProductsTotal(input);
|
||||
const items = (<ProductAPI>dataSources.productApi).getProducts(input);
|
||||
|
||||
return {
|
||||
pagination: {
|
||||
limit: input.pagination.limit,
|
||||
offset: 0, // TODO: this will be implemented later if the client app needs it
|
||||
total: total,
|
||||
},
|
||||
items: items,
|
||||
};
|
||||
}
|
||||
|
||||
async function getProduct(_, { id }, { dataSources }): Promise<Product> {
|
||||
@@ -64,11 +74,11 @@ export const productTypeDefs = {
|
||||
};
|
||||
|
||||
export const productQueryTypeDefs = {
|
||||
products: getProducts,
|
||||
products: getProductsResult,
|
||||
product: getProduct,
|
||||
};
|
||||
|
||||
// Mutations below
|
||||
// Mutations below, embryo stage
|
||||
|
||||
export const productMutationTypeDefs = {
|
||||
addKeyword(_, { productId, keywordId }, { dataSources }) {
|
||||
|
||||
Reference in New Issue
Block a user