Skip to content

Commit ed62dfb

Browse files
Merge pull request #14 from CodeChefVIT/sanjay/adminpanel
Build fix
2 parents 72fdeed + 6071dfd commit ed62dfb

2 files changed

Lines changed: 101 additions & 94 deletions

File tree

src/api/fetchScores.ts

Lines changed: 72 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
11
import axios from "./axiosConfig";
2+
import { z } from "zod";
3+
4+
const scoreSchema = z.object({
5+
id: z.string(),
6+
team_id: z.string(),
7+
design: z.number(),
8+
implementation: z.number(),
9+
presentation: z.number(),
10+
innovation: z.number(),
11+
teamwork: z.number(),
12+
comment: z.string(),
13+
round: z.number(),
14+
});
15+
const scoresResponseSchema = z.object({
16+
status: z.string(),
17+
message: z.string(),
18+
data: z.object({
19+
message: z.string(),
20+
scores: z.array(scoreSchema),
21+
}),
22+
});
223

3-
interface ScoreResponse {
4-
id: string;
5-
team_id: string;
6-
design: number;
7-
implementation: number;
8-
presentation: number;
9-
innovation: number;
10-
teamwork: number;
11-
comment: string;
12-
round: number;
13-
}
1424

15-
interface CreateScoreRequest {
16-
team_id: string;
17-
design: number;
18-
implementation: number;
19-
presentation: number;
20-
innovation: number;
21-
teamwork: number;
22-
comment: string;
23-
round: number;
25+
interface ScoreResponse extends z.infer<typeof scoreSchema>{}
26+
interface CreateScoreRequest extends Omit<z.infer<typeof scoreSchema>, 'id'>{
27+
team_id: string;
2428
}
2529

2630
export const fetchScores = async (teamId: string) => {
27-
try {
28-
const response = await axios.get<{
29-
status: string;
31+
try {
32+
const response = await axios.get<{
33+
status: string;
34+
message: string;
35+
data: {
3036
message: string;
31-
data: {
32-
message: string;
33-
scores: ScoreResponse[];
34-
};
35-
}>(`panel/getscore/${teamId}`, {
36-
withCredentials: true,
37-
});
38-
39-
// The scores are nested inside response.data.data.scores
40-
if (!response.data.data?.scores) {
41-
throw new Error('No scores data received');
42-
}
43-
44-
return response.data.data.scores;
45-
} catch (err) {
46-
console.error('Error fetching scores:', err);
47-
throw err;
48-
}
37+
scores: ScoreResponse[];
38+
};
39+
}>(`panel/getscore/${teamId}`, {
40+
withCredentials: true,
41+
});
42+
const parsedResponse = scoresResponseSchema.parse(response.data);
43+
return parsedResponse.data.scores;
44+
} catch (err) {
45+
console.error(err)
46+
throw err;
47+
}
4948
};
5049

50+
5151
export const createScore = async ({
52-
team_id,
53-
design,
54-
implementation,
55-
presentation,
56-
innovation,
57-
teamwork,
58-
comment,
59-
round,
52+
team_id,
53+
design,
54+
implementation,
55+
presentation,
56+
innovation,
57+
teamwork,
58+
comment,
59+
round,
6060
}: CreateScoreRequest) => {
6161
try {
62-
const response = await axios.post(
62+
const response = await axios.post(
6363
`panel/createscore`,
6464
{
6565
design,
@@ -71,32 +71,32 @@ export const createScore = async ({
7171
team_id,
7272
round,
7373
},
74-
{
75-
withCredentials: true,
76-
}
74+
{
75+
withCredentials: true,
76+
}
7777
);
78-
return response.data;
78+
return response.data;
7979
} catch (err) {
80-
console.log(err);
80+
console.error(err);
8181
throw err;
8282
}
8383
};
8484

8585
export const deleteScore = async (scoreId: string) => {
8686
try {
87-
const response = await axios.delete(`panel/deletescore/${scoreId}`, {
88-
withCredentials: true,
89-
});
87+
const response = await axios.delete(`panel/deletescore/${scoreId}`,{
88+
withCredentials: true,
89+
});
9090
return response.data;
9191
} catch (err) {
92-
console.log(err);
92+
console.error(err);
9393
throw err;
9494
}
9595
};
9696

9797
export const updateScore = async ({
98-
scoreId,
99-
design,
98+
scoreId,
99+
design,
100100
implementation,
101101
presentation,
102102
innovation,
@@ -116,20 +116,21 @@ export const updateScore = async ({
116116
try {
117117
const response = await axios.put(`panel/updatescore/${scoreId}`,
118118
{
119-
design,
119+
design,
120120
implementation,
121121
presentation,
122122
innovation,
123-
teamwork,
124-
comment,
125-
round
126-
},
127-
{
128-
withCredentials: true
129-
});
130-
return response.data;
123+
teamwork,
124+
comment,
125+
round
126+
},
127+
{
128+
withCredentials: true,
129+
}
130+
);
131+
return response.data;
131132
} catch (err) {
132-
console.log(err);
133+
console.error(err);
133134
throw err;
134135
}
135136
};

src/components/table/team-modal.tsx

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ interface TeamModalProps {
2323

2424
interface Score {
2525
id: string;
26-
team_id: string;
26+
team_id: string;
2727
design: number;
28-
implementation: number;
28+
implementation: number;
2929
presentation: number;
30-
innovation: number;
31-
teamwork: number;
32-
comment: string;
33-
round: number
30+
innovation: number;
31+
teamwork: number;
32+
comment: string;
33+
round: number
3434
}
3535

3636

@@ -100,15 +100,17 @@ export const TeamModal = ({ open, onClose, team }: TeamModalProps) => {
100100
teamwork,
101101
comment,
102102
round,
103+
103104
}: {
104-
scoreId: string,
105-
design: number,
106-
implementation: number,
107-
presentation: number,
108-
innovation: number,
109-
teamwork: number,
110-
comment: string,
111-
round: number,
105+
scoreId: string;
106+
design: number;
107+
implementation: number;
108+
presentation: number;
109+
innovation: number;
110+
teamwork: number;
111+
comment: string;
112+
round: number;
113+
112114
}) => updateScore({
113115
scoreId,
114116
design,
@@ -131,14 +133,18 @@ export const TeamModal = ({ open, onClose, team }: TeamModalProps) => {
131133

132134
const handleUpdateScore = async () => {
133135
if (!currentScoreId) return;
134-
await updateScoreMutation.mutateAsync({
135-
scoreId: currentScoreId,
136-
design,
137-
implementation,
138-
presentation,
139-
innovation,
140-
teamwork,
141-
comment,
136+
if(isNaN(Number(design)) || isNaN(Number(implementation)) || isNaN(Number(presentation)) || isNaN(Number(innovation))|| isNaN(Number(teamwork)) || isNaN(Number(round))){
137+
create("The score should be a number","error");
138+
return;
139+
}
140+
await updateScoreMutation.mutateAsync({
141+
scoreId: currentScoreId,
142+
design,
143+
implementation,
144+
presentation,
145+
innovation,
146+
teamwork,
147+
comment,
142148
round,
143149
});
144150
};
@@ -192,7 +198,7 @@ export const TeamModal = ({ open, onClose, team }: TeamModalProps) => {
192198
// setComment("");
193199
// setRound(0);
194200
// };
195-
201+
196202
const calculateTotalScore = (score: Score) => {
197203
return score.design + score.implementation + score.presentation +
198204
score.innovation + score.teamwork;

0 commit comments

Comments
 (0)