Update get_notification_by_id to take an optional service_id

It can be useful to get a notification by id while checking that the
notification belongs to a given service. This changes the
get_notification_by_id DAO function to optionally also filter by
service_id so that we can check this.
This commit is contained in:
Katie Smith
2018-11-15 10:55:29 +00:00
parent 902e1b403a
commit 365c462e93
2 changed files with 31 additions and 6 deletions

View File

@@ -227,11 +227,15 @@ def get_notification_with_personalisation(service_id, notification_id, key_type)
@statsd(namespace="dao")
def get_notification_by_id(notification_id, _raise=False):
if _raise:
return Notification.query.filter_by(id=notification_id).one()
else:
return Notification.query.filter_by(id=notification_id).first()
def get_notification_by_id(notification_id, service_id=None, _raise=False):
filters = [Notification.id == notification_id]
if service_id:
filters.append(Notification.service_id == service_id)
query = Notification.query.filter(*filters)
return query.one() if _raise else query.first()
def get_notifications(filter_dict=None):