mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user