mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-08 08:28:24 -04:00
more code review feedback
This commit is contained in:
@@ -96,7 +96,7 @@ def dao_fetch_live_services_data():
|
||||
|
||||
this_year_ft_billing = (
|
||||
select(FactBilling)
|
||||
.filter(
|
||||
.where(
|
||||
FactBilling.local_date >= year_start_date,
|
||||
FactBilling.local_date <= year_end_date,
|
||||
)
|
||||
@@ -145,7 +145,7 @@ def dao_fetch_live_services_data():
|
||||
this_year_ft_billing, Service.id == this_year_ft_billing.c.service_id
|
||||
)
|
||||
.outerjoin(User, Service.go_live_user_id == User.id)
|
||||
.filter(
|
||||
.where(
|
||||
Service.count_as_live.is_(True),
|
||||
Service.active.is_(True),
|
||||
Service.restricted.is_(False),
|
||||
@@ -221,7 +221,7 @@ def dao_fetch_service_by_id_with_api_keys(service_id, only_active=False):
|
||||
.options(joinedload(Service.api_keys))
|
||||
)
|
||||
if only_active:
|
||||
stmt = stmt.filter(Service.active)
|
||||
stmt = stmt.where(Service.active)
|
||||
return db.session.execute(stmt).scalars().unique().one()
|
||||
|
||||
|
||||
@@ -229,12 +229,12 @@ def dao_fetch_all_services_by_user(user_id, only_active=False):
|
||||
|
||||
stmt = (
|
||||
select(Service)
|
||||
.filter(Service.users.any(id=user_id))
|
||||
.where(Service.users.any(id=user_id))
|
||||
.order_by(asc(Service.created_at))
|
||||
.options(joinedload(Service.users))
|
||||
)
|
||||
if only_active:
|
||||
stmt = stmt.filter(Service.active)
|
||||
stmt = stmt.where(Service.active)
|
||||
return db.session.execute(stmt).scalars().unique().all()
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ def dao_archive_service(service_id):
|
||||
joinedload(Service.templates).subqueryload(Template.template_redacted),
|
||||
joinedload(Service.api_keys),
|
||||
)
|
||||
.filter(Service.id == service_id)
|
||||
.where(Service.id == service_id)
|
||||
)
|
||||
service = db.session.execute(stmt).scalars().unique().one()
|
||||
|
||||
@@ -283,7 +283,7 @@ def dao_fetch_service_by_id_and_user(service_id, user_id):
|
||||
|
||||
stmt = (
|
||||
select(Service)
|
||||
.filter(Service.users.any(id=user_id), Service.id == service_id)
|
||||
.where(Service.users.any(id=user_id), Service.id == service_id)
|
||||
.options(joinedload(Service.users))
|
||||
)
|
||||
result = db.session.execute(stmt).scalar_one()
|
||||
@@ -396,7 +396,7 @@ def delete_service_and_all_associated_db_objects(service):
|
||||
|
||||
subq = select(Template.id).where(Template.service == service).subquery()
|
||||
|
||||
stmt = delete(TemplateRedacted).filter(TemplateRedacted.template_id.in_(subq))
|
||||
stmt = delete(TemplateRedacted).where(TemplateRedacted.template_id.in_(subq))
|
||||
_delete_commit(stmt)
|
||||
|
||||
_delete_commit(delete(ServiceSmsSender).where(ServiceSmsSender.service == service))
|
||||
@@ -426,7 +426,7 @@ def delete_service_and_all_associated_db_objects(service):
|
||||
_delete_commit(delete(AnnualBilling).where(AnnualBilling.service_id == service.id))
|
||||
|
||||
stmt = (
|
||||
select(VerifyCode).join(User).filter(User.id.in_([x.id for x in service.users]))
|
||||
select(VerifyCode).join(User).where(User.id.in_([x.id for x in service.users]))
|
||||
)
|
||||
verify_codes = db.session.execute(stmt).scalars().all()
|
||||
list(map(db.session.delete, verify_codes))
|
||||
@@ -452,7 +452,7 @@ def dao_fetch_todays_stats_for_service(service_id):
|
||||
Notification.status,
|
||||
func.count(Notification.id).label("count"),
|
||||
)
|
||||
.filter(
|
||||
.where(
|
||||
Notification.service_id == service_id,
|
||||
Notification.key_type != KeyType.TEST,
|
||||
Notification.created_at >= start_date,
|
||||
@@ -476,7 +476,7 @@ def dao_fetch_stats_for_service_from_days(service_id, start_date, end_date):
|
||||
func.date_trunc("day", NotificationAllTimeView.created_at).label("day"),
|
||||
func.count(NotificationAllTimeView.id).label("count"),
|
||||
)
|
||||
.filter(
|
||||
.where(
|
||||
NotificationAllTimeView.service_id == service_id,
|
||||
NotificationAllTimeView.key_type != KeyType.TEST,
|
||||
NotificationAllTimeView.created_at >= start_date,
|
||||
@@ -505,7 +505,7 @@ def dao_fetch_stats_for_service_from_days_for_user(
|
||||
func.count(NotificationAllTimeView.id).label("count"),
|
||||
)
|
||||
.select_from(NotificationAllTimeView)
|
||||
.filter(
|
||||
.where(
|
||||
NotificationAllTimeView.service_id == service_id,
|
||||
NotificationAllTimeView.key_type != KeyType.TEST,
|
||||
NotificationAllTimeView.created_at >= start_date,
|
||||
@@ -535,7 +535,7 @@ def dao_fetch_todays_stats_for_all_services(
|
||||
Notification.service_id,
|
||||
func.count(Notification.id).label("count"),
|
||||
)
|
||||
.filter(
|
||||
.where(
|
||||
Notification.created_at >= start_date, Notification.created_at < end_date
|
||||
)
|
||||
.group_by(
|
||||
@@ -544,7 +544,7 @@ def dao_fetch_todays_stats_for_all_services(
|
||||
)
|
||||
|
||||
if not include_from_test_key:
|
||||
substmt = substmt.filter(Notification.key_type != KeyType.TEST)
|
||||
substmt = substmt.where(Notification.key_type != KeyType.TEST)
|
||||
|
||||
substmt = substmt.subquery()
|
||||
|
||||
@@ -564,7 +564,7 @@ def dao_fetch_todays_stats_for_all_services(
|
||||
)
|
||||
|
||||
if only_active:
|
||||
stmt = stmt.filter(Service.active)
|
||||
stmt = stmt.where(Service.active)
|
||||
|
||||
return db.session.execute(stmt).all()
|
||||
|
||||
@@ -579,7 +579,7 @@ def dao_suspend_service(service_id):
|
||||
stmt = (
|
||||
select(Service)
|
||||
.options(joinedload(Service.api_keys))
|
||||
.filter(Service.id == service_id)
|
||||
.where(Service.id == service_id)
|
||||
)
|
||||
service = db.session.execute(stmt).scalars().unique().one()
|
||||
|
||||
@@ -612,7 +612,7 @@ def dao_find_services_sending_to_tv_numbers(start_date, end_date, threshold=500)
|
||||
Notification.service_id.label("service_id"),
|
||||
func.count(Notification.id).label("notification_count"),
|
||||
)
|
||||
.filter(
|
||||
.where(
|
||||
Notification.service_id == Service.id,
|
||||
Notification.created_at >= start_date,
|
||||
Notification.created_at <= end_date,
|
||||
@@ -636,7 +636,7 @@ def dao_find_services_with_high_failure_rates(start_date, end_date, threshold=10
|
||||
func.count(Notification.id).label("total_count"),
|
||||
Notification.service_id.label("service_id"),
|
||||
)
|
||||
.filter(
|
||||
.where(
|
||||
Notification.service_id == Service.id,
|
||||
Notification.created_at >= start_date,
|
||||
Notification.created_at <= end_date,
|
||||
@@ -664,7 +664,7 @@ def dao_find_services_with_high_failure_rates(start_date, end_date, threshold=10
|
||||
).label("permanent_failure_rate"),
|
||||
)
|
||||
.join(substmt, substmt.c.service_id == Notification.service_id)
|
||||
.filter(
|
||||
.where(
|
||||
Notification.service_id == Service.id,
|
||||
Notification.created_at >= start_date,
|
||||
Notification.created_at <= end_date,
|
||||
@@ -696,7 +696,7 @@ def get_live_services_with_organization():
|
||||
)
|
||||
.select_from(Service)
|
||||
.outerjoin(Service.organization)
|
||||
.filter(
|
||||
.where(
|
||||
Service.count_as_live.is_(True),
|
||||
Service.active.is_(True),
|
||||
Service.restricted.is_(False),
|
||||
@@ -718,7 +718,7 @@ def fetch_notification_stats_for_service_by_month_by_user(
|
||||
(NotificationAllTimeView.status).label("notification_status"),
|
||||
func.count(NotificationAllTimeView.id).label("count"),
|
||||
)
|
||||
.filter(
|
||||
.where(
|
||||
NotificationAllTimeView.service_id == service_id,
|
||||
NotificationAllTimeView.created_at >= start_date,
|
||||
NotificationAllTimeView.created_at < end_date,
|
||||
|
||||
Reference in New Issue
Block a user