add billing period

This commit is contained in:
2025-08-21 13:32:44 -03:00
parent 6c301d320b
commit c70a74b94a
14 changed files with 282 additions and 98 deletions

View File

@@ -112,31 +112,46 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
),
flatten_top=False,
)
order_layer.put_item(
item={
'id': pk,
'sk': f'{sk}#ENROLLMENT#{enrollment["id"]}',
'user': pick(('id', 'name'), enrollment['user']),
'course': pick(('id', 'name'), enrollment['course']),
'unit_price': course['unit_price'],
# Post-migration: uncomment the following line
# 'enrolled_at': enrollment['created_at'],
'enrolled_at': enrollment['create_date'],
'created_at': now_,
}
# Add author if present
| (
{
'author': {
'id': author['user_id'],
'name': author['name'],
}
with order_layer.transact_writer() as transact:
transact.put(
item={
'id': pk,
'sk': f'{sk}#ENROLLMENT#{enrollment["id"]}',
'user': pick(('id', 'name'), enrollment['user']),
'course': pick(('id', 'name'), enrollment['course']),
'unit_price': course['unit_price'],
# Post-migration: uncomment the following line
# 'enrolled_at': enrollment['created_at'],
'enrolled_at': enrollment['create_date'],
'created_at': now_,
}
if author
else {}
),
cond_expr='attribute_not_exists(sk)',
)
# Add author if present
| (
{
'author': {
'id': author['user_id'],
'name': author['name'],
}
}
if author
else {}
),
cond_expr='attribute_not_exists(sk)',
)
transact.update(
key=KeyPair(
pk=new_image['id'],
sk=new_image['sk'],
),
table_name=ENROLLMENT_TABLE,
update_expr='SET billing_period = :billing_period, \
updated_at = :updated_at',
expr_attr_values={
':billing_period': sk,
':updated_at': now_,
},
cond_expr='attribute_exists(sk)',
)
except Exception as exc:
logger.exception(
exc,

View File

@@ -38,7 +38,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
new_image = event.detail['new_image']
# Key pattern `BILLING#ORG#{org_id}`
*_, org_id = new_image['id'].split('#')
# Key pattern `START#{start_date}#END#{end_date}#SCHEDULE#AUTO_CLOSE`
# Key pattern `START#{start_date}#END#{end_date}
_, start_date, _, end_date, *_ = new_image['sk'].split('#')
emailmsg = Message(

View File

@@ -23,13 +23,15 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
new_image = event.detail['new_image']
order_id = new_image['id']
org_id = new_image['tenant_id']
# Post-migration: Uncomment the following line
# org_id = new_image['org_id']
result = enrollment_layer.collection.query(
KeyPair(
# Post-migration: Uncomment the following line
# f'SLOT#ORG#{org_id}',
f'vacancies#{org_id}',
order_id,
pk=f'vacancies#{org_id}',
sk=order_id,
),
limit=100,
)