import apiClient from './clients/api-client'; import { AxiosResponse } from 'axios'; import { ShoppingCart } from '../models/payment'; import { ComputePriceResult, Price, PriceIndexFilter } from '../models/price'; import ApiLib from '../lib/api'; 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?: PriceIndexFilter): Promise> { const res: AxiosResponse = await apiClient.get(`/api/prices${ApiLib.filtersToQuery(filters)}`); return res?.data; } static async create (price: Price): Promise { const res: AxiosResponse = await apiClient.post('/api/prices', { price }); return res?.data; } static async update (price: Price): Promise { const res: AxiosResponse = await apiClient.patch(`/api/prices/${price.id}`, { price }); return res?.data; } static async destroy (priceId: number): Promise { const res: AxiosResponse = await apiClient.delete(`/api/prices/${priceId}`); return res?.data; } }