get user id from order

This commit is contained in:
2025-07-23 01:14:56 -03:00
parent edecbce356
commit 45a6038066
8 changed files with 22 additions and 16 deletions

View File

@@ -40,19 +40,19 @@ class LifecycleEvents(str, Enum):
"""Lifecycle events related to scheduling actions."""
# Reminder if the user does not access within 3 days
# REMINDER_NO_ACCESS_3_DAYS = 'schedules#reminder_no_access_3_days'
# REMINDER_NO_ACCESS_3_DAYS = 'SCHEDULES#REMINDER_NO_ACCESS_3_DAYS'
DOES_NOT_ACCESS = 'schedules#does_not_access'
# When there is no activity 7 days after the first access
# NO_ACTIVITY_7_DAYS = 'schedules#no_activity_7_days'
# NO_ACTIVITY_7_DAYS = 'SCHEDULES#NO_ACTIVITY_7_DAYS'
NO_ACTIVITY = 'schedules#no_activity'
# Reminder 30 days before the access period expires
# ACCESS_PERIOD_REMINDER_30_DAYS = 'schedules#access_period_reminder_30_days'
# ACCESS_PERIOD_REMINDER_30_DAYS = 'SCHEDULES#ACCESS_PERIOD_REMINDER_30_DAYS'
ACCESS_PERIOD_ENDS = 'schedules#access_period_ends'
# Reminder for certificate expiration set to 30 days from now
CERT_EXPIRATION_REMINDER_30_DAYS = 'schedules#cert_expiration_reminder_30_days'
CERT_EXP_REMINDER_30_DAYS = 'SCHEDULES#CERT_EXP_REMINDER_30_DAYS'
# Archive the course after the certificate expires
# SET_AS_ARCHIVE = 'schedules#set_as_archive'

View File

@@ -54,8 +54,8 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
'id': f'vacancies#{tenant_id}',
'sk': f'{order_id}#{uuid4()}',
# Post-migration: uncomment the follow lines
# 'id': f'slots#org#{tenant_id}',
# 'sk': f'order#{order_id}#enrollment#{uuid4()}',
# 'id': f'SLOT#ORG#{tenant_id}',
# 'sk': f'ORDER#{order_id}#ENROLLMENT#{uuid4()}',
'course': asdict(slot),
'created_at': now_,
},
@@ -80,6 +80,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
class Course:
id: str
name: str
# Post-migration: remove the following line
time_in_days: int
@@ -93,6 +94,7 @@ 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()

View File

@@ -6,7 +6,6 @@ from aws_lambda_powertools.utilities.data_classes import (
event_source,
)
from aws_lambda_powertools.utilities.typing import LambdaContext
from glom import glom
from layercake.dateutils import now
from layercake.dynamodb import (
DynamoDBPersistenceLayer,
@@ -44,12 +43,9 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> list[str]
if item['unit_price'] > 0
}
result = order_layer.collection.query(KeyPair(order_id, 'assignees#'))
user_id = glom(result, 'items.0.sk').removeprefix('assignees#')
courses = _get_courses(set(items.keys()))
user = User(
id=user_id,
id=order['user_id'],
name=order['name'],
email=order['email'],
cpf=order['cpf'],

View File

@@ -1,10 +1,11 @@
import os
from dataclasses import dataclass
from uuid import uuid4
import jsonlines
import pytest
PYTEST_TABLE_NAME = 'pytest'
PYTEST_TABLE_NAME = f'pytest-{uuid4()}'
PK = 'id'
SK = 'sk'

View File

@@ -1,4 +1,4 @@
import app.events.stopgap.enroll as app
import app.events.stopgap.patch_enroll as app
from aws_lambda_powertools.utilities.typing import LambdaContext
from layercake.dynamodb import (
DynamoDBPersistenceLayer,

View File

@@ -8,7 +8,6 @@
{"id": {"S": "6a403773-aeac-4e6a-ac39-dc958e4be52a"},"sk": {"S": "0"},"access_period": {"N": "360"},"cert": {"M": {"exp_interval": {"N": "360"}}},"created_at": {"S": "2025-07-14T15:09:18.559528-03:00"},"metadata__konviva_class_id": {"N": "281"},"name": {"S": "Reciclagem em NR-11 - Operador de Empilhadeira"},"tenant_id": {"S": "*"}}
{"id": {"S": "123"},"sk": {"S": "0"},"access_period": {"N": "360"},"cert": {"M": {"exp_interval": {"N": "360"}}},"created_at": {"S": "2025-07-14T15:09:18.559528-03:00"},"metadata__konviva_class_id": {"N": "281"},"name": {"S": "pytest"},"tenant_id": {"S": "*"}}
{"id": {"S": "5OxmMjL-ujoR5IMGegQz"},"sk": {"S": "konviva"},"created_at": {"S": "2025-07-11T13:52:35.521154-03:00"},"konvivaId": {"N": "26943"}}
{"id": {"S": "cpYSbBcie2NDbZhDKCxCih"}, "sk": {"S": "0"},"cpf": {"S": "02713421535"},"create_date": {"S": "2025-07-21T16:19:43.297712-03:00"},"due_date": {"S": "2025-07-22T16:13:41.056000-03:00"},"email": {"S": "sergio@somosbeta.com.br"},"name": {"S": "Sérgio Rafael Siqueira"},"payment_date": {"S": "2025-07-21T16:21:47.161889-03:00"},"payment_method": {"S": "PIX"},"phone_number": {"S": "+5574998189595"},"status": {"S": "PAID"},"total": {"N": "99"},"update_date": {"S": "2025-07-21T16:21:47.161889-03:00"}}
{"id": {"S": "cpYSbBcie2NDbZhDKCxCih"}, "sk": {"S": "assignees#5OxmMjL-ujoR5IMGegQz"},"create_date": {"S": "2025-07-21T16:20:43.631344-03:00"},"scope": {"S": "USER"}}
{"id": {"S": "cpYSbBcie2NDbZhDKCxCih"}, "sk": {"S": "0"},"cpf": {"S": "02713421535"},"create_date": {"S": "2025-07-21T16:19:43.297712-03:00"},"due_date": {"S": "2025-07-22T16:13:41.056000-03:00"},"email": {"S": "sergio@somosbeta.com.br"},"name": {"S": "Sérgio Rafael Siqueira"},"payment_date": {"S": "2025-07-21T16:21:47.161889-03:00"},"payment_method": {"S": "PIX"},"phone_number": {"S": "+5574998189595"},"status": {"S": "PAID"},"total": {"N": "99"},"update_date": {"S": "2025-07-21T16:21:47.161889-03:00"}, "user_id": {"S": "5OxmMjL-ujoR5IMGegQz"}}
{"id": {"S": "cpYSbBcie2NDbZhDKCxCih"}, "sk": {"S": "items"},"items": {"L": [{"M": {"id": {"S": "6a403773-aeac-4e6a-ac39-dc958e4be52a"},"name": {"S": "Reciclagem em NR-11 - Operador de Empilhadeira"},"quantity": {"N": "1"},"unit_price": {"N": "99"}}}]}}
{"id": {"S": "cpYSbBcie2NDbZhDKCxCih"}, "sk": {"S": "generated_items"},"create_date": {"S": "2025-07-21T16:21:50.143551-03:00"},"scope": {"S": "SINGLE_USER"},"status": {"S": "SUCCESS"},"update_date": {"S": "2025-07-21T16:21:53.994941-03:00"}}

View File

@@ -36,7 +36,15 @@ def update_policies(
}
| billing_policy
)
transact.put(
item={
'id': 'SUBSCRIPTION',
'sk': f'ORG#{id}',
'created_at': now_,
}
)
else:
transact.delete(key=KeyPair(id, billing_sk))
transact.delete(key=KeyPair('SUBSCRIPTION', f'ORG#{id}'))
return True

View File

@@ -1,4 +1,4 @@
{"id": {"S": "439e9a43-ab92-469a-a849-b6e824370f80"}, "access_period": {"S": "360"}, "name": {"S": "No\u00e7\u00f5es em Primeiros Socorros"}, "sk": {"S": "0"}, "create_date": {"S": "2024-12-30T00:06:33.088916-03:00"}, "metadata__betaeducacao_id": {"S": "2c1e724a-58c6-4c20-90df-18b5660d6304"}, "metadata__tenant_id": {"S": "*"}, "metadata__konviva_id": {"S": "94"}}
{"id": {"S": "439e9a43-ab92-469a-a849-b6e824370f80"}, "access_period": {"S": "360"}, "name": {"S": "No\u00e7\u00f5es em Primeiros Socorros"}, "sk": {"S": "0"}, "create_date": {"S": "2024-12-30T00:06:33.088916-03:00"}, "metadata__betaeducacao_id": {"S": "2c1e724a-58c6-4c20-90df-18b5660d6304"}, "metadata__unit_price": {"N": "199"}, "metadata__tenant_id": {"S": "*"}, "metadata__konviva_id": {"S": "94"}}
{"id": {"S": "15ee05a3-4ceb-4b7e-9979-db75b28c9ade"}, "access_period": {"S": "360"}, "name": {"S": "Reciclagem de NR-10 SEP 08 horas"}, "sk": {"S": "0"}, "create_date": {"S": "2024-12-30T00:02:33.088916-03:00"}, "metadata__betaeducacao_id": {"S": "1d86444e-36d6-4ed7-8cea-24a4df9ca15f"}, "metadata__tenant_id": {"S": "*"}, "metadata__konviva_id": {"S": "276"}}
{"id": {"S": "4ea2498a-a6a9-4293-94d0-ceeb248e64b7"}, "access_period": {"S": "720"}, "name": {"S": "NR-10 B\u00e1sico"}, "sk": {"S": "0"}, "create_date": {"S": "2024-12-30T00:07:33.088916-03:00"}, "metadata__betaeducacao_id": {"S": "38"}, "metadata__tenant_id": {"S": "*"}, "metadata__konviva_id": {"S": "21"}}
{"id": {"S": "e1c44881-2fe3-484e-ada2-12b6bf5b9398"}, "access_period": {"S": "720"}, "name": {"S": "NR-35 Seguran\u00e7a nos Trabalhos em Altura (Te\u00f3rico)"}, "sk": {"S": "0"}, "create_date": {"S": "2024-12-30T00:11:33.088916-03:00"}, "metadata__betaeducacao_id": {"S": "42"}, "metadata__tenant_id": {"S": "*"}, "metadata__konviva_id": {"S": "1"}}