add access_expires_at to enrollment
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
import sqlite3
|
||||
from datetime import timedelta
|
||||
|
||||
from aws_lambda_powertools import Logger
|
||||
from aws_lambda_powertools.utilities.data_classes import (
|
||||
@@ -34,8 +35,17 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
|
||||
try:
|
||||
course = _get_course(new_image['course']['id'])
|
||||
access_period = int(course['access_period'])
|
||||
access_expires_at = now_ + timedelta(days=access_period)
|
||||
|
||||
with enrollment_layer.transact_writer() as transact:
|
||||
transact.update(
|
||||
key=KeyPair(new_image['id'], new_image['sk']),
|
||||
update_expr='SET access_expires_at = :access_expires_at',
|
||||
expr_attr_values={
|
||||
':access_expires_at': access_expires_at,
|
||||
},
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': new_image['id'],
|
||||
@@ -49,7 +59,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
'id': new_image['id'],
|
||||
'sk': 'METADATA#COURSE',
|
||||
'created_at': now_,
|
||||
'access_period': int(course['access_period']),
|
||||
'access_period': access_period,
|
||||
'cert': course.get('cert', None),
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user