renamem orders
This commit is contained in:
@@ -7,8 +7,21 @@ from layercake.strutils import md5_hash
|
||||
|
||||
from schemas import Enrollment
|
||||
|
||||
Org = TypedDict('Org', {'org_id': str, 'name': str})
|
||||
DeduplicationWindow = TypedDict('DeduplicationWindow', {'offset_days': int})
|
||||
Org = TypedDict(
|
||||
'Org',
|
||||
{
|
||||
'org_id': str,
|
||||
'name': str,
|
||||
},
|
||||
)
|
||||
|
||||
DeduplicationWindow = TypedDict(
|
||||
'DeduplicationWindow',
|
||||
{
|
||||
'offset_days': int,
|
||||
},
|
||||
)
|
||||
|
||||
Subscription = TypedDict(
|
||||
'Subscription',
|
||||
{
|
||||
@@ -44,7 +57,6 @@ def enroll(
|
||||
deduplication_window: DeduplicationWindow | None = None,
|
||||
persistence_layer: DynamoDBPersistenceLayer,
|
||||
) -> bool:
|
||||
"""Enrolls a user into a course and schedules lifecycle events."""
|
||||
now_ = now()
|
||||
user = enrollment.user
|
||||
course = enrollment.course
|
||||
@@ -60,9 +72,7 @@ def enroll(
|
||||
**enrollment.model_dump(),
|
||||
}
|
||||
| ({'subscription_covered': True} if subscription else {})
|
||||
| ({'tenant_id': org['org_id']} if org else {}),
|
||||
# Post-migration: uncomment the following line
|
||||
# | ({'org_id': org['org_id']} if org else {}),
|
||||
| ({'org_id': org['org_id']} if org else {}),
|
||||
)
|
||||
|
||||
# Relationships between this enrollment and its related entities
|
||||
@@ -97,9 +107,7 @@ def enroll(
|
||||
transact.put(
|
||||
item={
|
||||
'id': enrollment.id,
|
||||
# Post-migration: uncomment the following line
|
||||
# 'sk': 'ORG',
|
||||
'sk': 'tenant',
|
||||
'sk': 'ORG',
|
||||
'created_at': now_,
|
||||
}
|
||||
| org
|
||||
|
||||
@@ -34,7 +34,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
order = order_layer.collection.get_items(
|
||||
TransactKey(order_id) + SortKey('0') + SortKey('items', path_spec='items'),
|
||||
)
|
||||
# Post-migration: rename `tenant_id` to `org_id`
|
||||
# Post-migration (orders): rename `tenant_id` to `org_id`
|
||||
org_id = order['tenant_id']
|
||||
items = {
|
||||
item['id']: int(item['quantity'])
|
||||
@@ -54,7 +54,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
item={
|
||||
'id': f'vacancies#{org_id}',
|
||||
'sk': f'{order_id}#{uuid4()}',
|
||||
# Post-migration: uncomment the follow lines
|
||||
# Post-migration (orders): uncomment the follow lines
|
||||
# 'id': f'SLOT#ORG#{org_id}',
|
||||
# 'sk': f'ORDER#{order_id}#ENROLLMENT#{uuid4()}',
|
||||
'course': asdict(slot),
|
||||
@@ -81,8 +81,6 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
class Course:
|
||||
id: str
|
||||
name: str
|
||||
# Post-migration: remove the following line
|
||||
time_in_days: int
|
||||
|
||||
|
||||
def _get_courses(ids: set) -> tuple[Course, ...]:
|
||||
@@ -95,8 +93,6 @@ def _get_courses(ids: set) -> tuple[Course, ...]:
|
||||
Course(
|
||||
id=idx,
|
||||
name=obj['name'],
|
||||
# Post-migration: remove the following line
|
||||
time_in_days=int(obj['access_period']),
|
||||
)
|
||||
for idx, obj in result.items()
|
||||
)
|
||||
|
||||
@@ -81,6 +81,8 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
emailmsg = Message(
|
||||
from_=EMAIL_SENDER,
|
||||
to=_get_admin_emails(org_id),
|
||||
reply_to=REPLY_TO,
|
||||
bcc=BCC,
|
||||
subject=SUBJECT.format(month=month),
|
||||
)
|
||||
emailmsg.add_alternative(MESSAGE.format(month=month))
|
||||
|
||||
@@ -29,11 +29,10 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
path_spec='offset_days',
|
||||
rename_key='dedup_window_offset_days',
|
||||
)
|
||||
+ SortKey('konviva')
|
||||
+ SortKey('tenant', rename_key='org'),
|
||||
+ SortKey('ORG', rename_key='org')
|
||||
+ SortKey('konviva'),
|
||||
# Post-migration: uncomment the following lines
|
||||
# + SortKey('KONVIVA', rename_key='konviva')
|
||||
# + SortKey('ORG', rename_key='org'),
|
||||
flatten_top=False,
|
||||
)
|
||||
user = User.model_validate(new_image['user'])
|
||||
|
||||
@@ -45,6 +45,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
':completed': 'COMPLETED',
|
||||
':now': now_,
|
||||
},
|
||||
exc_cls=StatusConflictError,
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
@@ -68,3 +69,6 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
class StatusConflictError(Exception): ...
|
||||
|
||||
@@ -24,7 +24,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
new_image = event.detail['new_image']
|
||||
now_ = now()
|
||||
terms = user_layer.get_item(
|
||||
# Post-migration: uncomment the following line
|
||||
# Post-migration (users): uncomment the following line
|
||||
# KeyPair(new_image['org_id'], 'METADATA#BILLING_TERMS'),
|
||||
KeyPair(new_image['tenant_id'], 'metadata#billing_policy'),
|
||||
)
|
||||
@@ -48,7 +48,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
item={
|
||||
'id': new_image['id'],
|
||||
'sk': 'METADATA#SUBSCRIPTION_COVERED',
|
||||
'org_id': new_image['tenant_id'],
|
||||
'org_id': new_image['org_id'],
|
||||
'billing_day': terms['billing_day'],
|
||||
'created_at': now_,
|
||||
},
|
||||
|
||||
@@ -72,8 +72,7 @@ Resources:
|
||||
detail:
|
||||
new_image:
|
||||
sk: ["0"]
|
||||
# Post-migration: rename `tenant_id` to `org_id`
|
||||
tenant_id:
|
||||
org_id:
|
||||
- exists: true
|
||||
|
||||
EventPatchCourseMetadataFunction:
|
||||
|
||||
@@ -26,7 +26,6 @@ def test_append_cert(
|
||||
'name': 'How to Sing Better',
|
||||
},
|
||||
'cert': {
|
||||
# 'expires_at': '2026-02-10T20:14:42.880991',
|
||||
'expires_at': expires_at.isoformat(),
|
||||
},
|
||||
'user': {
|
||||
|
||||
Reference in New Issue
Block a user