mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-31 04:41:56 -05:00
fix complaint_dao
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from flask import current_app
|
||||
from sqlalchemy import desc
|
||||
from sqlalchemy import desc, func, select
|
||||
|
||||
from app import db
|
||||
from app.dao.dao_utils import autocommit
|
||||
@@ -21,17 +21,21 @@ def fetch_paginated_complaints(page=1):
|
||||
|
||||
|
||||
def fetch_complaints_by_service(service_id):
|
||||
return (
|
||||
Complaint.query.filter_by(service_id=service_id)
|
||||
stmt = (
|
||||
select(Complaint)
|
||||
.filter_by(service_id=service_id)
|
||||
.order_by(desc(Complaint.created_at))
|
||||
.all()
|
||||
)
|
||||
return db.session.execute(stmt).scalars().all()
|
||||
|
||||
|
||||
def fetch_count_of_complaints(start_date, end_date):
|
||||
start_date = get_midnight_in_utc(start_date)
|
||||
end_date = get_midnight_in_utc(end_date + timedelta(days=1))
|
||||
|
||||
return Complaint.query.filter(
|
||||
Complaint.created_at >= start_date, Complaint.created_at < end_date
|
||||
).count()
|
||||
stmt = (
|
||||
select(func.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