@@ -117,7 +117,6 @@ router.post("/question", userCheck, async (req, res) => {
117
117
118
118
router . post ( "/submit" , userCheck , async ( req , res ) => {
119
119
const qid = req . body . qid ;
120
- // console.log(qid);
121
120
const ctfFlag : string = req . body . ctfFlag ;
122
121
const timeStampUser : string = req . body . timeStampUser ;
123
122
@@ -140,11 +139,11 @@ router.post("/submit", userCheck, async (req, res) => {
140
139
if ( question . solvedBy . indexOf ( req . session . user ) > - 1 ) {
141
140
res . json ( {
142
141
success : false ,
143
- message : "Stop spamming!"
142
+ message : "Stop spamming!. Question already solved by you "
144
143
} ) ;
145
144
return ;
146
145
}
147
- console . log ( question , data ) ;
146
+ // console.log(question, data);
148
147
if ( data . ctfFlag == question . answer ) {
149
148
console . log ( req . session . user ) ;
150
149
const solved : boolean = true ;
@@ -178,7 +177,7 @@ router.post("/submit", userCheck, async (req, res) => {
178
177
$set : {
179
178
currentPoints : newPoints
180
179
} ,
181
- $push : { solvedBy : req . session . user }
180
+ $push : { solvedBy : [ req . session . user , new Date ( ) . toISOString ( ) . replace ( / T / , ' ' ) . replace ( / \. . + / , '' ) ] }
182
181
} ,
183
182
( err , doc ) => {
184
183
if ( err ) {
@@ -207,7 +206,7 @@ router.post("/submit", userCheck, async (req, res) => {
207
206
{ _id : new ObjectId ( req . session . userID ) } ,
208
207
{
209
208
$inc : { points : newPoints } ,
210
- $push : { solved : question . name }
209
+ $push : { solved : [ question . name , new Date ( ) . toISOString ( ) . replace ( / T / , ' ' ) . replace ( / \. . + / , '' ) ] }
211
210
} ,
212
211
( err , doc ) => {
213
212
console . log ( doc ) ;
@@ -285,7 +284,7 @@ router.post("/submit", userCheck, async (req, res) => {
285
284
const newAttempt = new attemptedChallenges ( {
286
285
questionId : data . qid ,
287
286
participant : req . session . userID ,
288
- timeSubmitted : Date ( ) ,
287
+ timeSubmitted : new Date ( ) . toISOString ( ) . replace ( / T / , ' ' ) . replace ( / \. . + / , '' ) ,
289
288
pointsOnSubmission : pointsOnAttempt
290
289
} ) ;
291
290
// console.log(newAttempt);
@@ -310,25 +309,15 @@ router.post("/submit", userCheck, async (req, res) => {
310
309
} ) ;
311
310
312
311
router . get ( "/leaderboard" , async ( req , res ) => {
313
- let currStandings = await Leaderboard . find ( { } , ( err , doc ) => {
314
- if ( err ) {
315
- console . log ( err ) ;
316
- res . status ( 400 ) . json ( {
317
- success : false ,
318
- message : "Failed leaderboard fetch"
319
- } ) ;
320
- return ;
321
- }
322
- if ( ! doc ) {
323
- res . status ( 400 ) . json ( {
324
- success : false ,
325
- message : "leaderboard not found"
326
- } ) ;
327
- return ;
328
- }
329
- } ) . sort ( { points : 1 } ) ;
330
-
331
- console . log ( currStandings ) ;
312
+ let currStandings = await Leaderboard . find ( { } ) . sort ( { points : 1 } )
313
+ if ( ! currStandings ) {
314
+ res . status ( 400 ) . json ( {
315
+ success : false ,
316
+ message : "Cannot find leaderboard this moment"
317
+ } ) ;
318
+ return ;
319
+ }
320
+ // console.log(currStandings);
332
321
// console.log(currStandings);
333
322
res . json ( currStandings ) ;
334
323
} ) ;
0 commit comments