mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 22:42:28 -05:00
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:
@@ -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()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user