Files
dibbler/dibbler/queries/adjust_interest.py
h7x4 e9ce51b97b
All checks were successful
Run tests / run-tests (push) Successful in 1m23s
fixup! WIP
2025-12-10 15:38:32 +09:00

29 lines
734 B
Python

from sqlalchemy.orm import Session
from dibbler.models import Transaction, User
# TODO: this type of transaction should be password protected.
# the password can be set as a string literal in the config file.
def adjust_interest(
sql_session: Session,
user: User,
new_interest: int,
message: str | None = None,
) -> None:
if new_interest < 0:
raise ValueError("Interest rate cannot be negative")
if user.id is None:
raise ValueError("User must be persisted in the database.")
transaction = Transaction.adjust_interest(
user_id=user.id,
interest_rate_percent=new_interest,
message=message,
)
sql_session.add(transaction)
sql_session.commit()