update table

This commit is contained in:
2025-12-13 00:14:24 -03:00
parent 72f049babd
commit a1c0e3dcd5
6 changed files with 191 additions and 95 deletions

View File

@@ -94,6 +94,7 @@ def enroll(
enrollment: Enrollment,
*,
org: Org | None = None,
cancel_policy: bool = False,
subscription: Subscription | None = None,
created_by: CreatedBy | None = None,
scheduled_at: datetime | None = None,
@@ -120,6 +121,15 @@ def enroll(
| ({'scheduled_at': scheduled_at} if scheduled_at else {})
)
if cancel_policy:
transact.put(
item={
'id': enrollment.id,
'sk': 'CANCEL_POLICY',
'created_at': now_,
}
)
# Relationships between this enrollment and its related entities
for entity in linked_entities:
# Parent knows the child
@@ -168,7 +178,8 @@ def enroll(
item={
'id': enrollment.id,
'sk': 'CREATED_BY',
'created_by': created_by,
'name': created_by['name'],
'user_id': created_by['id'],
'created_at': now_,
}
)

View File

@@ -12,7 +12,7 @@ from layercake.funcs import pick
from boto3clients import dynamodb_client
from config import ENROLLMENT_TABLE
from enrollment import Enrollment, enroll
from enrollment import Enrollment, Subscription, enroll
logger = Logger(__name__)
dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
@@ -33,6 +33,14 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
course=old_image['course'],
user=old_image['user'],
)
subscription: Subscription | None = (
{
'org_id': org_id,
'billing_day': int(billing_day),
}
if billing_day
else None
)
try:
enroll(
@@ -41,14 +49,8 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
'org_id': org_id,
'name': old_image['org_name'],
},
subscription=(
{
'org_id': org_id,
'billing_day': int(billing_day),
}
if billing_day
else None
),
subscription=subscription,
cancel_policy=bool(subscription),
created_by=created_by,
scheduled_at=datetime.fromisoformat(old_image['created_at']),
# Transfer the deduplication window if it exists