mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
fix complaint_dao
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from sqlalchemy import desc
|
from sqlalchemy import desc, func, select
|
||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
from app.dao.dao_utils import autocommit
|
from app.dao.dao_utils import autocommit
|
||||||
@@ -21,17 +21,21 @@ def fetch_paginated_complaints(page=1):
|
|||||||
|
|
||||||
|
|
||||||
def fetch_complaints_by_service(service_id):
|
def fetch_complaints_by_service(service_id):
|
||||||
return (
|
stmt = (
|
||||||
Complaint.query.filter_by(service_id=service_id)
|
select(Complaint)
|
||||||
|
.filter_by(service_id=service_id)
|
||||||
.order_by(desc(Complaint.created_at))
|
.order_by(desc(Complaint.created_at))
|
||||||
.all()
|
|
||||||
)
|
)
|
||||||
|
return db.session.execute(stmt).scalars().all()
|
||||||
|
|
||||||
|
|
||||||
def fetch_count_of_complaints(start_date, end_date):
|
def fetch_count_of_complaints(start_date, end_date):
|
||||||
start_date = get_midnight_in_utc(start_date)
|
start_date = get_midnight_in_utc(start_date)
|
||||||
end_date = get_midnight_in_utc(end_date + timedelta(days=1))
|
end_date = get_midnight_in_utc(end_date + timedelta(days=1))
|
||||||
|
|
||||||
return Complaint.query.filter(
|
stmt = (
|
||||||
Complaint.created_at >= start_date, Complaint.created_at < end_date
|
select(func.count())
|
||||||
).count()
|
.select_from(Complaint)
|
||||||
|
.filter(Complaint.created_at >= start_date, Complaint.created_at < end_date)
|
||||||
|
)
|
||||||
|
return db.session.execute(stmt).scalar() or 0
|
||||||
|
|||||||
Reference in New Issue
Block a user