Add helpers to shopify items

This commit is contained in:
2024-04-19 16:02:09 -06:00
parent aa1277fafd
commit 4e07eee0b9
4 changed files with 43 additions and 9 deletions

View File

@@ -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>[])
}
}