add get_earlier_provider_message fn to broadcast_event

replacing get_earlier_provider_messages. The old function returned the
previous references for earlier events for a broadcast_message. However,
these depend on the message sent to a specific provider, so the function
needs to change. It now takes in a provider, and only returns
broadcast_provider_messages sent to that provider. If there are earlier
broadcast_events without a provider_message for the chosen provider, it
raises an exception - you cannot cancel a message if all the previous
events have not been created properly (as we wouldn't know what
references to cancel).
This commit is contained in:
Leo Hemsted
2020-11-17 12:35:10 +00:00
parent f12c949ae9
commit 0257774cfa
6 changed files with 72 additions and 24 deletions

View File

@@ -62,7 +62,8 @@ from app.models import (
ServiceContactList,
BroadcastMessage,
BroadcastStatusType,
BroadcastEvent
BroadcastEvent,
BroadcastProviderMessage
)
@@ -1050,3 +1051,18 @@ def create_broadcast_event(
db.session.add(b_e)
db.session.commit()
return b_e
def create_broadcast_provider_message(
broadcast_event,
provider,
status='sending'
):
provider_message = BroadcastProviderMessage(
broadcast_event=broadcast_event,
provider=provider,
status=status
)
db.session.add(provider_message)
db.session.commit()
return provider_message