Refactor code for dao_fetch_servies_by_sms_sender to use inbound_numbers

This will need to be refactored after the deployment of api and admin and after the update script for existing services using inbound numbers has been executed.
This commit is contained in:
Ken Tsang
2017-08-16 12:27:42 +01:00
parent ce962380e3
commit c36423aac6
5 changed files with 113 additions and 22 deletions

View File

@@ -1,7 +1,7 @@
import uuid
from datetime import date, datetime, timedelta
from sqlalchemy import asc, func
from sqlalchemy import asc, func, or_, and_
from sqlalchemy.orm import joinedload
from flask import current_app
@@ -19,6 +19,7 @@ from app.models import (
Template,
TemplateHistory,
TemplateRedacted,
InboundNumber,
Job,
NotificationHistory,
Notification,
@@ -65,9 +66,22 @@ def dao_fetch_service_by_id(service_id, only_active=False):
return query.one()
############
# refactor this when API only uses inbound_numbers and not sms_sender
############
def dao_fetch_services_by_sms_sender(sms_sender):
inbound_number = InboundNumber.query.filter(
InboundNumber.number == sms_sender
).first()
if not inbound_number:
return []
return Service.query.filter(
Service.sms_sender == sms_sender
or_(
Service.sms_sender == sms_sender,
Service.id == inbound_number.service_id
)
).all()