Add POST /cards/wipe-team

This commit is contained in:
Cal Corum 2023-03-30 10:55:48 -05:00
parent bd4af6e7fa
commit 7bd66b791b

27
main.py
View File

@ -2338,6 +2338,28 @@ async def v1_cards_post_delete(del_ids: str, token: str = Depends(oauth2_scheme)
logging.info(f'del_ids: {del_ids} / type: {type(del_ids)}')
# sheets.post_deletion(SHEETS_AUTH, del_ids.split(','))
@app.post('/api/v1/cards/wipe-team/{team_id}')
async def v1_cards_wipe_team(team_id: int, token: str = Depends(oauth2_scheme)):
if not valid_token(token):
logging.warning(f'Bad Token: {token}')
db.close()
raise HTTPException(
status_code=401,
detail='You are not authorized to wipe teams. This event has been logged.'
)
try:
this_team = Team.get_by_id(team_id)
except Exception as e:
logging.error(f'/cards/wipe-team/{team_id} - could not find team')
raise HTTPException(status_code=404, detail=f'Team {team_id} not found')
t_query = Card.update(team=None).where(Card.team == this_team).execute()
db.close()
return f'Wiped {t_query} cards'
# @app.get('/api/v1/cards/{card_id}/sell')
# async def v1_cards_sell(card_id, ts: int = None):
# try:
@ -2405,7 +2427,10 @@ async def v1_cards_patch(
if player_id is not None:
this_card.player_id = player_id
if team_id is not None:
this_card.team_id = team_id
if team_id == 0:
this_card.team_id = None
else:
this_card.team_id = team_id
if pack_id is not None:
this_card.pack_id = pack_id
if value is not None: