11/*
22 * Copyright (C) 2013-2014 TopCoder Inc., All Rights Reserved.
33 *
4- * @version 1.6
4+ * @version 1.7
55 * @author Sky_, freegod, panoptimum, Ghost_141
66 * changes in 1.1:
77 * - implement srm API
2222 * - added API for retrieving SRM schedule
2323 * Changes in 1.6:
2424 * - Update search srm challenges api to use informixoltp database.
25+ * Changes in 1.7:
26+ * - Update search srm challenges api. Add challengeName filter.
2527 */
2628/*jslint node: true, nomen: true */
2729"use strict" ;
@@ -179,7 +181,7 @@ exports.searchSRMChallenges = {
179181 description : "searchSRMChallenges" ,
180182 inputs : {
181183 required : [ ] ,
182- optional : [ "pageSize" , "pageIndex" , "sortColumn" , "sortOrder" , "listType" ]
184+ optional : [ "pageSize" , "pageIndex" , "sortColumn" , "sortOrder" , "listType" , "challengeName" ]
183185 } ,
184186 blockedConnectionTypes : [ ] ,
185187 outputExample : { } ,
@@ -189,7 +191,7 @@ exports.searchSRMChallenges = {
189191 run : function ( api , connection , next ) {
190192 api . log ( "Execute searchSRMChallenges#run" , 'debug' ) ;
191193 var helper = api . helper , params = connection . params , sqlParams , listType ,
192- pageIndex , pageSize , sortColumn , sortOrder , error , result , status ,
194+ pageIndex , pageSize , sortColumn , sortOrder , error , result , status , challengeName ,
193195 dbConnectionMap = connection . dbConnectionMap ;
194196 if ( ! dbConnectionMap ) {
195197 helper . handleNoConnection ( api , connection , next ) ;
@@ -205,6 +207,7 @@ exports.searchSRMChallenges = {
205207 pageIndex = Number ( params . pageIndex || 1 ) ;
206208 pageSize = Number ( params . pageSize || DEFAULT_PAGE_SIZE ) ;
207209 listType = ( params . listType || 'ACTIVE' ) . toUpperCase ( ) ;
210+ challengeName = '%' + params . challengeName . toLowerCase ( ) + '%' || '%' ;
208211
209212 if ( ! _ . isDefined ( params . sortOrder ) && sortColumn === "roundid" ) {
210213 sortOrder = "desc" ;
@@ -229,6 +232,7 @@ exports.searchSRMChallenges = {
229232 helper . checkPositiveInteger ( pageSize , "pageSize" ) ||
230233 helper . checkContains ( [ "asc" , "desc" ] , sortOrder , "sortOrder" ) ||
231234 helper . checkContains ( [ helper . ListType . ACTIVE , helper . ListType . UPCOMING ] , listType , 'listType' ) ||
235+ _ . checkArgument ( challengeName . length <= 32 , 'The challengeName should less than 32 characters.' ) ||
232236 helper . checkContains ( allowedSort , sortColumn , "sortColumn" ) ;
233237 if ( error ) {
234238 cb ( error ) ;
@@ -244,6 +248,7 @@ exports.searchSRMChallenges = {
244248 pageSize : pageSize ,
245249 sortColumn : helper . getSortColumnDBName ( sortColumn ) ,
246250 sortOrder : sortOrder ,
251+ challengeName : challengeName ,
247252 status : status
248253 } ;
249254
0 commit comments