finish seat
This commit is contained in:
@@ -10,8 +10,15 @@ from layercake.dateutils import now
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import ENROLLMENT_TABLE
|
||||
from enrollment import Enrollment, Subscription, enroll
|
||||
from config import ENROLLMENT_TABLE, ORDER_TABLE
|
||||
from enrollment import (
|
||||
Enrollment,
|
||||
Kind,
|
||||
LinkedEntity,
|
||||
Seat,
|
||||
Subscription,
|
||||
enroll,
|
||||
)
|
||||
|
||||
logger = Logger(__name__)
|
||||
dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
@@ -30,7 +37,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
offset_days = old_image.get('dedup_window_offset_days')
|
||||
billing_day = old_image.get('subscription_billing_day')
|
||||
created_by = old_image.get('created_by')
|
||||
seat = old_image.get('seat')
|
||||
seat: Seat | None = old_image.get('seat')
|
||||
enrollment = Enrollment(
|
||||
course=old_image['course'],
|
||||
user=old_image['user'],
|
||||
@@ -45,6 +52,21 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
)
|
||||
|
||||
try:
|
||||
# The enrollment must know its source
|
||||
linked_entities = (
|
||||
frozenset(
|
||||
{
|
||||
LinkedEntity(
|
||||
id=seat['order_id'],
|
||||
kind=Kind.ORDER,
|
||||
table_name=ORDER_TABLE,
|
||||
),
|
||||
},
|
||||
)
|
||||
if seat
|
||||
else frozenset()
|
||||
)
|
||||
|
||||
enroll(
|
||||
enrollment,
|
||||
org={
|
||||
@@ -58,6 +80,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
scheduled_at=datetime.fromisoformat(old_image['scheduled_at']),
|
||||
# Transfer the deduplication window if it exists
|
||||
deduplication_window={'offset_days': offset_days} if offset_days else None,
|
||||
linked_entities=linked_entities,
|
||||
persistence_layer=dyn,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user