Skip to content

Commit 18d07fc

Browse files
committed
Team Score
1 parent fb7fcd2 commit 18d07fc

2 files changed

Lines changed: 401 additions & 51 deletions

File tree

src/api/fetchScores.ts

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import axios from "./axiosConfig";
2+
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+
}
14+
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;
24+
}
25+
26+
export const fetchScores = async (teamId: string) => {
27+
try {
28+
const response = await axios.get<{
29+
status: string;
30+
message: string;
31+
scores: ScoreResponse[];
32+
}>(`panel/getscore/${teamId}`, {
33+
withCredentials: true,
34+
});
35+
return response.data.scores;
36+
} catch (err) {
37+
console.log(err);
38+
throw err;
39+
}
40+
};
41+
42+
export const createScore = async ({
43+
team_id,
44+
design,
45+
implementation,
46+
presentation,
47+
innovation,
48+
teamwork,
49+
comment,
50+
round,
51+
}: CreateScoreRequest) => {
52+
try {
53+
const response = await axios.post(
54+
`panel/createscore`,
55+
{
56+
design,
57+
implementation,
58+
presentation,
59+
innovation,
60+
teamwork,
61+
comment,
62+
team_id,
63+
round,
64+
},
65+
{
66+
withCredentials: true,
67+
}
68+
);
69+
return response.data;
70+
} catch (err) {
71+
console.log(err);
72+
throw err;
73+
}
74+
};
75+
76+
export const deleteScore = async (scoreId: string) => {
77+
try {
78+
const response = await axios.delete(`panel/deletescore/${scoreId}`, {
79+
withCredentials: true,
80+
});
81+
return response.data;
82+
} catch (err) {
83+
console.log(err);
84+
throw err;
85+
}
86+
};
87+
88+
export const updateScore = async ({
89+
scoreId,
90+
design,
91+
implementation,
92+
presentation,
93+
innovation,
94+
teamwork,
95+
comment,
96+
round
97+
}: {
98+
scoreId:string,
99+
design:number,
100+
implementation:number,
101+
presentation:number,
102+
innovation:number,
103+
teamwork:number,
104+
comment:string,
105+
round:number,
106+
}) => {
107+
try {
108+
const response = await axios.put(`panel/updatescore/${scoreId}`,
109+
{
110+
design,
111+
implementation,
112+
presentation,
113+
innovation,
114+
teamwork,
115+
comment,
116+
round
117+
},
118+
{
119+
withCredentials: true
120+
});
121+
return response.data;
122+
} catch (err) {
123+
console.log(err);
124+
throw err;
125+
}
126+
};

0 commit comments

Comments
 (0)