fix(users): align user management API response parsing and field mapping

Aperta
#12 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@Rithish-2914 ci sta già lavorando.

Dal 18/9/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

bug
What happened?
Problem

The Admin User Management page (/users) is unable to render users and perform moderation actions due to API contract mismatches:

  1. Empty Users Table:

    • getUsers() in src/api/users.ts expects an un-enveloped response { status: string, users: User[], next_cursor?: string }.
    • The backend GET /admin/users returns standard envelope { "message": "Users fetched successfully", "data": [ UserResponse... ] }.
    • Because response.data.users is undefined, the TanStack table receives an empty array and displays no users.
  2. Field Mapping & Ban/Unban Parsing:

    • Backend UserResponse returns snake_case fields (id, name, email, reg_no, role, round_qualified, is_banned, balance, score), which need consistent normalization into the frontend User model.
    • banUser and unbanUser need response handling aligned with { message: string, data: UserResponse }.
  3. User Upgrade Request Body:

    • upgradeUserToRound() currently sends an empty POST body to POST /admin/users/:id/upgrade, whereas the backend expects UpgradeUserRequest containing round_qualified / role.

Proposed Solution
  1. Update src/api/users.ts:

    • Unwrap response.data.data in getUsers() and normalize id, name, email, reg_no, role, round_qualified, and is_banned.
    • Update banUser() and unbanUser() to handle backend response envelopes.
    • Allow passing roundQualified and role in upgradeUserToRound().
  2. Update src/app/(protected)/users/page.tsx & user-columns.tsx:

    • Ensure table accessors read the normalized User data.
    • Fix pagination display text.

Affected Files
  • src/api/users.ts
  • src/app/(protected)/users/page.tsx
  • src/app/(protected)/users/user-columns.tsx
Steps to reproduce
Steps to Reproduce
  1. Start the Go backend and log into the Admin portal (cookoff-admin-11.0) with an admin account.
  2. Navigate to the Users tab from the sidebar (/users).
  3. Observed Behavior: The table remains completely empty with no user rows rendered, despite users existing in the database (since response.data.users is undefined).
  4. Inspect Network tab for GET /admin/users: the response returns { "message": "Users fetched successfully", "data": [...] } with snake_case keys (id, reg_no, round_qualified), but the frontend expects { users: [...] } and PascalCase keys (ID, RegNo, RoundQualified).
  5. Triggering Ban/Unban or user upgrade fails to handle response wrappers or sends empty upgrade payloads.
Expected Behavior
  • /users should unwrap response.data.data, populate the table with all registered users, correctly display details (Name, RegNo, Email, Round, Role), and allow instant banning/unbanning and round upgrades
Environment

No response

Lingua principale
TypeScript
Stelle
0
Fork
1
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di CodeChefVIT/cookoff-admin-11.0

Tutte le issue di CodeChefVIT/cookoff-admin-11.0

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.