add relationship
This commit is contained in:
@@ -73,15 +73,34 @@ def enroll(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
for entity in linked_entities:
|
# Relationships between this enrollment and its related entities
|
||||||
keyprefix = entity.type.lower()
|
for parent_entity in linked_entities:
|
||||||
|
perent_id = parent_entity.id
|
||||||
|
entity_sk = f'LINKED_ENTITIES#{parent_entity.type}'
|
||||||
|
keyprefix = parent_entity.type.lower()
|
||||||
|
|
||||||
|
# Child knows the parent
|
||||||
transact.put(
|
transact.put(
|
||||||
item={
|
item={
|
||||||
'id': enrollment.id,
|
'id': enrollment.id,
|
||||||
'sk': f'LINKED_ENTITIES#{entity.type}',
|
'sk': entity_sk,
|
||||||
|
'kind': 'PARENT',
|
||||||
'created_at': now_,
|
'created_at': now_,
|
||||||
f'{keyprefix}_id': entity.id,
|
f'{keyprefix}_id': perent_id,
|
||||||
}
|
},
|
||||||
|
cond_expr='attribute_not_exists(sk)',
|
||||||
|
)
|
||||||
|
|
||||||
|
# Parent knows the child
|
||||||
|
transact.put(
|
||||||
|
item={
|
||||||
|
'id': perent_id,
|
||||||
|
'sk': entity_sk,
|
||||||
|
'kind': 'CHILD',
|
||||||
|
'created_at': now_,
|
||||||
|
f'{keyprefix}_id': enrollment.id,
|
||||||
|
},
|
||||||
|
cond_expr='attribute_not_exists(sk)',
|
||||||
)
|
)
|
||||||
|
|
||||||
if org:
|
if org:
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ Resources:
|
|||||||
EventSendReminderEmailsFunction:
|
EventSendReminderEmailsFunction:
|
||||||
Type: AWS::Serverless::Function
|
Type: AWS::Serverless::Function
|
||||||
Properties:
|
Properties:
|
||||||
Handler: events.emails.send_reminder_emails.lambda_handler
|
Handler: events.send_reminder_emails.lambda_handler
|
||||||
LoggingConfig:
|
LoggingConfig:
|
||||||
LogGroup: !Ref EventLog
|
LogGroup: !Ref EventLog
|
||||||
Policies:
|
Policies:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import app.events.reenroll_if_failed as app
|
import app.events.reenroll_if_failed as app
|
||||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||||
from layercake.dynamodb import DynamoDBPersistenceLayer
|
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
|
||||||
|
|
||||||
|
|
||||||
def test_reenroll(
|
def test_reenroll(
|
||||||
@@ -27,3 +27,21 @@ def test_reenroll(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert app.lambda_handler(event, lambda_context) # type: ignore
|
assert app.lambda_handler(event, lambda_context) # type: ignore
|
||||||
|
|
||||||
|
parent_entity = dynamodb_persistence_layer.collection.get_item(
|
||||||
|
KeyPair(
|
||||||
|
pk='294e9864-8284-4287-b153-927b15d90900',
|
||||||
|
sk='LINKED_ENTITIES#ENROLLMENT',
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assert parent_entity['kind'] == 'CHILD'
|
||||||
|
|
||||||
|
child_entity = dynamodb_persistence_layer.collection.get_item(
|
||||||
|
KeyPair(
|
||||||
|
pk=parent_entity['enrollment_id'],
|
||||||
|
sk='LINKED_ENTITIES#ENROLLMENT',
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert child_entity['enrollment_id'] == parent_entity['id']
|
||||||
|
assert child_entity['kind'] == 'PARENT'
|
||||||
|
|||||||
Reference in New Issue
Block a user