mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-25 00:33:41 -04:00
fix inbound_number_dao
This commit is contained in:
@@ -1,24 +1,30 @@
|
|||||||
|
from sqlalchemy import select, update
|
||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
from app.dao.dao_utils import autocommit
|
from app.dao.dao_utils import autocommit
|
||||||
from app.models import InboundNumber
|
from app.models import InboundNumber
|
||||||
|
|
||||||
|
|
||||||
def dao_get_inbound_numbers():
|
def dao_get_inbound_numbers():
|
||||||
return InboundNumber.query.order_by(InboundNumber.updated_at).all()
|
stmt = select(InboundNumber).order_by(InboundNumber.updated_at)
|
||||||
|
return db.session.execute(stmt).all()
|
||||||
|
|
||||||
|
|
||||||
def dao_get_available_inbound_numbers():
|
def dao_get_available_inbound_numbers():
|
||||||
return InboundNumber.query.filter(
|
stmt = select(InboundNumber).filter(
|
||||||
InboundNumber.active, InboundNumber.service_id.is_(None)
|
InboundNumber.active, InboundNumber.service_id.is_(None)
|
||||||
).all()
|
)
|
||||||
|
return db.session.execute(stmt).all()
|
||||||
|
|
||||||
|
|
||||||
def dao_get_inbound_number_for_service(service_id):
|
def dao_get_inbound_number_for_service(service_id):
|
||||||
return InboundNumber.query.filter(InboundNumber.service_id == service_id).first()
|
stmt = select(InboundNumber).filter(InboundNumber.service_id == service_id)
|
||||||
|
return db.session.execute(stmt).scalars().first()
|
||||||
|
|
||||||
|
|
||||||
def dao_get_inbound_number(inbound_number_id):
|
def dao_get_inbound_number(inbound_number_id):
|
||||||
return InboundNumber.query.filter(InboundNumber.id == inbound_number_id).first()
|
stmt = select(InboundNumber).filter(InboundNumber.id == inbound_number_id)
|
||||||
|
return db.session.execute(stmt).scalars().first()
|
||||||
|
|
||||||
|
|
||||||
@autocommit
|
@autocommit
|
||||||
@@ -29,9 +35,8 @@ def dao_set_inbound_number_to_service(service_id, inbound_number):
|
|||||||
|
|
||||||
@autocommit
|
@autocommit
|
||||||
def dao_set_inbound_number_active_flag(service_id, active):
|
def dao_set_inbound_number_active_flag(service_id, active):
|
||||||
inbound_number = InboundNumber.query.filter(
|
stmt = select(InboundNumber).filter(InboundNumber.service_id == service_id)
|
||||||
InboundNumber.service_id == service_id
|
inbound_number = db.session.execute(stmt).scalars().first()
|
||||||
).first()
|
|
||||||
inbound_number.active = active
|
inbound_number.active = active
|
||||||
|
|
||||||
db.session.add(inbound_number)
|
db.session.add(inbound_number)
|
||||||
@@ -39,9 +44,13 @@ def dao_set_inbound_number_active_flag(service_id, active):
|
|||||||
|
|
||||||
@autocommit
|
@autocommit
|
||||||
def dao_allocate_number_for_service(service_id, inbound_number_id):
|
def dao_allocate_number_for_service(service_id, inbound_number_id):
|
||||||
updated = InboundNumber.query.filter_by(
|
stmt = (
|
||||||
id=inbound_number_id, active=True, service_id=None
|
update(InboundNumber)
|
||||||
).update({"service_id": service_id})
|
.filter_by(id=inbound_number_id, active=True, service_id=None)
|
||||||
if not updated:
|
.values({"service_id": service_id})
|
||||||
|
)
|
||||||
|
result = db.session.execute(stmt)
|
||||||
|
db.session.commit()
|
||||||
|
if not result.rowcount == 0:
|
||||||
raise Exception("Inbound number: {} is not available".format(inbound_number_id))
|
raise Exception("Inbound number: {} is not available".format(inbound_number_id))
|
||||||
return InboundNumber.query.get(inbound_number_id)
|
return db.session.get(InboundNumber, inbound_number_id)
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ def _create_service_invite(invited_user, invite_link_host):
|
|||||||
redis_store.set(
|
redis_store.set(
|
||||||
f"email-personalisation-{saved_notification.id}",
|
f"email-personalisation-{saved_notification.id}",
|
||||||
json.dumps(personalisation),
|
json.dumps(personalisation),
|
||||||
ex=2*24*60*60,
|
ex=2 * 24 * 60 * 60,
|
||||||
)
|
)
|
||||||
send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)
|
send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user