feat: sincronizacion automatica de tasa bcv y ui#27
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds end-to-end support for automatically fetching Banco Central de Venezuela (BCV) exchange rates, persisting them server-side, optionally auto-applying them to events, and exposing/consuming the data from the web UI.
Changes:
- Added a new BCV rate domain (DB model + repository) plus a BCV provider/scraper and API module endpoints to fetch/sync rates.
- Extended
EventandExchangeRatemodels/types to supportautoSyncBcvand ratesource(manualvsbcv), including UI updates to toggle auto-sync and display source. - Added scraping dependencies (
cheerio,undici) and wired the provider into the API container.
Reviewed changes
Copilot reviewed 33 out of 34 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Locks new dependencies (notably cheerio/undici) required for scraping. |
| packages/web/src/features/events/services/bcvService.ts | Adds web client methods to read/sync BCV rates via API. |
| packages/web/src/features/events/pages/EventConfigPage.tsx | Adds BCV rate card, manual sync button, auto-sync toggle, and source display in UI. |
| packages/web/src/features/events/hooks/useCurrentExchangeRate.ts | Adds refetch-on-custom-event behavior for exchange rate updates. |
| packages/shared/src/utils/currency.ts | Adds getEurUsdRate helper derived from BCV EUR/USD Bs rates. |
| packages/shared/src/types/index.ts | Exports newly added BCV types. |
| packages/shared/src/types/exchangeRate.types.ts | Extends exchange rate type with source and nullable setBy*. |
| packages/shared/src/types/event.types.ts | Extends event type with autoSyncBcv. |
| packages/shared/src/types/bcv.types.ts | Introduces BcvRateType shared contract. |
| packages/shared/src/schemas/event.schemas.ts | Allows autoSyncBcv in event create/update schemas. |
| packages/api/src/modules/exchange-rates/exchange-rates.service.ts | Adds source + optional setBy to exchange rate creation. |
| packages/api/src/modules/exchange-rates/exchange-rates.mapper.ts | Maps new source and optional setBy* fields. |
| packages/api/src/modules/events/events.service.ts | Persists and updates autoSyncBcv on events. |
| packages/api/src/modules/events/events.mapper.ts | Exposes autoSyncBcv in API event payloads. |
| packages/api/src/modules/bcv/index.ts | Registers BCV module composition (service/controller/router). |
| packages/api/src/modules/bcv/bcv.service.ts | Implements BCV rate read/sync service. |
| packages/api/src/modules/bcv/bcv.routes.ts | Defines authenticated BCV endpoints (GET /, POST /sync). |
| packages/api/src/modules/bcv/bcv.mapper.ts | Maps BCV rate entity to shared BcvRateType. |
| packages/api/src/modules/bcv/bcv.controller.ts | Adds controller handlers for read/sync. |
| packages/api/src/infrastructure/repositories/PrismaExchangeRateRepository.ts | Persists and maps new exchange-rate source and nullable setBy. |
| packages/api/src/infrastructure/repositories/PrismaEventRepository.ts | Persists/maps new autoSyncBcv field. |
| packages/api/src/infrastructure/repositories/PrismaBcvRateRepository.ts | Adds Prisma-backed persistence for BCV rates. |
| packages/api/src/infrastructure/container.ts | Wires BCV provider + repository and mounts BCV module routes. |
| packages/api/src/infrastructure/bcv/scraper.ts | Implements BCV HTML scraping using undici + cheerio. |
| packages/api/src/infrastructure/bcv/provider.ts | Implements caching, refresh logic, and auto-sync propagation to events. |
| packages/api/src/core/interfaces/repositories/IExchangeRateRepository.ts | Updates exchange-rate repository contract for source + optional setBy. |
| packages/api/src/core/interfaces/repositories/IEventRepository.ts | Updates event repository contract for autoSyncBcv. |
| packages/api/src/core/interfaces/repositories/IBcvRateRepository.ts | Introduces BCV rate repository contract. |
| packages/api/src/core/entities/ExchangeRate.ts | Extends domain entity with source and nullable setBy*. |
| packages/api/src/core/entities/Event.ts | Extends domain entity with autoSyncBcv. |
| packages/api/src/core/entities/BcvRate.ts | Introduces BCV rate domain entity. |
| packages/api/prisma/schema.prisma | Adds autoSyncBcv, exchange-rate source, nullable setBy, and BcvRate model. |
| packages/api/prisma/migrations/20260602032103_add_bcv/migration.sql | Creates/updates tables & constraints for BCV + new exchange-rate fields. |
| packages/api/package.json | Adds cheerio and undici dependencies to API package. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚀 Pull Request: Sistema de Sincronización de Tasas BCV
Este Pull Request introduce un nuevo sistema para sincronizar automáticamente las tasas de cambio del Banco Central de Venezuela (BCV). Incluye la infraestructura necesaria para el scraping (extracción de datos), persistencia en base de datos y la auto-aplicación de estas tasas a los eventos.
✨ Aspectos Clave
BcvRate: Creada para almacenar las tasas obtenidas.ExchangeRateyEventpara soportar la sincronización automática.🛠️ Cambios Detallados
🔄 Sistema de Auto-Sincronización de Tasas BCV
BcvRatepara almacenar las tasas del BCV, junto con el esquema de Prisma y su respectiva migración. [1] [2] [3] [4] [5]BcvProvider: Se implementó este servicio para consultar, guardar en caché y refrescar las tasas, actualizando automáticamente los eventos que tengan la opciónautoSyncBcvactiva.cheerioyundicipara extraer los valores actualizados del USD y EUR directamente desde la página oficial del BCV.📊 Cambios en Esquemas y Entidades
Event: Se extendió para incluir el campo booleanoautoSyncBcv, permitiendo a cada evento decidir si desea activar la sincronización automática. [1] [2] [3] [4] [5] [6] [7] [8] [9]ExchangeRate: Se actualizó para admitir el camposource(manualobcv). Además, el camposetByahora permite valores nulos (nullable) para diferenciar si la tasa fue fijada de forma manual por un usuario o de forma automática por el sistema. [1] [2] [3] [4]📦 Nuevas Dependencias
cheerio(para el parsing de HTML) yundici(para realizar peticiones HTTP de manera eficiente). [1] [2]close #26