Skip to content

Commit

Permalink
feat(auto_account_deletion_days): lint + refact sqla queries +
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquesfize committed Apr 3, 2024
1 parent e190aff commit a70c2ca
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app/api/route_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from app.utils.utilssqlalchemy import json_resp
from app.models import TRoles, CorRoleAppProfil, TProfils, CorRoles

import sqlalchemy as sa

route = Blueprint("api_register", __name__)

Expand Down Expand Up @@ -85,16 +86,18 @@ def create_temp_user():
return {"msg": msg}, 400

# Delete duplicate entries
db.session.query(TempUser).filter(
TempUser.identifiant == temp_user.identifiant
).delete()
db.session.execute(
sa.delete(TempUser).where(TempUser.identifiant == temp_user.identifiant)
)
db.session.commit()


# Delete old entries (cleaning)
db.session.query(TempUser).filter(
TempUser.date_insert <= (datetime.now() - timedelta(days=current_app.config["AUTO_ACCOUNT_DELETION_DAYS"]))
).delete()
days = 7 if not "AUTO_ACCOUNT_DELETION_DAYS" in current_app.config else 7
db.session.execute(
sa.delete(TempUser).where(
TempUser.date_insert <= (datetime.now() - timedelta(days=days))
)
)
db.session.commit()

# Update attributes
Expand Down

0 comments on commit a70c2ca

Please sign in to comment.