fix duplicate user

This commit is contained in:
2026-01-28 10:43:46 -03:00
parent 428006cfac
commit fc14d425f2
14 changed files with 151 additions and 141 deletions

View File

@@ -220,15 +220,25 @@ def enroll_now(enrollment: Enrollment, context: Context):
exc_cls=OrderNotFoundError,
table_name=ORDER_TABLE,
)
transact.put(
item={
'id': seat.order_id,
'sk': f'ENROLLMENT#{enrollment.id}',
'course': course.model_dump(),
'user': user.model_dump(),
'status': 'EXECUTED',
'executed_at': now_,
'created_at': now_,
transact.update(
key=KeyPair(
pk=str(seat.order_id),
sk=f'ENROLLMENT#{enrollment.id}',
),
update_expr='SET course = :course, \
#user = :user, \
#status = :executed, \
executed_at = :now, \
created_at = if_not_exists(created_at, :now)',
expr_attr_names={
'#user': 'user',
'#status': 'status',
},
expr_attr_values={
':course': course.model_dump(),
':user': user.model_dump(),
':executed': 'EXECUTED',
':now': now_,
},
table_name=ORDER_TABLE,
)
@@ -240,6 +250,15 @@ def enroll_now(enrollment: Enrollment, context: Context):
cond_expr='attribute_exists(sk)',
exc_cls=SeatNotFoundError,
)
# Enrollment should know where it comes from
transact.put(
item={
'id': enrollment.id,
'sk': f'LINKED_ENTITY#PARENT#ORDER#{seat.order_id}',
'created_at': now_,
},
cond_expr='attribute_not_exists(sk)',
)
transact.put(
item={