UNPKG

@cranberry-money/shared-services

Version:

Platform-agnostic API services with pure functions and dependency injection. Includes auth, portfolios, instruments, countries, sectors, and more.

27 lines 1.31 kB
import { PORTFOLIO_ENDPOINTS, ASSET_ALLOCATION_ENDPOINTS } from '@cranberry-money/shared-constants'; import { ORDER_BY_CREATED_AT, QUERY_PARAM_ORDER_BY } from '@cranberry-money/shared-constants'; let configuredApiClient = null; export const configurePortfolioAllocations = (apiClient) => { configuredApiClient = apiClient; }; const getConfiguredClient = () => { if (!configuredApiClient) { throw new Error('Portfolio allocations service not configured. Call configurePortfolioAllocations(apiClient) before using portfolio allocation functions.'); } return configuredApiClient; }; export const getPortfolioAllocations = (portfolioUuid) => { return getConfiguredClient().get(`${PORTFOLIO_ENDPOINTS.BASE}${portfolioUuid}/allocations/`, { params: { [QUERY_PARAM_ORDER_BY]: ORDER_BY_CREATED_AT }, }); }; export const createAssetAllocation = (data) => { return getConfiguredClient().post(ASSET_ALLOCATION_ENDPOINTS.BASE, data); }; export const updateAssetAllocation = (uuid, data) => { return getConfiguredClient().patch(`${ASSET_ALLOCATION_ENDPOINTS.BASE}${uuid}/`, data); }; export const deleteAssetAllocation = (uuid) => { return getConfiguredClient().delete(`${ASSET_ALLOCATION_ENDPOINTS.BASE}${uuid}/`); }; //# sourceMappingURL=portfolioAllocations.js.map