Files
notifications-api/app/dao/service_user_dao.py
Rebecca Law 68d28aa83b The update of SQLAlchemy 1.4.10 has caused some conflicts in our code. This PR fixes most of those conflicts.
- sqlalchemy.sql.expression.case must include an else statement.
- clearly define list of columns for inbound_sms_history insert, getting the list from InboundSmsHistory.__table__.c was causing data type errors.
- remove relationships when not needed, the foreign key relationship is established in the creation of the column. This will get rid of the warnings referenced here: http://sqlalche.me/e/14/qzyx.
- update queries now that he user relationship in ServiceUser db model has been removed.
- move the check that a template is archived to the view instead of the dao method. The check was clearing the session before the version history could be done.

Deleting notifications in the night tasks still needs to be
investigated. The raw sql is causing an error.
2021-04-29 13:32:36 +01:00

31 lines
713 B
Python

from app import db
from app.dao.dao_utils import autocommit
from app.models import ServiceUser, User
def dao_get_service_user(user_id, service_id):
return ServiceUser.query.filter_by(user_id=user_id, service_id=service_id).one()
def dao_get_active_service_users(service_id):
query = db.session.query(
ServiceUser
).join(
User, User.id == ServiceUser.user_id
).filter(
User.state == 'active',
ServiceUser.service_id == service_id
)
return query.all()
def dao_get_service_users_by_user_id(user_id):
return ServiceUser.query.filter_by(user_id=user_id).all()
@autocommit
def dao_update_service_user(service_user):
db.session.add(service_user)