diff --git a/actions/challenges.js b/actions/challenges.js index f0ad906ab..6693ae3cd 100755 --- a/actions/challenges.js +++ b/actions/challenges.js @@ -1,7 +1,7 @@ /* * Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved. * - * @version 1.19 + * @version 1.20 * @author Sky_, mekanizumu, TCSASSEMBLER, freegod, Ghost_141, kurtrips, xjtufreeman, ecnu_haozi, hesibo, LazyChild * @changes from 1.0 * merged with Member Registration API @@ -46,6 +46,8 @@ * add clientSelection flag in studio results * changes in 1.19: * add new allowed sort columns. + * changes in 1.20: + * add get challenge detail api for both design and develop challenge. */ "use strict"; /*jslint stupid: true, unparam: true, continue: true */ @@ -786,6 +788,10 @@ var getChallenge = function (api, connection, dbConnectionMap, isStudio, next) { submissionEndDate : formatDate(data.submission_end_date) }; + if (connection.action == "getChallenge") { + challenge.type = isStudio ? 'design' : 'develop'; + } + if (data.project_type === COPILOT_POSTING_PROJECT_TYPE && (isCopilot || helper.isAdmin(caller))) { challenge.copilotDetailedRequirements = data.copilot_detailed_requirements; } @@ -1515,6 +1521,44 @@ exports.getStudioChallenge = { } }; +/** + * The API for getting challenge details. + * + * @since 1.19 + */ +exports.getChallenge = { + name: "getChallenge", + description: "getStudioChallenge", + inputs: { + required: ["contestId"], + optional: ["refresh"] + }, + blockedConnectionTypes: [], + outputExample: {}, + version: 'v2', + transaction: 'read', // this action is read-only + databases: ["tcs_catalog", "tcs_dw"], + 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) { + if (err) { + api.helper.handleError(api, connection, err); + next(connection, true); + } else if (result.length == 0) { + api.helper.handleError(api, connection, new NotFoundError("Challenge not found.")); + next(connection, true); + } else { + var isStudio = Boolean(result[0].is_studio); + getChallenge(api, connection, connection.dbConnectionMap, isStudio, next); + } + }); + } else { + api.helper.handleNoConnection(api, connection, next); + } + } +}; + /** * The API for searching challenges */ diff --git a/queries/challenge_details b/queries/challenge_details index a80e5b354..9575117e0 100755 --- a/queries/challenge_details +++ b/queries/challenge_details @@ -53,7 +53,7 @@ SELECT ELSE 0 END AS current_phase_remaining_time , CASE WHEN pidr.value = 'On' THEN - NVL((SELECT value::decimal FROM project_info pi_dr WHERE pi_dr.project_info_type_id = 30 AND pi_dr.project_id = p.project_id), (SELECT round(NVL(pi16.value::decimal, 0)) FROM project_info pi16 WHERE pi16.project_info_type_id = 16 AND pi16.project_id = p.project_id)) + NVL((SELECT value::decimal FROM project_info pi_dr WHERE pi_dr.project_info_type_id = 30 AND pi_dr.project_id = p.project_id), (SELECT round(NVL(pi16.value::decimal, 1)) FROM project_info pi16 WHERE pi16.project_info_type_id = 16 AND pi16.project_id = p.project_id)) ELSE NULL END AS digital_run_points , pi51.value AS submission_limit , nvl((SELECT max(event_id) from contest_project_xref x, contest c where project_id = p.project_id and c.contest_id = x.contest_id), 0) as event_id diff --git a/routes.js b/routes.js index 356a1e2f6..67f2f9f74 100755 --- a/routes.js +++ b/routes.js @@ -138,6 +138,7 @@ var testMethods = { exports.routes = { get: [ { path: "/:apiVersion/logs", action: "getLogTail" }, + { path: "/:apiVersion/challenges/:contestId", action: "getChallenge" }, { path: "/:apiVersion/challenges", action: "searchSoftwareAndStudioChallenges" }, { path: "/:apiVersion/develop/challenges/checkpoint/:challengeId", action: "getSoftwareCheckpoint" },