mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-28 11:21:38 -05:00
Add dao method to get count of slow delivery notifications by provider
This commit is contained in:
@@ -11,13 +11,16 @@ from sqlalchemy.orm import joinedload
|
||||
|
||||
from app import db, create_uuid
|
||||
from app.dao import days_ago
|
||||
from app.dao.provider_details_dao import get_provider_details_by_identifier
|
||||
from app.models import (
|
||||
Service,
|
||||
Notification,
|
||||
NotificationHistory,
|
||||
NotificationStatistics,
|
||||
ProviderDetails,
|
||||
Template,
|
||||
NOTIFICATION_CREATED,
|
||||
NOTIFICATION_DELIVERED,
|
||||
NOTIFICATION_SENDING,
|
||||
NOTIFICATION_PENDING,
|
||||
NOTIFICATION_TECHNICAL_FAILURE,
|
||||
@@ -421,3 +424,32 @@ def get_total_sent_notifications_in_date_range(start_date, end_date, notificatio
|
||||
).scalar()
|
||||
|
||||
return result or 0
|
||||
|
||||
|
||||
def get_count_of_slow_delivery_sms_notifications_for_provider(
|
||||
created_at,
|
||||
sent_at,
|
||||
provider,
|
||||
threshold,
|
||||
delivery_time,
|
||||
service_id,
|
||||
template_id
|
||||
):
|
||||
count = db.session.query(
|
||||
func.count().label('total'),
|
||||
Notification.sent_by
|
||||
).filter(
|
||||
Notification.service_id == service_id,
|
||||
Notification.template_id == template_id,
|
||||
Notification.created_at >= created_at,
|
||||
Notification.sent_at >= sent_at,
|
||||
Notification.status == NOTIFICATION_DELIVERED,
|
||||
Notification.sent_by == provider,
|
||||
(Notification.updated_at - Notification.sent_at) >= delivery_time,
|
||||
).group_by(
|
||||
Notification.sent_by
|
||||
).having(
|
||||
func.count().label('total') >= threshold,
|
||||
).first()
|
||||
|
||||
return count
|
||||
|
||||
Reference in New Issue
Block a user