diff --git a/app/routers/users.py b/app/routers/users.py index 4940019..5a7444b 100644 --- a/app/routers/users.py +++ b/app/routers/users.py @@ -163,7 +163,7 @@ async def update_users_me(current_user: Annotated[users.User, Depends(users_toke return current_user @router.put("/users", tags=["users"], status_code=status.HTTP_201_CREATED) -async def update_users(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))], userSingle: users.UserIn | None = None, response: Response = Response): +async def update_users(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))], userSingle: users.UserIn | None = None): if userSingle is None: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, @@ -173,7 +173,6 @@ async def update_users(authorize: Annotated[bool, Depends(permissions_checker.Pe user = user_repository.find_one_by({"$or":[{"username": {'$eq': userSingle.username}}, {"email": {"$eq": userSingle.email}}]}) if user is not None: - response.status_code = status.HTTP_201_CREATED if user.username == userSingle.username: raise HTTPException( status_code=status.HTTP_204_NO_CONTENT, @@ -184,17 +183,16 @@ async def update_users(authorize: Annotated[bool, Depends(permissions_checker.Pe status_code=status.HTTP_204_NO_CONTENT, detail="email" ) - user.username = userSingle.username - user.password = users_token.get_password_hash(userSingle.password) + + user = users.User(username=userSingle.username, password=users_token.get_password_hash(userSingle.password), email=userSingle.email) user.roles = userSingle.roles - user.email = userSingle.email user.firstName = userSingle.firstName user.name = userSingle.name user.birth = userSingle.birth user.created_at = datetime.today() user_repository.save(user) content = {"message": "user is created"} - response = JSONResponse(content=content) + response = JSONResponse(content=content, status_code=status.HTTP_201_CREATED) return response