Skip to content

Commit

Permalink
Fix get seller admins
Browse files Browse the repository at this point in the history
  • Loading branch information
armanddidierjean committed Nov 17, 2024
1 parent a39ed00 commit 0efe07c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
12 changes: 7 additions & 5 deletions app/core/myeclpay/cruds_myeclpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,25 @@ async def get_admin_sellers(


async def get_seller(
seller_id: UUID,
seller_user_id: UUID,
db: AsyncSession,
) -> models_myeclpay.Seller | None:
result = await db.execute(
select(models_myeclpay.Seller).where(
models_myeclpay.Seller.id == seller_id,
models_myeclpay.Seller.user_id == seller_user_id,
),
)
return result.scalars().first()


async def delete_seller(
seller_id: UUID,
seller_user_id: UUID,
db: AsyncSession,
) -> models_myeclpay.Seller | None:
) -> None:
await db.execute(
delete(models_myeclpay.Seller).where(models_myeclpay.Seller.id == seller_id),
delete(models_myeclpay.Seller).where(
models_myeclpay.Seller.user_id == seller_user_id,
),
)


Expand Down
17 changes: 9 additions & 8 deletions app/core/myeclpay/endpoints_myeclpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ async def get_store_admin_seller(


@router.delete(
"/myeclpay/stores/{store_id}/admins/{seller_id}",
"/myeclpay/stores/{store_id}/admins/{seller_user_id}",
status_code=204,
)
async def delete_store_admin_seller(
store_id: UUID,
seller_id: UUID,
seller_user_id: UUID,
db: AsyncSession = Depends(get_db),
user: CoreUser = Depends(is_user_a_member_of(GroupType.payment)),
):
Expand All @@ -168,25 +168,25 @@ async def delete_store_admin_seller(
**The user must be a member of group Payment**
"""
await cruds_myeclpay.get_seller(
seller_id=seller_id,
seller = await cruds_myeclpay.get_seller(
seller_user_id=seller_user_id,
db=db,
)

if seller_id is None:
if seller is None:
raise HTTPException(
status_code=404,
detail="Seller does not exist",
)

if seller_id.store_id != store_id:
if seller.store_id != store_id:
raise HTTPException(
status_code=400,
detail="Seller does not belong to the store",
)

await cruds_myeclpay.delete_seller(
seller_id=seller_id,
seller_user_id=seller_user_id,
db=db,
)

Expand Down Expand Up @@ -549,7 +549,8 @@ async def revoke_user_devices(
)

wallet_device = await cruds_myeclpay.get_wallet_device(
wallet_device_id=wallet_device_id, db=db
wallet_device_id=wallet_device_id,
db=db,
)

if wallet_device is None:
Expand Down

0 comments on commit 0efe07c

Please sign in to comment.