async def delete_shop_for_executors( executors_id: str, shop_id:List[str], current_user= Security(deps.get_current_active_user,scopes=["shop_executor"]), db: Session = Depends(deps.get_db) ): if current_user.role=="manager": for id in shop_id: if crud_shop.check_shop_manager(db=db,shop_id=id,manager_id=current_user.id) is False: raise HTTPException( status_code=status.HTTP_502_BAD_GATEWAY, detail="Shop not belong to your channel" ) executor=crud_user.get_user(db=db,user_id=executors_id) if executor is None or executor.role!="executor" : raise HTTPException( status_code=status.HTTP_502_BAD_GATEWAY, detail="Invalid executor id" ) for id in shop_id: if crud_shop_executor.get_shop_executor(db=db,shop_id=id,executor_id=executors_id) is None: raise HTTPException( status_code=status.HTTP_502_BAD_GATEWAY, detail="Shop not found" ) for id in shop_id: crud_shop_executor.delete_shop_executor(db=db,shop_id=id,executor_id=executors_id) return {"message":"delete success"}
async def delete_shop_for_executors(executors_id: str, shop_id: List[str], token: Optional[str] = Header(None), db: Session = Depends(deps.get_db)): try: check_sercurity_scopes(token=token, scopes=settings.DELETE_EXECUTOR_SHOP_SCOPE) payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM]) if payload.get("role") == "manager": for id in shop_id: if crud_shop.check_shop_manager( db=db, shop_id=id, manager_id=payload.get("id")) is False: raise HTTPException( status_code=status.HTTP_502_BAD_GATEWAY, detail="Shop not belong to your channel") executor = crud_user.get_user(db=db, user_id=executors_id) if executor is None or executor.role != "executor": raise HTTPException(status_code=status.HTTP_502_BAD_GATEWAY, detail="Invalid executor id") for id in shop_id: if crud_shop_executor.get_shop_executor( db=db, shop_id=id, executor_id=executors_id) is None: raise HTTPException(status_code=status.HTTP_502_BAD_GATEWAY, detail="Shop not found") for id in shop_id: crud_shop_executor.delete_shop_executor(db=db, shop_id=id, executor_id=executors_id) except (JWTError, ValidationError): raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Unauthorized ", headers={"WWW-Authenticate": "Bearer"}, ) except (mysql.connector.Error): raise HTTPException( status_code=status.HTTP_502_BAD_GATEWAY, detail="My sql connection error ", headers={"WWW-Authenticate": "Bearer"}, ) return {"message": "delete success"}