habulaj commited on
Commit
1d4c987
·
verified ·
1 Parent(s): 5be5d76

Update routes/approvals.py

Browse files
Files changed (1) hide show
  1. routes/approvals.py +14 -6
routes/approvals.py CHANGED
@@ -5,11 +5,20 @@ import asyncio
5
  from fastapi import APIRouter, HTTPException, Header
6
  from typing import Dict, Any
7
  from functools import lru_cache
 
8
  import requests
9
  from collections import defaultdict
10
 
11
  router = APIRouter()
12
 
 
 
 
 
 
 
 
 
13
  # Configuração do Supabase
14
  SUPABASE_URL = "https://ussxqnifefkgkaumjann.supabase.co"
15
  SUPABASE_KEY = os.getenv("SUPA_KEY")
@@ -142,7 +151,7 @@ async def get_users_pending_approval() -> Dict[str, Any]:
142
 
143
  @router.post("/admin/approve-account")
144
  async def approve_account(
145
- user_id: str,
146
  user_token: str = Header(None, alias="User-key")
147
  ):
148
  """
@@ -151,7 +160,7 @@ async def approve_account(
151
  try:
152
  await verify_admin_token(user_token)
153
 
154
- update_url = f"{SUPABASE_URL}/rest/v1/User?id=eq.{user_id}"
155
  payload = {
156
  "approved_account": True
157
  }
@@ -172,8 +181,7 @@ async def approve_account(
172
 
173
  @router.post("/admin/reject-account")
174
  async def reject_account(
175
- user_id: str,
176
- reason: str = None,
177
  user_token: str = Header(None, alias="User-key")
178
  ):
179
  """
@@ -182,10 +190,10 @@ async def reject_account(
182
  try:
183
  await verify_admin_token(user_token)
184
 
185
- update_url = f"{SUPABASE_URL}/rest/v1/User?id=eq.{user_id}"
186
  payload = {
187
  "approved_account": False,
188
- "approval_reason": reason or "No reason specified"
189
  }
190
 
191
  async with aiohttp.ClientSession() as session:
 
5
  from fastapi import APIRouter, HTTPException, Header
6
  from typing import Dict, Any
7
  from functools import lru_cache
8
+ from pydantic import BaseModel
9
  import requests
10
  from collections import defaultdict
11
 
12
  router = APIRouter()
13
 
14
+
15
+ class ApproveAccountRequest(BaseModel):
16
+ user_id: str
17
+
18
+ class RejectAccountRequest(BaseModel):
19
+ user_id: str
20
+ reason: str | None = None
21
+
22
  # Configuração do Supabase
23
  SUPABASE_URL = "https://ussxqnifefkgkaumjann.supabase.co"
24
  SUPABASE_KEY = os.getenv("SUPA_KEY")
 
151
 
152
  @router.post("/admin/approve-account")
153
  async def approve_account(
154
+ body: ApproveAccountRequest,
155
  user_token: str = Header(None, alias="User-key")
156
  ):
157
  """
 
160
  try:
161
  await verify_admin_token(user_token)
162
 
163
+ update_url = f"{SUPABASE_URL}/rest/v1/User?id=eq.{body.user_id}"
164
  payload = {
165
  "approved_account": True
166
  }
 
181
 
182
  @router.post("/admin/reject-account")
183
  async def reject_account(
184
+ body: RejectAccountRequest,
 
185
  user_token: str = Header(None, alias="User-key")
186
  ):
187
  """
 
190
  try:
191
  await verify_admin_token(user_token)
192
 
193
+ update_url = f"{SUPABASE_URL}/rest/v1/User?id=eq.{body.user_id}"
194
  payload = {
195
  "approved_account": False,
196
+ "approval_reason": body.reason or "No reason specified"
197
  }
198
 
199
  async with aiohttp.ClientSession() as session: