import apiClient from './clients/api-client'; import { AxiosResponse } from 'axios'; import { ShoppingCart } from '../models/payment'; import { ComputePriceResult, Price, PriceIndexFilter } from '../models/price'; export default class PriceAPI { static async compute (cart: ShoppingCart): Promise { const res: AxiosResponse = await apiClient.post(`/api/prices/compute`, cart); return res?.data; } static async index (filters?: Array): Promise> { const res: AxiosResponse = await apiClient.get(`/api/prices${this.filtersToQuery(filters)}`); return res?.data; } static async update (price: Price): Promise { const res: AxiosResponse = await apiClient.patch(`/api/price/${price.id}`, { price }); return res?.data; } private static filtersToQuery(filters?: Array): string { if (!filters) return ''; return '?' + filters.map(f => `${f.key}=${f.value}`).join('&'); } }