Add helpers to shopify items
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ShopifyProduct, parseShopifyProduct } from './shopifyUtils';
|
||||
import { ShopifyProduct, ShopifyProductWithHelpers, addShopifyHelperProperties, parseShopifyProduct } from './shopifyUtils';
|
||||
import axios from 'axios';
|
||||
import { map, pipe } from 'ramda';
|
||||
|
||||
@Injectable()
|
||||
export class LimaService {
|
||||
public readonly shopifyUrl = 'https://www.limacoffeeroasters.com/products.json'
|
||||
|
||||
public async fetchProducts(): Promise<ShopifyProduct<Date>[]> {
|
||||
public async fetchProducts(): Promise<ShopifyProductWithHelpers[]> {
|
||||
const response = await axios.get(this.shopifyUrl)
|
||||
if (response.status !== 200) {
|
||||
throw new Error('Failed to fetch products')
|
||||
}
|
||||
return response.data.products.map(parseShopifyProduct);
|
||||
return pipe(
|
||||
map(parseShopifyProduct),
|
||||
map(addShopifyHelperProperties({ shopBaseUrl: 'https://www.limacoffeeroasters.com' }))
|
||||
)(response.data.products as ShopifyProduct<string>[])
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user