Dindn't solve all conflicts in previous commit
This commit is contained in:
@@ -96,7 +96,9 @@ class TrainingService(ITrainingService):
|
||||
for area in training_content.weak_areas:
|
||||
weak_areas["weak_areas"].append(area.dict())
|
||||
|
||||
new_id = str(uuid.uuid4())
|
||||
training_doc = {
|
||||
'id': new_id,
|
||||
'created_at': int(datetime.now().timestamp() * 1000),
|
||||
**exam_map,
|
||||
**usefull_tips.dict(),
|
||||
@@ -105,6 +107,7 @@ class TrainingService(ITrainingService):
|
||||
}
|
||||
doc_id = await self._db.save_to_db('training', training_doc)
|
||||
return {
|
||||
"id": new_id
|
||||
"id": doc_id
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,11 @@ import shortuuid
|
||||
|
||||
from datetime import datetime
|
||||
from logging import getLogger
|
||||
|
||||
import pandas as pd
|
||||
from typing import Dict
|
||||
|
||||
import shortuuid
|
||||
from pymongo.database import Database
|
||||
|
||||
from app.dtos.user_batch import BatchUsersDTO, UserDTO
|
||||
@@ -49,6 +54,15 @@ class UserService(IUserService):
|
||||
FileHelper.remove_file(path)
|
||||
return {"ok": True}
|
||||
|
||||
@staticmethod
|
||||
def _map_to_batch(request_data: Dict) -> BatchUsersDTO:
|
||||
users_list = [{**user} for user in request_data["users"]]
|
||||
for user in users_list:
|
||||
user["studentID"] = str(user["studentID"])
|
||||
|
||||
users: list[UserDTO] = [UserDTO(**user) for user in users_list]
|
||||
return BatchUsersDTO(makerID=request_data["makerID"], users=users)
|
||||
|
||||
@staticmethod
|
||||
def _generate_firebase_auth_csv(batch_dto: BatchUsersDTO, path: str):
|
||||
# https://firebase.google.com/docs/cli/auth#file_format
|
||||
@@ -119,12 +133,6 @@ class UserService(IUserService):
|
||||
self._insert_new_user(user)
|
||||
code = self._create_code(user, maker_id)
|
||||
|
||||
if user.type == "corporate":
|
||||
self._set_corporate_default_groups(user)
|
||||
|
||||
if user.corporate:
|
||||
self._assign_corporate_to_user(user, code)
|
||||
|
||||
if user.groupName and len(user.groupName.strip()) > 0:
|
||||
self._assign_user_to_group_by_name(user, maker_id)
|
||||
|
||||
@@ -144,7 +152,8 @@ class UserService(IUserService):
|
||||
'isFirstLogin': False,
|
||||
'isVerified': True,
|
||||
'registrationDate': datetime.now(),
|
||||
'subscriptionExpirationDate': user.expiryDate
|
||||
'subscriptionExpirationDate': user.expiryDate,
|
||||
'entities': user.entities
|
||||
}
|
||||
self._db.users.insert_one(new_user)
|
||||
|
||||
@@ -164,74 +173,6 @@ class UserService(IUserService):
|
||||
})
|
||||
return code
|
||||
|
||||
def _set_corporate_default_groups(self, user: UserDTO):
|
||||
user_id = str(user.id)
|
||||
default_groups = [
|
||||
{
|
||||
'admin': user_id,
|
||||
'id': str(uuid.uuid4()),
|
||||
'name': "Teachers",
|
||||
'participants': [],
|
||||
'disableEditing': True,
|
||||
},
|
||||
{
|
||||
'admin': user_id,
|
||||
'id': str(uuid.uuid4()),
|
||||
'name': "Students",
|
||||
'participants': [],
|
||||
'disableEditing': True,
|
||||
},
|
||||
{
|
||||
'admin': user_id,
|
||||
'id': str(uuid.uuid4()),
|
||||
'name': "Corporate",
|
||||
'participants': [],
|
||||
'disableEditing': True,
|
||||
}
|
||||
]
|
||||
for group in default_groups:
|
||||
self._db.groups.insert_one(group)
|
||||
|
||||
def _assign_corporate_to_user(self, user: UserDTO, code: str):
|
||||
user_id = str(user.id)
|
||||
corporate_user = self._db.users.find_one(
|
||||
{"email": user.corporate}
|
||||
)
|
||||
if corporate_user:
|
||||
self._db.codes.update_one(
|
||||
{"id": code},
|
||||
{"$set": {"creator": corporate_user["id"]}},
|
||||
upsert=True
|
||||
)
|
||||
group_type = "Students" if user.type == "student" else "Teachers"
|
||||
|
||||
group = self._db.groups.find_one(
|
||||
{
|
||||
"admin": corporate_user["id"],
|
||||
"name": group_type
|
||||
}
|
||||
)
|
||||
|
||||
if group:
|
||||
participants = group['participants']
|
||||
if user_id not in participants:
|
||||
participants.append(user_id)
|
||||
self._db.groups.update_one(
|
||||
{"id": group["id"]},
|
||||
{"$set": {"participants": participants}}
|
||||
)
|
||||
|
||||
else:
|
||||
group = {
|
||||
'admin': corporate_user["id"],
|
||||
'id': str(uuid.uuid4()),
|
||||
'name': group_type,
|
||||
'participants': [user_id],
|
||||
'disableEditing': True,
|
||||
}
|
||||
|
||||
self._db.groups.insert_one(group)
|
||||
|
||||
def _assign_user_to_group_by_name(self, user: UserDTO, maker_id: str):
|
||||
user_id = str(user.id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user