import { ComposableFunctionArgs , Context , Logger , } from '@vue-storefront/core' ; import { GetProductSearchParams , ProductReviewRatingMetadata , CreateProductReviewInput , CustomerProductReviewParams , } from '@vue-storefront/magento-api' ; import { useReviewFactory , UseReviewFactoryParams } from '../../factories/useReviewFactory' ; const factoryParams = { searchReviews : async ( context , params ? ) => { Logger . debug ( '[Magento] search review params input:' , JSON . stringify ( params , null , 2 ) ) ; const { customQuery , ... input } = params ; const { data } = await context . $magento . api . productReview ( input as GetProductSearchParams ) ; Logger . debug ( '[Result]:' , { data } ) ; return data . products . items ; } , addReview : async ( context , params ) => { Logger . debug ( '[Magento] add review params input:' , JSON . stringify ( params , null , 2 ) ) ; const { customQuery , ... input } = params ; const { data } = await context . $magento . api . createProductReview ( input ) ; Logger . debug ( '[Result]:' , { data } ) ; return data . createProductReview . review ; } , loadReviewMetadata : async ( context , params ) => { Logger . debug ( '[Magento] load review metadata' ) ; const { data } = await context . $magento . api . productReviewRatingsMetadata ( ) ; Logger . debug ( '[Result]:' , { data } ) ; return data . productReviewRatingsMetadata . items ; } , loadCustomerReviews : async ( context , params ? ) => { Logger . debug ( '[Magento] load customer review based on:' , { params } ) ; const { customQuery , ... input } = params ; const { data } = await context . $magento . api . customerProductReview ( input ) ; Logger . debug ( '[Result]:' , { data } ) ; return data . customer ; } , } ; export default useReviewFactory < any , ComposableFunctionArgs < GetProductSearchParams > , ComposableFunctionArgs < CustomerProductReviewParams > , CreateProductReviewInput , ProductReviewRatingMetadata > ( factoryParams ) ;