2021-04-12 10:45:41 +02:00
|
|
|
import apiClient from './clients/api-client';
|
2020-12-01 17:55:23 +01:00
|
|
|
import { AxiosResponse } from 'axios';
|
2021-05-21 18:25:18 +02:00
|
|
|
import { ShoppingCart } from '../models/payment';
|
2021-06-22 11:13:44 +02:00
|
|
|
import { ComputePriceResult, Price, PriceIndexFilter } from '../models/price';
|
2022-06-28 14:59:51 +02:00
|
|
|
import ApiLib from '../lib/api';
|
2020-12-01 17:55:23 +01:00
|
|
|
|
|
|
|
export default class PriceAPI {
|
2021-05-21 18:25:18 +02:00
|
|
|
static async compute (cart: ShoppingCart): Promise<ComputePriceResult> {
|
2021-07-01 12:04:48 +02:00
|
|
|
const res: AxiosResponse<ComputePriceResult> = await apiClient.post('/api/prices/compute', cart);
|
2020-12-02 10:06:18 +01:00
|
|
|
return res?.data;
|
2020-12-01 17:55:23 +01:00
|
|
|
}
|
2021-06-22 11:13:44 +02:00
|
|
|
|
2021-06-23 17:00:15 +02:00
|
|
|
static async index (filters?: PriceIndexFilter): Promise<Array<Price>> {
|
2022-06-28 14:59:51 +02:00
|
|
|
const res: AxiosResponse = await apiClient.get(`/api/prices${ApiLib.filtersToQuery(filters)}`);
|
2021-06-22 11:13:44 +02:00
|
|
|
return res?.data;
|
|
|
|
}
|
|
|
|
|
2021-12-21 17:13:40 +01:00
|
|
|
static async create (price: Price): Promise<Price> {
|
|
|
|
const res: AxiosResponse<Price> = await apiClient.post('/api/prices', { price });
|
|
|
|
return res?.data;
|
|
|
|
}
|
|
|
|
|
2021-06-22 11:13:44 +02:00
|
|
|
static async update (price: Price): Promise<Price> {
|
2021-06-22 17:56:13 +02:00
|
|
|
const res: AxiosResponse<Price> = await apiClient.patch(`/api/prices/${price.id}`, { price });
|
2021-07-01 12:04:48 +02:00
|
|
|
return res?.data;
|
2021-06-22 11:13:44 +02:00
|
|
|
}
|
|
|
|
|
2021-12-21 17:13:40 +01:00
|
|
|
static async destroy (priceId: number): Promise<void> {
|
|
|
|
const res: AxiosResponse<void> = await apiClient.delete(`/api/prices/${priceId}`);
|
|
|
|
return res?.data;
|
|
|
|
}
|
2020-12-01 17:55:23 +01:00
|
|
|
}
|