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

Commit 8d4846c

Browse files
committed
Merge user develop and design api
2 parents a27b9a8 + dbd5b68 commit 8d4846c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2812
-121
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 & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -63,48 +63,6 @@ var STUDIO_ID = 6;
6363
var OPENAIM_ID = 8;
6464
var HIGH_SCHOOL_ID = 3;
6565

66-
/**
67-
* check whether given user is activated.
68-
* @param {String} handle - the handle to check.
69-
* @param {Object} api - the action hero api object
70-
* @param {Object} dbConnectionMap - the database connection map
71-
* @param {Function<err>} callback - the callback function
72-
*/
73-
function checkCoderActivated(handle, api, dbConnectionMap, callback) {
74-
api.dataAccess.executeQuery('check_coder_activated', { handle: handle }, dbConnectionMap, function (err, result) {
75-
if (err) {
76-
callback(err, null);
77-
return;
78-
}
79-
if (result && result[0] && result[0].status === 'A') {
80-
callback(err, null);
81-
} else {
82-
callback(err, new BadRequestError('User is not activated.'));
83-
}
84-
});
85-
}
86-
87-
///**
88-
// * Check whether given user is activated.
89-
// * @param {String} handle - the handle to check.
90-
// * @param {Object} api - the action hero api object
91-
// * @param {Object} dbConnectionMap - the database connection map
92-
// * @param {Function<err>} callback - the callback function
93-
// */
94-
//function checkUserActivated(handle, api, dbConnectionMap, callback) {
95-
// api.dataAccess.executeQuery('check_user_activated', { handle: handle }, dbConnectionMap, function (err, result) {
96-
// if (err) {
97-
// callback(err, null);
98-
// return;
99-
// }
100-
// if (result && result[0] && result[0].status === 'A') {
101-
// callback(err, null);
102-
// } else {
103-
// callback(err, new BadRequestError('User is not activated.'));
104-
// }
105-
// });
106-
//}
107-
10866
/**
10967
* Update user preference.
11068
*
@@ -183,42 +141,6 @@ function updateDemographicResponse(key, value, questionId, userId, api, dbConnec
183141
}
184142

185143

186-
/**
187-
* Check if the user exist and activated.
188-
* @param {String} handle - the user handle.
189-
* @param {Object} api - the api object.
190-
* @param {Object} dbConnectionMap - the database connection map object.
191-
* @param {Function} callback - the callback function.
192-
* @since 1.10
193-
*/
194-
function checkUserExistAndActivate(handle, api, dbConnectionMap, callback) {
195-
async.waterfall([
196-
function (cb) {
197-
// check user existence and activated status.
198-
async.parallel({
199-
exist: function (cb) {
200-
api.helper.checkUserExists(handle, api, dbConnectionMap, cb);
201-
},
202-
activate: function (cb) {
203-
checkCoderActivated(handle, api, dbConnectionMap, cb);
204-
}
205-
}, cb);
206-
},
207-
function (results, cb) {
208-
// handle the error situation.
209-
if (results.exist) {
210-
cb(results.exist);
211-
return;
212-
}
213-
if (results.activate) {
214-
cb(results.activate);
215-
return;
216-
}
217-
cb();
218-
}
219-
], callback);
220-
}
221-
222144
/**
223145
* Get the user basic profile information.
224146
* @param {Object} api - the api object.
@@ -270,7 +192,7 @@ function getBasicUserProfile(api, handle, privateInfoEligibility, dbConnectionMa
270192
}
271193
});
272194
} else {
273-
checkUserExistAndActivate(handle, api, dbConnectionMap, cb);
195+
helper.checkCoderExistAndActivate(handle, api, dbConnectionMap, cb);
274196
}
275197
}, function (cb) {
276198
var execQuery = function (name) {
@@ -785,7 +707,7 @@ exports.getMarathonStatistics = {
785707
}
786708
async.waterfall([
787709
function (cb) {
788-
checkUserExistAndActivate(handle, api, dbConnectionMap, cb);
710+
helper.checkCoderExistAndActivate(handle, api, dbConnectionMap, cb);
789711
}, function (cb) {
790712
var executeQuery = function (sqlName, cbx) {
791713
api.dataAccess.executeQuery(sqlName, sqlParams, dbConnectionMap, cbx);
@@ -899,7 +821,7 @@ exports.getSoftwareStatistics = {
899821
cb();
900822
}
901823
}, function (cb) {
902-
checkUserExistAndActivate(handle, api, dbConnectionMap, cb);
824+
helper.checkCoderExistAndActivate(handle, api, dbConnectionMap, cb);
903825
}, function (cb) {
904826
var execQuery = function (name, cbx) {
905827
api.dataAccess.executeQuery(name,
@@ -1036,7 +958,7 @@ exports.getStudioStatistics = {
1036958

1037959
async.waterfall([
1038960
function (cb) {
1039-
checkUserExistAndActivate(handle, api, dbConnectionMap, cb);
961+
helper.checkCoderExistAndActivate(handle, api, dbConnectionMap, cb);
1040962
}, function (cb) {
1041963
api.dataAccess.executeQuery('get_studio_member_statistics_track', sqlParams, dbConnectionMap, cb);
1042964
}, function (results, cb) {
@@ -1105,7 +1027,7 @@ exports.getAlgorithmStatistics = {
11051027
}
11061028
async.waterfall([
11071029
function (cb) {
1108-
checkUserExistAndActivate(handle, api, dbConnectionMap, cb);
1030+
helper.checkCoderExistAndActivate(handle, api, dbConnectionMap, cb);
11091031
}, function (cb) {
11101032
var execQuery = function (name) {
11111033
return function (cbx) {
@@ -1498,7 +1420,7 @@ exports.getCopilotStatistics = {
14981420
cb();
14991421
}
15001422
}, function (cb) {
1501-
checkUserExistAndActivate(handle, api, dbConnectionMap, cb);
1423+
helper.checkCoderExistAndActivate(handle, api, dbConnectionMap, cb);
15021424
}, function (cb) {
15031425
var execQuery = function (name, cbx) {
15041426
api.dataAccess.executeQuery(name,

actions/srmChallenges.js

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright (C) 2013-2014 TopCoder Inc., All Rights Reserved.
33
*
4-
* @version 1.8
4+
* @version 1.9
55
* @author Sky_, freegod, panoptimum, Ghost_141
66
* changes in 1.1:
77
* - implement srm API
@@ -26,6 +26,8 @@
2626
* - Update search srm challenges api. Add challengeName filter.
2727
* Changes in 1.8:
2828
* - Implement get srm practice problems api.
29+
* Changes in 1.9:
30+
* - Implement Rounds For Problem API
2931
*/
3032
/*jslint node: true, nomen: true */
3133
"use strict";
@@ -2079,7 +2081,7 @@ function getPracticeProblems(api, connection, next) {
20792081
sqlParams = {
20802082
firstRowIndex: (pageIndex - 1) * pageSize,
20812083
pageSize: pageSize,
2082-
sortColumn: helper.getSortColumnDBName(sortColumn.toLowerCase()),
2084+
sortColumn: helper.getSortColumnDBName(sortColumn),
20832085
sortOrder: sortOrder.toLowerCase(),
20842086
userId: caller.userId
20852087
};
@@ -2137,3 +2139,112 @@ exports.getPracticeProblems = {
21372139
}
21382140
}
21392141
};
2142+
2143+
/**
2144+
* getSrmRoundsForProblem implements the rounds for problem api.
2145+
*
2146+
* @param {Object} api - The api object.
2147+
* @param {Object} connection - The connection object.
2148+
* @param {Function} next - The callback function.
2149+
*/
2150+
function getSrmRoundsForProblem(api, connection, next) {
2151+
// control flow designators
2152+
var problemId = 'problemId',
2153+
checkProblem = 'checkProblem',
2154+
// shortcuts
2155+
helper = api.helper,
2156+
dbConnectionMap = connection.dbConnectionMap,
2157+
dataAccess = _.bind(api.dataAccess.executeQuery, api.dataAccess);
2158+
return async.waterfall(
2159+
[
2160+
function (cb) {
2161+
var id = parseInt(connection.params.problemId, 10),
2162+
error = helper.checkIdParameter(id, problemId),
2163+
results = {};
2164+
if (error) {
2165+
return cb(error);
2166+
}
2167+
results[problemId] = id;
2168+
return cb(null, results);
2169+
},
2170+
function (results, cb) {
2171+
var id = results[problemId];
2172+
dataAccess(
2173+
'check_problem_exists',
2174+
{problem_id: id},
2175+
dbConnectionMap,
2176+
function (error, result) {
2177+
if (error) {
2178+
return cb(error);
2179+
}
2180+
results[checkProblem] = result;
2181+
return cb(null, results);
2182+
}
2183+
);
2184+
},
2185+
function (results, cb) {
2186+
if (results[checkProblem][0].is_there) {
2187+
return cb(null, results);
2188+
}
2189+
return cb(new NotFoundError("The problem doesn't exist."));
2190+
},
2191+
function (results, cb) {
2192+
var id = results[problemId];
2193+
return dataAccess(
2194+
'get_rounds_for_problem',
2195+
{problem_id: id},
2196+
dbConnectionMap,
2197+
function (error, result) {
2198+
if (error) {
2199+
return cb(error);
2200+
}
2201+
return cb(
2202+
null,
2203+
{
2204+
rounds: helper.transferDBResults2Response(result)
2205+
}
2206+
);
2207+
}
2208+
);
2209+
}
2210+
],
2211+
function (error, results) {
2212+
if (error) {
2213+
helper.handleError(api, connection, error);
2214+
return next(connection, true);
2215+
}
2216+
connection.response = results;
2217+
return next(connection, true);
2218+
}
2219+
);
2220+
}
2221+
2222+
/**
2223+
* Rounds For Problem API
2224+
*
2225+
* This api returns the rounds that used the given problem (identified by problem id).
2226+
* This api will exclude the practice rounds.
2227+
* This api includes only finished rounds
2228+
*
2229+
* @since 1.9
2230+
*/
2231+
exports.getSrmRoundsForProblem = {
2232+
name: "getSrmRoundsForProblem",
2233+
description: "SRM Rounds For Problem API",
2234+
inputs: {
2235+
required: ['problemId'],
2236+
optional: []
2237+
},
2238+
blockedConnectionTypes: [],
2239+
outputExample: {},
2240+
version: 'v2',
2241+
transaction: 'read', // this action is read-only
2242+
databases: ["topcoder_dw"],
2243+
run: function (api, connection, next) {
2244+
if (connection.dbConnectionMap) {
2245+
api.log("Execute getSrmRoundsForProblem", 'debug');
2246+
return getSrmRoundsForProblem(api, connection, next);
2247+
}
2248+
return api.helper.handleNoConnection(api, connection, next);
2249+
}
2250+
};

0 commit comments

Comments
 (0)