habulaj commited on
Commit
e9b4f67
·
verified ·
1 Parent(s): 0305b83

Update routes/support.py

Browse files
Files changed (1) hide show
  1. routes/support.py +32 -0
routes/support.py CHANGED
@@ -360,6 +360,38 @@ async def create_ticket(
360
  raise HTTPException(status_code=500, detail=f"Erro ao criar mensagem: {error_detail}")
361
 
362
  return {"ticket_id": ticket_id}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
 
364
  # 📧 Envio de e-mails com Gmail API
365
  GMAIL_CLIENT_ID = "784687789817-3genmmvps11ip3a6fkbkkd8dm3bstgdc.apps.googleusercontent.com"
 
360
  raise HTTPException(status_code=500, detail=f"Erro ao criar mensagem: {error_detail}")
361
 
362
  return {"ticket_id": ticket_id}
363
+
364
+ class CloseTicketRequest(BaseModel):
365
+ ticket_id: int
366
+
367
+ @router.post("/ticket/close")
368
+ async def close_ticket(
369
+ body: CloseTicketRequest,
370
+ user_token: str = Header(None, alias="User-key")
371
+ ):
372
+ user_id = await verify_user_token(user_token)
373
+ finished_date = datetime.utcnow().isoformat()
374
+
375
+ update_payload = {
376
+ "finished": True,
377
+ "finished_date": finished_date
378
+ }
379
+
380
+ async with aiohttp.ClientSession() as session:
381
+ async with session.patch(
382
+ f"{SUPABASE_URL}/rest/v1/Tickets?id=eq.{body.ticket_id}",
383
+ headers={
384
+ **SUPABASE_ROLE_HEADERS,
385
+ "Content-Type": "application/json"
386
+ },
387
+ json=update_payload
388
+ ) as update_resp:
389
+
390
+ if update_resp.status != 204:
391
+ error_detail = await update_resp.text()
392
+ raise HTTPException(status_code=500, detail=f"Error closing ticket: {error_detail}")
393
+
394
+ return {"message": "Ticket closed successfully", "ticket_id": body.ticket_id}
395
 
396
  # 📧 Envio de e-mails com Gmail API
397
  GMAIL_CLIENT_ID = "784687789817-3genmmvps11ip3a6fkbkkd8dm3bstgdc.apps.googleusercontent.com"