UNPKG

@mixxtor/currencyx-adonisjs

Version:

AdonisJS integration for CurrencyX.js with database exchange provider and cache support

47 lines (46 loc) 1.47 kB
/** * @mixxtor/currencyx-adonisjs * * (c) Mixxtor * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ import { createCurrency } from '@mixxtor/currencyx-js'; import { configProvider } from '@adonisjs/core'; import { RuntimeException } from '@adonisjs/core/exceptions'; export default class CurrencyProvider { app; constructor(app) { this.app = app; } /** * Register currency service */ async register() { this.app.container.singleton('currency.manager', async () => { const currencyConfigProvider = this.app.config.get('currency'); if (!currencyConfigProvider) { throw new RuntimeException('Currency configuration not found. Make sure you have a "config/currency.ts" file with "defineConfig" export'); } const config = await configProvider.resolve(this.app, currencyConfigProvider); if (!config) { throw new RuntimeException('Invalid "config/currency.ts" file. Make sure you are using the "defineConfig" method'); } // Create currency service with all providers return createCurrency(config); }); } /** * Boot the provider */ async boot() { // Nothing to boot } /** * Shutdown the provider */ async shutdown() { // Nothing to shutdown } }