def update_user( data: UserUpdate, user: UserModel = Depends(deps.get_user), db: Session = Depends(deps.get_db), rdc: RedisCache = Depends(deps.get_redis) ) -> Any: """ Endpoint for update current user """ db_user = crud_user.get_user_by_email(db, data.email) if db_user and db_user.id != user.id: raise HTTPException(status_code=400, detail='Endereço de email já registrador!') data.avatar = user.avatar data.is_active = user.is_active if not data.address and user.address: data.address = user.address user = crud_user.update(db, user, data) rdc.invalidate_cache_provider(user) if user.address: #<-- if have an address, is a provider rdc.invalidate_cache_user(user) rdc.invalidate_cache_prefix("providers-list") return user
def activate_random_user(db: Session, user: User) -> User: user_in = UserUpdate( name=user.name, surname=user.surname, email=user.email, is_active=True, ) if user.address: user_in.address = user.address return crud_user.update(db, user, user_in)