add enrollments to order
This commit is contained in:
@@ -114,7 +114,7 @@ def enroll(
|
||||
with processor(immediate, enroll_now, ctx) as batch:
|
||||
now_out = batch.process()
|
||||
|
||||
with processor(later, enroll_later, ctx) as batch:
|
||||
with processor(later, _enroll_later, ctx) as batch:
|
||||
later_out = batch.process()
|
||||
|
||||
def fmt(r):
|
||||
@@ -317,7 +317,7 @@ def enroll_now(enrollment: Enrollment, context: Context):
|
||||
return enrollment
|
||||
|
||||
|
||||
def enroll_later(enrollment: Enrollment, context: Context):
|
||||
def _enroll_later(enrollment: Enrollment, context: Context):
|
||||
now_ = now()
|
||||
user = enrollment.user
|
||||
course = enrollment.course
|
||||
|
||||
@@ -14,7 +14,7 @@ from pydantic import UUID4
|
||||
|
||||
from api_gateway import JSONResponse
|
||||
from boto3clients import dynamodb_client
|
||||
from config import ORDER_TABLE
|
||||
from config import ENROLLMENT_TABLE, ORDER_TABLE
|
||||
from exceptions import ConflictError, OrderConflictError, OrderNotFoundError
|
||||
from middlewares.authentication_middleware import User as Authenticated
|
||||
|
||||
@@ -48,14 +48,24 @@ def get_order(order_id: str):
|
||||
if not order:
|
||||
raise OrderNotFoundError('Order not found')
|
||||
|
||||
org_id = order.get('org_id')
|
||||
attempts = dyn.collection.query(KeyPair(order_id, 'TRANSACTION#ATTEMPT#'))
|
||||
enrollments = dyn.collection.query(KeyPair(order_id, 'ENROLLMENT#'))
|
||||
seats = (
|
||||
dyn.collection.query(
|
||||
key=KeyPair(f'SEAT#ORG#{org_id}', f'ORDER#{order_id}'),
|
||||
table_name=ENROLLMENT_TABLE,
|
||||
)
|
||||
if org_id
|
||||
else {'items': []}
|
||||
)
|
||||
|
||||
return (
|
||||
order
|
||||
| {
|
||||
'payment_attempts': attempts['items'],
|
||||
'enrollments': enrollments['items'],
|
||||
'seats': seats['items'],
|
||||
}
|
||||
# Post-migration (orders): remove the following lines
|
||||
| ({'created_at': order['create_date']} if 'create_date' in order else {})
|
||||
|
||||
@@ -356,5 +356,7 @@ def _get_settings(id: str) -> Settings:
|
||||
|
||||
if 'due_days' not in r:
|
||||
r['due_days'] = DUE_DAYS
|
||||
else:
|
||||
r['due_days'] = int(r['due_days'])
|
||||
|
||||
return cast(Settings, r)
|
||||
|
||||
@@ -11,7 +11,7 @@ from pydantic import FutureDatetime
|
||||
from api_gateway import JSONResponse
|
||||
from boto3clients import dynamodb_client
|
||||
from config import ENROLLMENT_TABLE
|
||||
from middlewares.authentication_middleware import User as Authenticated
|
||||
from routes.orgs import billing
|
||||
|
||||
from ...enrollments.enroll import Context, Enrollment, Org, Subscription, enroll_now
|
||||
|
||||
@@ -74,24 +74,20 @@ def proceed(
|
||||
exc_cls=ScheduledNotFoundError,
|
||||
)
|
||||
billing_day = scheduled.get('subscription_billing_day')
|
||||
ctx = cast(
|
||||
Context,
|
||||
{
|
||||
'created_by': router.context['user'],
|
||||
'org': Org(id=org_id, name=scheduled['org_name']),
|
||||
**(
|
||||
{'subscription': Subscription(billing_day=billing_day)}
|
||||
if billing_day
|
||||
else {}
|
||||
),
|
||||
},
|
||||
)
|
||||
ctx: Context = {
|
||||
'created_by': router.context['user'],
|
||||
'org': Org(id=org_id, name=scheduled['org_name']),
|
||||
}
|
||||
|
||||
if billing_day:
|
||||
ctx['subscription'] = Subscription(billing_day=billing_day)
|
||||
|
||||
try:
|
||||
enrollment = enroll_now(
|
||||
Enrollment(
|
||||
user=scheduled['user'],
|
||||
course=scheduled['course'],
|
||||
seat=scheduled.get('seat'),
|
||||
),
|
||||
ctx,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user