mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Merge branch 'master' into integrate_MMG
This commit is contained in:
@@ -63,15 +63,10 @@ def dao_get_notification_statistics_for_service_and_day(service_id, day):
|
||||
def dao_get_template_statistics_for_service(service_id, limit_days=None):
|
||||
filter = [TemplateStatistics.service_id == service_id]
|
||||
if limit_days:
|
||||
latest_stat = TemplateStatistics.query.filter_by(service_id=service_id).order_by(
|
||||
desc(TemplateStatistics.day)).limit(1).first()
|
||||
if latest_stat:
|
||||
last_date_to_fetch = latest_stat.day - timedelta(days=limit_days)
|
||||
else:
|
||||
last_date_to_fetch = date.today() - timedelta(days=limit_days)
|
||||
last_date_to_fetch = date.today() - timedelta(days=limit_days)
|
||||
filter.append(TemplateStatistics.day > last_date_to_fetch)
|
||||
return TemplateStatistics.query.filter(*filter).order_by(
|
||||
desc(TemplateStatistics.day)).join(Template).order_by(func.lower(Template.name)).all()
|
||||
desc(TemplateStatistics.updated_at)).all()
|
||||
|
||||
|
||||
@transactional
|
||||
@@ -102,7 +97,7 @@ def dao_create_notification(notification, notification_type):
|
||||
day=date.today(),
|
||||
service_id=notification.service_id,
|
||||
template_id=notification.template_id
|
||||
).update({'usage_count': TemplateStatistics.usage_count + 1})
|
||||
).update({'usage_count': TemplateStatistics.usage_count + 1, 'updated_at': datetime.utcnow()})
|
||||
|
||||
if update_count == 0:
|
||||
template_stats = TemplateStatistics(template_id=notification.template_id,
|
||||
|
||||
@@ -362,3 +362,9 @@ class TemplateStatistics(db.Model):
|
||||
template = db.relationship('Template')
|
||||
usage_count = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=1)
|
||||
day = db.Column(db.Date, index=True, nullable=False, unique=False, default=datetime.date.today)
|
||||
updated_at = db.Column(
|
||||
db.DateTime,
|
||||
index=False,
|
||||
unique=False,
|
||||
nullable=False,
|
||||
default=datetime.datetime.utcnow)
|
||||
|
||||
Reference in New Issue
Block a user