Skip to content

Commit fe1d93e

Browse files
leaderboard works!
1 parent 4e64ece commit fe1d93e

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

src/api/leaderboard.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
import { z } from "zod";
22
import axios from "./axiosConfig";
33
export const scoreSchema = z.object({
4-
team_name: z.string(),
4+
round: z.number(),
55
design: z.number(),
66
implementation: z.number(),
77
presentation: z.number(),
88
innovation: z.number(),
9-
teamwork: z.number(),
10-
comment: z.string(),
11-
total_score: z.number(),
9+
teamwork: z.number(), // Change from string to number
10+
round_total: z.number(),
1211
});
12+
13+
// Define the schema for a leaderboard user/team
1314
export const leaderboardUserSchema = z.object({
14-
ID: z.string(),
1515
team_id: z.string(),
1616
team_name: z.string(),
1717
rounds: z.array(scoreSchema),
1818
overall_total: z.number(),
1919
});
2020

21-
export type Leaderboard = z.infer<typeof leaderboardUserSchema>;
22-
23-
export const leaderBoardResponseSchema = z.object({
21+
// Define the schema for the whole response
22+
export const leaderboardResponseSchema = z.object({
2423
status: z.string(),
2524
message: z.string(),
2625
data: z.object({
27-
users: z.array(leaderboardUserSchema).nullable(),
26+
leaderboard: z.array(leaderboardUserSchema), // Array of teams
27+
next_cursor: z.string().nullable(),
2828
}),
29-
next_cursor: z.string(),
3029
});
31-
export type LeaderboardResponse = z.infer<typeof leaderBoardResponseSchema>;
30+
export type Leaderboard = z.infer<typeof leaderboardUserSchema> ;
3231

32+
// Type inference for the leaderboard response
33+
export type LeaderboardResponse = z.infer<typeof leaderboardResponseSchema>;
3334
export const fetchLeaderboard = async ({
3435
limit,
3536
cursorId,
@@ -52,10 +53,10 @@ export const fetchLeaderboard = async ({
5253

5354
const response = await axios.get<LeaderboardResponse>(url);
5455

55-
const parsedResponse = leaderBoardResponseSchema.parse(response.data);
56-
const users = parsedResponse.data.users;
56+
const parsedResponse = leaderboardResponseSchema.parse(response.data);
57+
const users = parsedResponse.data.leaderboard;
5758
console.log(users);
58-
const nextCursor = parsedResponse.next_cursor;
59+
const nextCursor = parsedResponse.data.next_cursor;
5960

6061
return {
6162
users,

0 commit comments

Comments
 (0)