21 lines
805 B
TypeScript
21 lines
805 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { ShopifyProduct, ShopifyProductWithHelpers, addShopifyHelperProperties, parseShopifyProduct } from './shopifyUtils';
|
|
import axios from 'axios';
|
|
import { map, pipe } from 'ramda';
|
|
|
|
@Injectable()
|
|
export class BindleService {
|
|
public readonly shopifyUrl = 'https://bindlecoffee.com/products.json'
|
|
|
|
public async fetchProducts(): Promise<ShopifyProductWithHelpers[]> {
|
|
const response = await axios.get(this.shopifyUrl)
|
|
if (response.status !== 200) {
|
|
throw new Error('Failed to fetch products')
|
|
}
|
|
return pipe(
|
|
map(parseShopifyProduct),
|
|
map(addShopifyHelperProperties({ shopBaseUrl: 'https://bindlecoffee.com' }))
|
|
)(response.data.products as ShopifyProduct<string>[])
|
|
}
|
|
}
|