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

Đang mở
#12 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

@Rithish-2914 đang làm issue này rồi.

Từ ngày 18/9/2026.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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

Ngôn ngữ chính
TypeScript
Star
0
Fork
1
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của CodeChefVIT/cookoff-admin-11.0

Tất cả issue của CodeChefVIT/cookoff-admin-11.0

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.