Files
plantillas-proyectos/backend/api/v1/modules/a76/exchange_rate/services.py
acazares 52b8fcd434 feat: Implement multi-tenancy support in middleware and security layers
- Enhanced TenantMiddleware to validate tenant information from JWT tokens.
- Added LicenseValidationMiddleware to check tenant licenses before processing requests.
- Updated security utilities to extract tenant information from tokens and validate company access.
- Introduced CompanyStore to manage active company state and handle company switching in the frontend.
- Modified API routes to include company_id in requests for better resource management.
- Improved logging and error handling throughout the middleware and API layers.
- Updated frontend components to reflect changes in company management and selection.
- Added new API route for fetching user's companies with proper authentication handling.
2025-11-11 14:15:31 -06:00

31 lines
905 B
Python

from sqlalchemy.orm import Session
from . import models, dto
class ExchangeRateService:
@staticmethod
def get_exchange_rate_by_date(db: Session, date: int):
return (
db.query(models.ExchangeRate)
.filter(models.ExchangeRate.date == date)
.first()
)
@staticmethod
def create_exchange_rate(
db: Session, exchange_rate_data: dto.ExchangeRateCreateDTO
):
new_exchange_rate = models.ExchangeRate(**exchange_rate_data.dict())
db.add(new_exchange_rate)
db.commit()
db.refresh(new_exchange_rate)
return new_exchange_rate
@staticmethod
def delete_exchange_rate(db: Session, date: int):
exchange_rate = ExchangeRateService.get_exchange_rate_by_date(db, date)
if exchange_rate:
db.delete(exchange_rate)
db.commit()
return exchange_rate