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

Challenges rss #176

Merged
merged 3 commits into from
Apr 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions actions/challengeRegistration.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ var timelineNotification = function (api, userId, challengeId, dbConnectionMap,
dbConnectionMap,
cb);
} else {
cb(null);
}
cb(null);
}
}
], next);
};
Expand Down Expand Up @@ -685,23 +685,23 @@ var registerSoftwareChallengeAction = function (api, connection, next) {
if (connection.dbConnectionMap) {
api.log("Execute registerSoftwareChallengeAction#run", 'debug');

var challengeId = Number(connection.params.challengeId);
var sqlParams = {
challengeId: challengeId,
user_id: connection.caller.userId
};
var execQuery = function (name) {
return function (cbx) {
api.dataAccess.executeQuery(name, sqlParams, connection.dbConnectionMap, cbx);
var challengeId = Number(connection.params.challengeId),
sqlParams = {
challengeId: challengeId,
user_id: connection.caller.userId
},
execQuery = function (name) {
return function (cbx) {
api.dataAccess.executeQuery(name, sqlParams, connection.dbConnectionMap, cbx);
};
};
};
async.waterfall([
function(cb) {
function (cb) {
async.parallel({
isCopilotPosting: execQuery('check_challenge_is_copilot_posting'),
isCopilot: execQuery('check_is_copilot')
}, cb);
}, function(res, cb) {
}, function (res, cb) {
if (res.isCopilotPosting.length > 0 && res.isCopilotPosting[0].challenge_is_copilot) {
if (res.isCopilot.length === 0 || !res.isCopilot[0].user_is_copilot) {
cb(new ForbiddenError('You should be a copilot before register a copilot posting.'));
Expand Down
48 changes: 10 additions & 38 deletions actions/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,6 @@ var ALLOWABLE_SORT_COLUMN = [
"postingDate", "numSubmissions", "numRegistrants", "currentPhaseRemainingTime", "currentPhaseName", "registrationOpen"
];

/**
* Represents a ListType enum
*/
var ListType = { ACTIVE: "ACTIVE", OPEN: "OPEN", UPCOMING: "UPCOMING", PAST: "PAST" };

/**
* Represents a predefined list of valid list type.
*/
var ALLOWABLE_LIST_TYPE = [ListType.ACTIVE, ListType.OPEN, ListType.UPCOMING, ListType.PAST];

/**
* Represents Percentage of Placement Points for digital run
*/
Expand All @@ -118,24 +108,6 @@ var DR_POINT = [[1], [0.7, 0.3], [0.65, 0.25, 0.10], [0.6, 0.22, 0.1, 0.08], [0.
*/
var MAX_INT = 2147483647;

/**
* The list type and registration phase status map.
*/
var LIST_TYPE_REGISTRATION_STATUS_MAP = {};
LIST_TYPE_REGISTRATION_STATUS_MAP[ListType.ACTIVE] = [2, 3];
LIST_TYPE_REGISTRATION_STATUS_MAP[ListType.OPEN] = [2];
LIST_TYPE_REGISTRATION_STATUS_MAP[ListType.UPCOMING] = [1];
LIST_TYPE_REGISTRATION_STATUS_MAP[ListType.PAST] = [3];

/**
* The list type and project status map.
*/
var LIST_TYPE_PROJECT_STATUS_MAP = {};
LIST_TYPE_PROJECT_STATUS_MAP[ListType.ACTIVE] = [1];
LIST_TYPE_PROJECT_STATUS_MAP[ListType.OPEN] = [1];
LIST_TYPE_PROJECT_STATUS_MAP[ListType.UPCOMING] = [2];
LIST_TYPE_PROJECT_STATUS_MAP[ListType.PAST] = [4, 5, 6, 7, 8, 9, 10, 11];

/**
* This copilot posting project type id
*/
Expand Down Expand Up @@ -207,7 +179,7 @@ function validateInputParameter(helper, caller, challengeType, query, filter, pa
helper.checkPositiveInteger(pageSize, "pageSize") ||
helper.checkMaxNumber(pageSize, MAX_INT, 'pageSize') ||
helper.checkMaxNumber(pageIndex, MAX_INT, 'pageIndex') ||
helper.checkContains(ALLOWABLE_LIST_TYPE, type.toUpperCase(), "type") ||
helper.checkContains(helper.ALLOWABLE_LIST_TYPE, type.toUpperCase(), "type") ||
checkQueryParameterAndSortColumn(helper, type, query, sortColumn);

if (_.isDefined(query.communityId)) {
Expand Down Expand Up @@ -480,7 +452,7 @@ var searchChallenges = function (api, connection, dbConnectionMap, community, ne

sortOrder = query.sortorder || "asc";
sortColumn = query.sortcolumn || DEFAULT_SORT_COLUMN;
listType = (query.listtype || ListType.OPEN).toUpperCase();
listType = (query.listtype || helper.ListType.OPEN).toUpperCase();
pageIndex = Number(query.pageindex || 1);
pageSize = Number(query.pagesize || 50);

Expand Down Expand Up @@ -508,8 +480,8 @@ var searchChallenges = function (api, connection, dbConnectionMap, community, ne
// Set the project type id
sqlParams.project_type_id = challengeType.category;
// Set the submission phase status id.
sqlParams.registration_phase_status = LIST_TYPE_REGISTRATION_STATUS_MAP[listType];
sqlParams.project_status_id = LIST_TYPE_PROJECT_STATUS_MAP[listType];
sqlParams.registration_phase_status = helper.LIST_TYPE_REGISTRATION_STATUS_MAP[listType];
sqlParams.project_status_id = helper.LIST_TYPE_PROJECT_STATUS_MAP[listType];
sqlParams.userId = caller.userId || 0;

// Check the private challenge access
Expand Down Expand Up @@ -788,7 +760,7 @@ var getChallenge = function (api, connection, dbConnectionMap, isStudio, next) {
submissionEndDate : formatDate(data.submission_end_date)
};

if (connection.action == "getChallenge") {
if (connection.action === "getChallenge") {
challenge.type = isStudio ? 'design' : 'develop';
}

Expand Down Expand Up @@ -1023,7 +995,7 @@ var submitForDevelopChallenge = function (api, connection, dbConnectionMap, next
console.log('-------------------------------------------');
console.log(stats.size + '\t' + api.config.submissionMaxSizeBytes);
console.log('-------------------------------------------');

if (stats.size > api.config.submissionMaxSizeBytes) {
cb(new RequestTooLargeError(
"The submission file size is greater than the max allowed size: " + (api.config.submissionMaxSizeBytes / 1024) + " KB."
Expand All @@ -1049,7 +1021,7 @@ var submitForDevelopChallenge = function (api, connection, dbConnectionMap, next
fileName: uploadId + "_" + fileName
});
api.dataAccess.executeQuery("insert_upload", sqlParams, dbConnectionMap, cb);
}, function(notUsed, cb) {
}, function (notUsed, cb) {
//Now check if the contest is a CloudSpokes one and if it needs to submit the thurgood job
if (!_.isUndefined(thurgoodPlatform) && !_.isUndefined(thurgoodLanguage) && type === 'final') {
//Make request to the thurgood job api url
Expand Down Expand Up @@ -1541,11 +1513,11 @@ exports.getChallenge = {
run: function (api, connection, next) {
if (connection.dbConnectionMap) {
api.log("Execute getChallenge#run", 'debug');
api.dataAccess.executeQuery('check_challenge_exists', {challengeId: connection.params.contestId}, connection.dbConnectionMap, function(err, result) {
api.dataAccess.executeQuery('check_challenge_exists', {challengeId: connection.params.contestId}, connection.dbConnectionMap, function (err, result) {
if (err) {
api.helper.handleError(api, connection, err);
next(connection, true);
} else if (result.length == 0) {
} else if (result.length === 0) {
api.helper.handleError(api, connection, new NotFoundError("Challenge not found."));
next(connection, true);
} else {
Expand Down Expand Up @@ -1771,7 +1743,7 @@ var DEFAULT_FONT_URL = 'community.topcoder.com/studio/the-process/font-policy/';
* Gets the file type based on the file name extension. Return null if not found.
* @since 1.14
*
* @param {Object} file - The file name
* @param {Object} fileName - The file name
* @param {Object} fileTypes - The file types from which to read
*/
var getFileType = function (fileName, fileTypes) {
Expand Down
6 changes: 3 additions & 3 deletions actions/docusign.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ exports.action = {
api.log("Executing getDocusignViewURL#run", 'debug');
async.waterfall([
function (cb) {
var x, spl, u;
var x, spl;

//Check if the templateId is valid
if (!templateId.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i)) {
Expand Down Expand Up @@ -185,8 +185,8 @@ exports.action = {
//persist the new envelope to database
sqlParams.envelopeId = resp.envelopeId;
sqlParams.complete = 0;
api.dataAccess.executeQuery(
'insert_docusign_envelope', sqlParams, dbConnectionMap, function (err) {
api.dataAccess.executeQuery('insert_docusign_envelope', sqlParams, dbConnectionMap,
function (err) {
if (err) {
cb(err);
return;
Expand Down
6 changes: 3 additions & 3 deletions actions/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ var downloadDesignSubmission = function (api, connection, dbConnectionMap, next)
noRights = false;
}

//Screener can download submission if screening has started
//Screener can download submission if screening has started
if (_.intersection(myResourceRoleIds, screenerRoles).length > 0 && basicInfo[0].is_at_or_after_screening) {
noRights = false;
}
Expand All @@ -595,9 +595,9 @@ var downloadDesignSubmission = function (api, connection, dbConnectionMap, next)
}
}

//managers can download the submissions anytime
//managers can download the submissions anytime
if (noRights && isManager) {
noRights = false;
noRights = false;
}

//everyone - can download previews and watermarks after review and if submissions are viewable
Expand Down
38 changes: 23 additions & 15 deletions actions/memberStatistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,26 @@ function getBasicUserProfile(api, handle, privateInfoEligibility, dbConnectionMa
sqlParams = {
handle: handle
},
result;
result,
loadData,
requestedData,
parts;

var loadData;
// check for an optional data query string param than enables loading a subset of data
var requestedData = connection.rawConnection.parsedURL.query.data;
requestedData = connection.rawConnection.parsedURL.query.data;
if (_.isDefined(requestedData)) {
// NOTE: an empty value is acceptable and indicates only basic data is returned
loadData = {};
if (requestedData) {
// data is comma delimited string of requested data
var parts = requestedData.split(',');
parts = requestedData.split(',');
_.each(parts, function (part) {
loadData[part] = true;
});
}
api.log("Requested data param found: " + requestedData, "debug");
} else {
loadData = {earnings:true, ratings:true, achievements:true, address:true, email:true}; // load all data by default
loadData = {earnings: true, ratings: true, achievements: true, address: true, email: true}; // load all data by default
}

async.waterfall([
Expand All @@ -159,14 +161,20 @@ function getBasicUserProfile(api, handle, privateInfoEligibility, dbConnectionMa
};
async.parallel({
basic: execQuery('basic'),
earning: loadData.earnings ? execQuery('overall_earning') : function(cbx) { cbx(); },
ratingSummary: loadData.ratings ? execQuery('rating_summary') : function(cbx) { cbx(); },
achievements: loadData.achievements ? execQuery('achievements') : function(cbx) { cbx(); },
earning: loadData.earnings ? execQuery('overall_earning') : function (cbx) { cbx(); },
ratingSummary: loadData.ratings ? execQuery('rating_summary') : function (cbx) { cbx(); },
achievements: loadData.achievements ? execQuery('achievements') : function (cbx) { cbx(); },
privateInfo: loadData.address && privateInfoEligibility ? execQuery('private') : function (cbx) { cbx(); },
emails: loadData.email && privateInfoEligibility ? execQuery('private_email') : function (cbx) { cbx(); }
}, cb);
}, function (results, cb) {
var basic = results.basic[0];
var basic = results.basic[0],
ratingSummary,
achievements,
emails,
appendIfNotEmpty,
privateInfo,
address;

result = {
handle: basic.handle,
Expand All @@ -181,7 +189,7 @@ function getBasicUserProfile(api, handle, privateInfoEligibility, dbConnectionMa
}

if (loadData.ratings) {
var ratingSummary = [];
ratingSummary = [];
results.ratingSummary.forEach(function (item) {
ratingSummary.push({
name: helper.getPhaseName(item.phase_id),
Expand All @@ -193,7 +201,7 @@ function getBasicUserProfile(api, handle, privateInfoEligibility, dbConnectionMa
}

if (loadData.achievements) {
var achievements = [];
achievements = [];
results.achievements.forEach(function (item) {
achievements.push({
date: item.achievement_date,
Expand All @@ -205,7 +213,7 @@ function getBasicUserProfile(api, handle, privateInfoEligibility, dbConnectionMa
}

if (privateInfoEligibility && loadData.email) {
var emails = [];
emails = [];
results.emails.forEach(function (item) {
emails.push({
email: item.email,
Expand All @@ -217,22 +225,22 @@ function getBasicUserProfile(api, handle, privateInfoEligibility, dbConnectionMa
}

if (privateInfoEligibility && loadData.address && results.privateInfo && results.privateInfo[0]) {
var appendIfNotEmpty = function (str) {
appendIfNotEmpty = function (str) {
var ret = '';
if (str && str.length > 0) {
ret += ', ' + str;
}
return ret;
};

var privateInfo = results.privateInfo[0];
privateInfo = results.privateInfo[0];

result.name = privateInfo.first_name + ' ' + privateInfo.last_name;
result.age = privateInfo.age;
result.gender = privateInfo.gender;
result.shirtSize = privateInfo.shirt_size;

var address = privateInfo.address1;
address = privateInfo.address1;
// if address1 is undefined, there is no address.
if (address) {
address += appendIfNotEmpty(privateInfo.address2);
Expand Down
Loading