Skip to content

Commit

Permalink
small changes to user creation
Browse files Browse the repository at this point in the history
  • Loading branch information
suryabulusu committed Nov 19, 2024
1 parent 1dba31d commit fcd421b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/router/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from router import (
group,
auth_group,
batch,
group_user,
user,
school,
Expand Down Expand Up @@ -99,6 +100,28 @@ async def create_school_user_record(data, school_name, district, auth_group_name
)


async def create_batch_user_record(data, batch_id):
batch_data = batch.get_batch(build_request(query_params={"name": batch_id}))
group_data = group.get_group(
build_request(query_params={"child_id": batch_data["id"], "type": "batch"})
)

await group_user.create_group_user(
build_request(
method="POST",
body={
"group_id": group_data[0]["id"],
"user_id": data["user"]["id"],
"academic_year": str(datetime.now().year)
+ "-"
+ str((datetime.now() + relativedelta(years=1)).year),
"start_date": datetime.now().strftime("%Y-%m-%d"),
"grade_id": data["grade_id"],
},
)
)


async def create_auth_group_user_record(data, auth_group_name):
auth_group_data = auth_group.get_auth_group(
build_request(query_params={"name": auth_group_name})
Expand Down Expand Up @@ -266,6 +289,7 @@ async def create_student(request: Request):
data["auth_group"] == "FeedingIndiaStudents"
or data["auth_group"] == "UttarakhandStudents"
or data["auth_group"] == "HimachalStudents"
or data["auth_group"] == "AllIndiaStudents"
):
# Use phone number as student ID
query_params["student_id"] = query_params["phone"]
Expand Down Expand Up @@ -325,6 +349,10 @@ async def create_student(request: Request):
new_student_data = create_new_student_record(query_params)
await create_auth_group_user_record(new_student_data, data["auth_group"])

if data["auth_group"] == "AllIndiaStudents":
batch_id = f"AllIndiaStudents_{query_params['grade']}_{datetime.now().year}_A001" # update 24
await create_batch_user_record(new_student_data, batch_id)

if "school_name" in query_params:
await create_school_user_record(
new_student_data,
Expand Down

0 comments on commit fcd421b

Please sign in to comment.