async def update_current( user_update: UserUpdate = Body(..., embed=True), user_current: UserTokenWrapper = Depends(get_current_user), conn: AsyncIOMotorClient = Depends(get_database), ) -> UserResponse: user_update.username = ( None if user_update.username == user_current.username else user_update.username ) user_update.email = ( None if user_update.email == user_current.email else user_update.email ) await check_availability_username_and_email( conn, user_update.email, user_update.username ) user_db: UserDB = await update_user(conn, user_current, user_update) return UserResponse(user=UserTokenWrapper(**user_db.dict()))
def update_user_me( *, password: str = Body(None), full_name: str = Body(None), email: EmailStr = Body(None), current_user: UserInDB = Depends(get_current_active_user), ): """ Update own user. """ user_in = UserUpdate(**current_user.dict()) if password is not None: user_in.password = password if full_name is not None: user_in.full_name = full_name if email is not None: user_in.email = email bucket = get_default_bucket() user = crud.user.update(bucket, username=current_user.username, user_in=user_in) return user
def update_user_me( *, db: Session = Depends(get_db), password: str = Body(None), full_name: str = Body(None), email: EmailStr = Body(None), current_user: DBUser = Depends(get_current_active_user), ): """ Update own user. """ current_user_data = jsonable_encoder(current_user) user_in = UserUpdate(**current_user_data) if password is not None: user_in.password = password if full_name is not None: user_in.full_name = full_name if email is not None: user_in.email = email user = crud.user.update(db, user=current_user, user_in=user_in) return user
async def update_user_me( *, password: str = Body(None), fullname: str = Body(None), email: EmailStr = Body(None), current_user: UserInDB = Depends(get_current_active_user), db: DBClient = client): """ Update own user """ # user_in = UserUpdate(**current_user.dict()) user_in = UserUpdate(**current_user) if password is not None: user_in.password = password if fullname is not None: user_in.fullname = fullname if user_in.email is not None: user_in.email = email user = await crud.update(db, current_user["_id"], user_in) if user: return utils.create_aliased_response(UserResponse(response=user)) return utils.create_404_response()