2018-07-11 17:02:49 +01:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
from app import db
|
2021-04-14 07:11:01 +01:00
|
|
|
from app.dao.dao_utils import autocommit
|
2018-07-11 17:02:49 +01:00
|
|
|
from app.models import ServiceDataRetention
|
|
|
|
|
|
|
|
|
|
|
2018-07-13 15:18:27 +01:00
|
|
|
def fetch_service_data_retention_by_id(service_id, data_retention_id):
|
2023-08-29 14:54:30 -07:00
|
|
|
data_retention = ServiceDataRetention.query.filter_by(
|
|
|
|
|
service_id=service_id, id=data_retention_id
|
|
|
|
|
).first()
|
2018-07-11 17:02:49 +01:00
|
|
|
return data_retention
|
|
|
|
|
|
|
|
|
|
|
2018-07-13 15:18:27 +01:00
|
|
|
def fetch_service_data_retention(service_id):
|
2023-08-29 14:54:30 -07:00
|
|
|
data_retention_list = (
|
|
|
|
|
ServiceDataRetention.query.filter_by(service_id=service_id)
|
|
|
|
|
.order_by(
|
|
|
|
|
# in the order that models.notification_types are created (email, sms, letter)
|
|
|
|
|
ServiceDataRetention.notification_type
|
|
|
|
|
)
|
|
|
|
|
.all()
|
|
|
|
|
)
|
2018-07-13 15:18:27 +01:00
|
|
|
return data_retention_list
|
|
|
|
|
|
|
|
|
|
|
2018-08-06 13:51:54 +01:00
|
|
|
def fetch_service_data_retention_by_notification_type(service_id, notification_type):
|
|
|
|
|
data_retention_list = ServiceDataRetention.query.filter_by(
|
2023-08-29 14:54:30 -07:00
|
|
|
service_id=service_id, notification_type=notification_type
|
2018-08-06 13:51:54 +01:00
|
|
|
).first()
|
|
|
|
|
return data_retention_list
|
|
|
|
|
|
|
|
|
|
|
2021-04-14 07:11:01 +01:00
|
|
|
@autocommit
|
2018-07-11 17:02:49 +01:00
|
|
|
def insert_service_data_retention(service_id, notification_type, days_of_retention):
|
2023-08-29 14:54:30 -07:00
|
|
|
new_data_retention = ServiceDataRetention(
|
|
|
|
|
service_id=service_id,
|
|
|
|
|
notification_type=notification_type,
|
|
|
|
|
days_of_retention=days_of_retention,
|
|
|
|
|
)
|
2018-07-11 17:02:49 +01:00
|
|
|
|
|
|
|
|
db.session.add(new_data_retention)
|
|
|
|
|
return new_data_retention
|
|
|
|
|
|
|
|
|
|
|
2021-04-14 07:11:01 +01:00
|
|
|
@autocommit
|
2023-08-29 14:54:30 -07:00
|
|
|
def update_service_data_retention(
|
|
|
|
|
service_data_retention_id, service_id, days_of_retention
|
|
|
|
|
):
|
2018-07-11 17:02:49 +01:00
|
|
|
updated_count = ServiceDataRetention.query.filter(
|
|
|
|
|
ServiceDataRetention.id == service_data_retention_id,
|
2023-08-29 14:54:30 -07:00
|
|
|
ServiceDataRetention.service_id == service_id,
|
|
|
|
|
).update({"days_of_retention": days_of_retention, "updated_at": datetime.utcnow()})
|
2018-07-11 17:02:49 +01:00
|
|
|
return updated_count
|
2021-12-06 09:30:48 +00:00
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
def fetch_service_data_retention_for_all_services_by_notification_type(
|
|
|
|
|
notification_type,
|
|
|
|
|
):
|
|
|
|
|
return ServiceDataRetention.query.filter(
|
|
|
|
|
ServiceDataRetention.notification_type == notification_type
|
|
|
|
|
).all()
|