Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 34afb00

Browse files
committed
Few updates to improve helper.js and fix bug in user algo challenges api.
1 parent 644d19d commit 34afb00

File tree

9 files changed

+33
-47
lines changed

9 files changed

+33
-47
lines changed

actions/challenges.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ var searchChallenges = function (api, connection, dbConnectionMap, community, ne
933933
sqlParams.firstRowIndex = (pageIndex - 1) * pageSize;
934934
sqlParams.pageSize = pageSize;
935935
sqlParams.sortColumn = sortColumn.toLowerCase();
936-
sqlParams.sortColumn = helper.getSortColumnDBName(sortColumn.toLowerCase());
936+
sqlParams.sortColumn = helper.getSortColumnDBName(sortColumn);
937937
sqlParams.sortOrder = sortOrder.toLowerCase();
938938
// Set the project type id
939939
sqlParams.project_type_id = challengeType.category;
@@ -3684,7 +3684,7 @@ var getChallenges = function (api, connection, listType, isMyChallenges, next) {
36843684
sqlParams = _.extend(sqlParams, {
36853685
first_row_index: (pageIndex - 1) * pageSize,
36863686
page_size: pageSize,
3687-
sort_column: helper.getSortColumnDBName(sortColumn.toLowerCase()),
3687+
sort_column: helper.getSortColumnDBName(sortColumn),
36883688
sort_order: sortOrder.toLowerCase(),
36893689
track: type.category,
36903690
// Set the submission phase status id.

actions/memberStatistics.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function getBasicUserProfile(api, handle, privateInfoEligibility, dbConnectionMa
192192
}
193193
});
194194
} else {
195-
helper.checkUserExistAndActivate(handle, api, dbConnectionMap, cb);
195+
helper.checkCoderExistAndActivate(handle, api, dbConnectionMap, cb);
196196
}
197197
}, function (cb) {
198198
var execQuery = function (name) {
@@ -707,7 +707,7 @@ exports.getMarathonStatistics = {
707707
}
708708
async.waterfall([
709709
function (cb) {
710-
helper.checkUserExistAndActivate(handle, api, dbConnectionMap, cb);
710+
helper.checkCoderExistAndActivate(handle, api, dbConnectionMap, cb);
711711
}, function (cb) {
712712
var executeQuery = function (sqlName, cbx) {
713713
api.dataAccess.executeQuery(sqlName, sqlParams, dbConnectionMap, cbx);
@@ -821,7 +821,7 @@ exports.getSoftwareStatistics = {
821821
cb();
822822
}
823823
}, function (cb) {
824-
helper.checkUserExistAndActivate(handle, api, dbConnectionMap, cb);
824+
helper.checkCoderExistAndActivate(handle, api, dbConnectionMap, cb);
825825
}, function (cb) {
826826
var execQuery = function (name, cbx) {
827827
api.dataAccess.executeQuery(name,
@@ -958,7 +958,7 @@ exports.getStudioStatistics = {
958958

959959
async.waterfall([
960960
function (cb) {
961-
helper.checkUserExistAndActivate(handle, api, dbConnectionMap, cb);
961+
helper.checkCoderExistAndActivate(handle, api, dbConnectionMap, cb);
962962
}, function (cb) {
963963
api.dataAccess.executeQuery('get_studio_member_statistics_track', sqlParams, dbConnectionMap, cb);
964964
}, function (results, cb) {
@@ -1027,7 +1027,7 @@ exports.getAlgorithmStatistics = {
10271027
}
10281028
async.waterfall([
10291029
function (cb) {
1030-
helper.checkUserExistAndActivate(handle, api, dbConnectionMap, cb);
1030+
helper.checkCoderExistAndActivate(handle, api, dbConnectionMap, cb);
10311031
}, function (cb) {
10321032
var execQuery = function (name) {
10331033
return function (cbx) {
@@ -1420,7 +1420,7 @@ exports.getCopilotStatistics = {
14201420
cb();
14211421
}
14221422
}, function (cb) {
1423-
helper.checkUserExistAndActivate(handle, api, dbConnectionMap, cb);
1423+
helper.checkCoderExistAndActivate(handle, api, dbConnectionMap, cb);
14241424
}, function (cb) {
14251425
var execQuery = function (name, cbx) {
14261426
api.dataAccess.executeQuery(name,

actions/srmChallenges.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2079,7 +2079,7 @@ function getPracticeProblems(api, connection, next) {
20792079
sqlParams = {
20802080
firstRowIndex: (pageIndex - 1) * pageSize,
20812081
pageSize: pageSize,
2082-
sortColumn: helper.getSortColumnDBName(sortColumn.toLowerCase()),
2082+
sortColumn: helper.getSortColumnDBName(sortColumn),
20832083
sortOrder: sortOrder.toLowerCase(),
20842084
userId: caller.userId
20852085
};

actions/user.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ function getUserMarathonMatches(api, connection, next) {
489489
cb(error);
490490
},
491491
function (cb) {
492-
helper.checkUserExistAndActivate(handle, api, dbConnectionMap, cb);
492+
helper.checkCoderExistAndActivate(handle, api, dbConnectionMap, cb);
493493
},
494494
function (cb) {
495495
sqlParams = {
@@ -612,25 +612,14 @@ function getUserAlgorithmChallenges(api, connection, next) {
612612
cb(error);
613613
},
614614
function (cb) {
615-
helper.checkUserExists(handle, api, dbConnectionMap, cb);
615+
helper.checkCoderExistAndActivate(handle, api, dbConnectionMap, cb);
616616
},
617-
function (err, cb) {
618-
if (err) {
619-
cb(err);
620-
return;
621-
}
622-
helper.checkUserActivated(handle, api, dbConnectionMap, cb);
623-
},
624-
function (err, cb) {
625-
if (err) {
626-
cb(err);
627-
return;
628-
}
617+
function (cb) {
629618
sqlParams = {
630619
first_row_index: (pageIndex - 1) * pageSize,
631620
page_size: pageSize,
632621
sort_order: sortOrder,
633-
sort_column: helper.getSortColumnDBName(sortColumn.toLowerCase()),
622+
sort_column: helper.getSortColumnDBName(sortColumn),
634623
handle: handle.toLowerCase()
635624
};
636625
async.parallel({
@@ -642,7 +631,7 @@ function getUserAlgorithmChallenges(api, connection, next) {
642631
var total = queryResult.count[0].total_count;
643632
response = {
644633
pageIndex: pageIndex,
645-
pageSize: pageIndex === -1 ? total : pageSize,
634+
pageSize: pageSize,
646635
total: total,
647636
data: queryResult.data.map(function (row) {
648637
return {
@@ -685,7 +674,7 @@ exports.getUserAlgorithmChallenges = {
685674
outputExample: {},
686675
version: 'v2',
687676
transaction: 'read',
688-
databases: ['topcoder_dw', 'common_oltp'],
677+
databases: ['topcoder_dw'],
689678
run: function (api, connection, next) {
690679
if (connection.dbConnectionMap) {
691680
api.log('getUserAlgorithmChallenges#run', 'debug');

initializers/helper.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@
106106
* - Move checkUserExistAndActivated method from actions/memberStatistics.js to this file.
107107
* Changes in 1.40:
108108
* - Update apiName2dbNameMap to add entries for coding_duration, num_contestants and num_submitters.
109+
* - Update getSortColumnDBName method to return column name in lower case.
110+
* - Update getLowerCaseList method to use map method.
109111
*/
110112
"use strict";
111113

@@ -861,11 +863,7 @@ helper.checkFilterDate = function (date, dateName, dateFormat) {
861863
* @return {Array} the array with lowercase strings
862864
*/
863865
helper.getLowerCaseList = function (arr) {
864-
var ret = [];
865-
arr.forEach(function (s) {
866-
ret.push(s.toLowerCase());
867-
});
868-
return ret;
866+
return arr.map(function (s) { return s.toLowerCase(); });
869867
};
870868

871869
/**
@@ -1162,7 +1160,7 @@ helper.getSortColumnDBName = function (apiName) {
11621160
if (_.isDefined(apiName2dbNameMap[apiName.toLowerCase()])) {
11631161
return apiName2dbNameMap[apiName.toLowerCase()];
11641162
}
1165-
return apiName;
1163+
return apiName.toLowerCase();
11661164
};
11671165

11681166

@@ -1637,13 +1635,14 @@ helper.checkCoderActivated = function (handle, api, dbConnectionMap, callback) {
16371635

16381636
/**
16391637
* Check if the user exist and activated.
1638+
* The method name coder indicate that this is checking topcoder_dw.coder instead of common_oltp.user table.
16401639
* @param {String} handle - the user handle.
16411640
* @param {Object} api - the api object.
16421641
* @param {Object} dbConnectionMap - the database connection map object.
16431642
* @param {Function} callback - the callback function.
16441643
* @since 1.39
16451644
*/
1646-
helper.checkUserExistAndActivate = function (handle, api, dbConnectionMap, callback) {
1645+
helper.checkCoderExistAndActivate = function (handle, api, dbConnectionMap, callback) {
16471646
async.waterfall([
16481647
function (cb) {
16491648
// check user existence and activated status.

test/sqls/getUserAlgoChallenges/common_oltp__clean

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/sqls/getUserAlgoChallenges/common_oltp__insert_test_data

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/sqls/getUserAlgoChallenges/topcoder_dw__insert_test_data

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ INSERT INTO round_type_lu(round_type_id,round_type_desc,algo_rating_type_id) VAL
4747
INSERT INTO round_type_lu(round_type_id,round_type_desc,algo_rating_type_id) VALUES (22, 'AMD Marathon Match', NULL);
4848
INSERT INTO round_type_lu(round_type_id,round_type_desc,algo_rating_type_id) VALUES (23, 'AMD Marathon Match Practice', NULL);
4949

50-
INSERT INTO coder(coder_id, handle, handle_lower) VALUES(132456, 'heffan', 'heffan');
51-
INSERT INTO coder(coder_id, handle, handle_lower) VALUES(300001, 'user1', 'user1');
52-
INSERT INTO coder(coder_id, handle, handle_lower) VALUES(300002, 'user2', 'user2');
53-
INSERT INTO coder(coder_id, handle, handle_lower) VALUES(300003, 'user3', 'user3');
54-
INSERT INTO coder(coder_id, handle, handle_lower) VALUES(300004, 'user4', 'user4');
55-
INSERT INTO coder(coder_id, handle, handle_lower) VALUES(300005, 'user5', 'user5');
56-
INSERT INTO coder(coder_id, handle, handle_lower) VALUES(300006, 'user6', 'user6');
57-
INSERT INTO coder(coder_id, handle, handle_lower) VALUES(300007, 'user7', 'user7');
58-
INSERT INTO coder(coder_id, handle, handle_lower) VALUES(300008, 'user8', 'user8');
59-
INSERT INTO coder(coder_id, handle, handle_lower) VALUES(300009, 'user9', 'user9');
60-
INSERT INTO coder(coder_id, handle, handle_lower) VALUES(300010, 'user10', 'user10');
50+
INSERT INTO coder(coder_id, handle, handle_lower, status) VALUES(132456, 'heffan', 'heffan', 'A');
51+
INSERT INTO coder(coder_id, handle, handle_lower, status) VALUES(300001, 'user1', 'user1', 'A');
52+
INSERT INTO coder(coder_id, handle, handle_lower, status) VALUES(300002, 'user2', 'user2', 'U');
53+
INSERT INTO coder(coder_id, handle, handle_lower, status) VALUES(300003, 'user3', 'user3', 'A');
54+
INSERT INTO coder(coder_id, handle, handle_lower, status) VALUES(300004, 'user4', 'user4', 'A');
55+
INSERT INTO coder(coder_id, handle, handle_lower, status) VALUES(300005, 'user5', 'user5', 'A');
56+
INSERT INTO coder(coder_id, handle, handle_lower, status) VALUES(300006, 'user6', 'user6', 'A');
57+
INSERT INTO coder(coder_id, handle, handle_lower, status) VALUES(300007, 'user7', 'user7', 'A');
58+
INSERT INTO coder(coder_id, handle, handle_lower, status) VALUES(300008, 'user8', 'user8', 'A');
59+
INSERT INTO coder(coder_id, handle, handle_lower, status) VALUES(300009, 'user9', 'user9', 'A');
60+
INSERT INTO coder(coder_id, handle, handle_lower, status) VALUES(300010, 'user10', 'user10', 'A');
6161

6262
INSERT INTO coder_rank_type_lu(coder_rank_type_id, coder_rank_type_desc) VALUES(2, 'Test');
6363

test/test_files/getUserAlgoChallenges/expected_get_user_algo_challenges_error_message.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"notExisted": "User does not exist."
1717
},
1818
"invalidSortOrder": "sortOrder should be an element of asc,desc.",
19-
"invalidSortColumn": "The sort column 'abc' is invalid, it should be element of id,type,prize,codingDuration,placement,numContestants,numSubmitters.",
19+
"invalidSortColumn": "The sort column 'abc' is invalid, it should be element of id,type,codingDuration,placement,numContestants,numSubmitters.",
2020
"missingSortColumn": "The sortColumn is missing.",
2121
"inActivatedUser": "User is not activated."
2222
}

0 commit comments

Comments
 (0)