@@ -12,6 +12,7 @@ import config from '../../config/config';
1212var router = express . Router ( ) ;
1313const client = Container . get ( DatabaseProvider ) . client ( ) ;
1414
15+ // Delete a contest
1516router . delete ( '/competition/:id' , authenticate , loginRequired , ( req , res ) => {
1617 client . competitions
1718 . update ( {
@@ -35,10 +36,12 @@ router.delete('/competition/:id', authenticate, loginRequired, (req, res) => {
3536 } ) ;
3637} ) ;
3738
39+ // Create a contest
3840router . post ( '/competition' , authenticate , loginRequired , ( req , res ) => {
3941 const title = req . body . title ;
42+ const practice = Boolean ( req . body . practice ) ;
4043
41- if ( title == null || ( title as string ) . length > 20 ) {
44+ if ( title == null || ( title as string ) . length > 120 ) {
4245 Util . sendResponse (
4346 res ,
4447 resCode . badRequest ,
@@ -53,6 +56,7 @@ router.post('/competition', authenticate, loginRequired, (req, res) => {
5356 title : req . body . title ,
5457 description : req . body . description ,
5558 public : false ,
59+ practice : practice ,
5660 created_at : new Date ( ) ,
5761 host_user_id : res . locals . user . id ,
5862 updated_at : new Date ( ) ,
@@ -70,6 +74,7 @@ router.post('/competition', authenticate, loginRequired, (req, res) => {
7074 } ) ;
7175} ) ;
7276
77+ // Update a contest
7378router . put ( '/competition' , authenticate , loginRequired , ( req , res ) => {
7479 const competitionBody = req . body ;
7580 if (
@@ -123,6 +128,7 @@ router.put('/competition', authenticate, loginRequired, (req, res) => {
123128 } ) ;
124129} ) ;
125130
131+ // Fetch a contest
126132router . get ( '/competition/:id' , authenticate , loginRequired , ( req , res ) => {
127133 if ( req . params . id == '' ) {
128134 Util . sendResponse ( res , resCode . badRequest ) ;
@@ -175,6 +181,7 @@ function isAnyErrorPresent(obj: any) {
175181 return error ;
176182}
177183
184+ // Fetch quality of a contest
178185router . get (
179186 '/competition/:id/quality' ,
180187 authenticate ,
@@ -279,6 +286,7 @@ router.get(
279286 }
280287
281288 if (
289+ question . question_choices ?. length &&
282290 question . question_choices . every ( ( q ) => q . is_correct )
283291 ) {
284292 questionWarnings . question_choices . push (
@@ -327,6 +335,7 @@ router.get(
327335 }
328336) ;
329337
338+ // Fetch all contests
330339router . get ( '/competitions' , authenticate , ( req , res ) => {
331340 const user : UserInfo | null = res . locals . user ;
332341 const params = {
0 commit comments