2017-09-08 11:14:26 +01:00
|
|
|
from app import db
|
|
|
|
|
from app.dao.dao_utils import transactional
|
2017-09-14 12:23:52 +01:00
|
|
|
from app.errors import InvalidRequest
|
2017-09-08 11:14:26 +01:00
|
|
|
from app.models import ServiceEmailReplyTo
|
|
|
|
|
|
|
|
|
|
|
2017-09-14 12:23:52 +01:00
|
|
|
def dao_get_reply_to_by_service_id(service_id):
|
|
|
|
|
reply_to = db.session.query(
|
|
|
|
|
ServiceEmailReplyTo
|
|
|
|
|
).filter(
|
|
|
|
|
ServiceEmailReplyTo.service_id == service_id
|
|
|
|
|
).all()
|
|
|
|
|
return reply_to
|
|
|
|
|
|
|
|
|
|
|
2017-09-08 11:14:26 +01:00
|
|
|
def create_or_update_email_reply_to(service_id, email_address):
|
|
|
|
|
reply_to = dao_get_reply_to_by_service_id(service_id)
|
2017-09-13 15:27:00 +01:00
|
|
|
if len(reply_to) == 0:
|
2017-09-08 11:14:26 +01:00
|
|
|
reply_to = ServiceEmailReplyTo(service_id=service_id, email_address=email_address)
|
|
|
|
|
dao_create_reply_to_email_address(reply_to)
|
2017-09-13 15:27:00 +01:00
|
|
|
elif len(reply_to) == 1:
|
|
|
|
|
reply_to[0].email_address = email_address
|
|
|
|
|
dao_update_reply_to_email(reply_to[0])
|
|
|
|
|
else:
|
2017-09-14 12:23:52 +01:00
|
|
|
# Once we move allowing multiple email address this methods will be removed
|
2017-09-13 15:27:00 +01:00
|
|
|
raise InvalidRequest(
|
|
|
|
|
"Multiple reply to email addresses were found, this method should not be used.",
|
|
|
|
|
status_code=500
|
|
|
|
|
)
|
2017-09-08 11:14:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@transactional
|
|
|
|
|
def dao_create_reply_to_email_address(reply_to_email):
|
|
|
|
|
db.session.add(reply_to_email)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@transactional
|
|
|
|
|
def dao_update_reply_to_email(reply_to):
|
|
|
|
|
db.session.add(reply_to)
|