Files
InvoiceShelf/resources/scripts-v2/api/services/exchange-rate.service.ts
Darko Gjorgjijoski 991b716b33 Phase 1: TypeScript foundation in scripts-v2/
Create the complete TypeScript foundation for the Vue 3 migration
in a parallel scripts-v2/ directory. 72 files, 5430 lines, zero
any types, strict mode.

- types/ (21 files): Domain interfaces for all 17 entities derived
  from actual Laravel models and API resources. Enums for all
  statuses. Generic API response wrappers.
- api/ (29 files): Typed axios client with interceptors, endpoint
  constants from routes/api.php, 25 typed service classes covering
  every API endpoint.
- composables/ (14 files): Vue 3 composition functions for auth,
  notifications, dialogs, modals, pagination, filters, currency,
  dates, theme, sidebar, company context, and permissions.
- utils/ (5 files): Pure typed utilities for money formatting,
  date formatting (date-fns), localStorage, and error handling.
- config/ (3 files): Typed ability constants, app constants.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 05:00:00 +02:00

118 lines
3.4 KiB
TypeScript

import { client } from '../client'
import { API } from '../endpoints'
import type { ExchangeRateProvider, Currency } from '../../types/domain/currency'
import type { ApiResponse, ListParams } from '../../types/api'
export interface CreateExchangeRateProviderPayload {
driver: string
key: string
active?: boolean
currencies?: string[]
}
export interface ExchangeRateResponse {
exchange_rate: number
}
export interface ActiveProviderResponse {
has_active_provider: boolean
exchange_rate: number | null
}
export interface SupportedCurrenciesResponse {
supportedCurrencies: string[]
}
export interface UsedCurrenciesResponse {
activeUsedCurrencies: Currency[]
}
export interface BulkCurrenciesResponse {
currencies: Array<Currency & { exchange_rate: number | null }>
}
export interface BulkUpdatePayload {
currencies: Array<{
id: number
exchange_rate: number
}>
}
export interface ConfigDriversResponse {
exchange_rate_drivers: string[]
}
export const exchangeRateService = {
// Providers CRUD
async listProviders(params?: ListParams): Promise<ApiResponse<ExchangeRateProvider[]>> {
const { data } = await client.get(API.EXCHANGE_RATE_PROVIDERS, { params })
return data
},
async getProvider(id: number): Promise<ApiResponse<ExchangeRateProvider>> {
const { data } = await client.get(`${API.EXCHANGE_RATE_PROVIDERS}/${id}`)
return data
},
async createProvider(payload: CreateExchangeRateProviderPayload): Promise<ApiResponse<ExchangeRateProvider>> {
const { data } = await client.post(API.EXCHANGE_RATE_PROVIDERS, payload)
return data
},
async updateProvider(
id: number,
payload: Partial<CreateExchangeRateProviderPayload>,
): Promise<ApiResponse<ExchangeRateProvider>> {
const { data } = await client.put(`${API.EXCHANGE_RATE_PROVIDERS}/${id}`, payload)
return data
},
async deleteProvider(id: number): Promise<{ success: boolean }> {
const { data } = await client.delete(`${API.EXCHANGE_RATE_PROVIDERS}/${id}`)
return data
},
// Exchange Rates
async getRate(currencyId: number): Promise<ExchangeRateResponse> {
const { data } = await client.get(`${API.CURRENCIES}/${currencyId}/exchange-rate`)
return data
},
async getActiveProvider(currencyId: number): Promise<ActiveProviderResponse> {
const { data } = await client.get(`${API.CURRENCIES}/${currencyId}/active-provider`)
return data
},
// Currency lists
async getSupportedCurrencies(): Promise<SupportedCurrenciesResponse> {
const { data } = await client.get(API.SUPPORTED_CURRENCIES)
return data
},
async getUsedCurrencies(): Promise<UsedCurrenciesResponse> {
const { data } = await client.get(API.USED_CURRENCIES)
return data
},
async getBulkCurrencies(): Promise<BulkCurrenciesResponse> {
const { data } = await client.get(API.CURRENCIES_USED)
return data
},
async bulkUpdateExchangeRate(payload: BulkUpdatePayload): Promise<{ success: boolean }> {
const { data } = await client.post(API.CURRENCIES_BULK_UPDATE, payload)
return data
},
// Config
async getDrivers(): Promise<ConfigDriversResponse> {
const { data } = await client.get(API.CONFIG, { params: { key: 'exchange_rate_drivers' } })
return data
},
async getCurrencyConverterServers(): Promise<Record<string, unknown>> {
const { data } = await client.get(API.CONFIG, { params: { key: 'currency_converter_servers' } })
return data
},
}