File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ 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+ }
49+ } ;
50+
51+ export const createScore = async ( {
52+ team_id,
53+ design,
54+ implementation,
55+ presentation,
56+ innovation,
57+ teamwork,
58+ comment,
59+ round,
60+ } : CreateScoreRequest ) => {
61+ try {
62+ const response = await axios . post (
63+ `panel/createscore` ,
64+ {
65+ design,
66+ implementation,
67+ presentation,
68+ innovation,
69+ teamwork,
70+ comment,
71+ team_id,
72+ round,
73+ } ,
74+ {
75+ withCredentials : true ,
76+ }
77+ ) ;
78+ return response . data ;
79+ } catch ( err ) {
80+ console . log ( err ) ;
81+ throw err ;
82+ }
83+ } ;
84+
85+ export const deleteScore = async ( scoreId : string ) => {
86+ try {
87+ const response = await axios . delete ( `panel/deletescore/${ scoreId } ` , {
88+ withCredentials : true ,
89+ } ) ;
90+ return response . data ;
91+ } catch ( err ) {
92+ console . log ( err ) ;
93+ throw err ;
94+ }
95+ } ;
96+
97+ export const updateScore = async ( {
98+ scoreId,
99+ design,
100+ implementation,
101+ presentation,
102+ innovation,
103+ teamwork,
104+ comment,
105+ round
106+ } : {
107+ scoreId :string ,
108+ design :number ,
109+ implementation :number ,
110+ presentation :number ,
111+ innovation :number ,
112+ teamwork :number ,
113+ comment :string ,
114+ round :number ,
115+ } ) => {
116+ try {
117+ const response = await axios . put ( `panel/updatescore/${ scoreId } ` ,
118+ {
119+ design,
120+ implementation,
121+ presentation,
122+ innovation,
123+ teamwork,
124+ comment,
125+ round
126+ } ,
127+ {
128+ withCredentials : true
129+ } ) ;
130+ return response . data ;
131+ } catch ( err ) {
132+ console . log ( err ) ;
133+ throw err ;
134+ }
135+ } ;
You can’t perform that action at this time.
0 commit comments