- Rearranged imports in multiple files for consistency and clarity. - Updated logging middleware to exclude specific paths from logging. - Enhanced security module by cleaning up token handling and improving tenant validation. - Added tenant and company scoped mixins for better database model management. - Implemented generic CRUD routes for tenant-scoped resources. - Improved error handling and response management in API routes. - Cleaned up login and logout processes to ensure proper session management. - Introduced mechanisms to clear local storage and cookies on tenant change. - Enhanced company store to detect tenant changes and clear data accordingly. - Added new DTO mixins for currency and value affect flags.
32 lines
906 B
Python
32 lines
906 B
Python
from sqlalchemy.orm import Session
|
|
|
|
from . import dto, models
|
|
|
|
|
|
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
|