@@ -48,8 +48,21 @@ const PracticeProblemsKeyMappings = _.reduce(
48
48
* @param {Array<String> } filter.statuses the statues
49
49
* @param {Date } filter.registrationStartTimeAfter the start of the registration time
50
50
* @param {Date= } filter.registrationStartTimeBefore the end of the registration time
51
+ * @param {String } filter.sortBy the sort field
52
+ * @param {String } filter.sortOrder the sort order
53
+ * @param {Number } filter.page the sort order
54
+ * @param {Number } filter.perPage the sort order
51
55
*/
52
56
function getSRMScheduleQuery ( filter ) {
57
+ const offset = ( filter . page - 1 ) * filter . perPage ;
58
+ let sortBy = filter . sortBy ;
59
+ if ( criteria . sortBy === "registrationStartTime" ) {
60
+ sortBy = "reg.start_time" ;
61
+ } else if ( criteria . sortBy === "codingStartTime" ) {
62
+ sortBy = "coding.start_time" ;
63
+ } else if ( criteria . sortBy === "challengeStartTime" ) {
64
+ sortBy = "challenge.start_time" ;
65
+ }
53
66
const statuses = _ . join (
54
67
_ . map ( filter . statuses , ( s ) => `'${ _ . toUpper ( s ) } '` ) ,
55
68
","
@@ -64,8 +77,9 @@ function getSRMScheduleQuery(filter) {
64
77
: ""
65
78
} `;
66
79
67
- const query = `SELECT
68
- FIRST 50
80
+ const query = `SELECT
81
+ SKIP ${ offset }
82
+ FIRST ${ filter . perPage }
69
83
r.round_id AS roundId
70
84
, r.name AS name
71
85
, r.short_name AS shortName
@@ -95,8 +109,7 @@ function getSRMScheduleQuery(filter) {
95
109
r.round_type_id in (1,2,10) AND
96
110
UPPER(r.status) in (${ statuses } ) AND
97
111
${ registrationTimeFilter }
98
- ORDER BY
99
- reg.start_time DESC` ;
112
+ ORDER BY ${ sortBy } ${ filter . sortOrder } ` ;
100
113
return query ;
101
114
}
102
115
0 commit comments