add billing period
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user