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

Commit be41301

Browse files
committed
Revert "TC API - Modify Answer API And Delete Answer API"
1 parent 9a8b3ba commit be41301

13 files changed

+14
-824
lines changed

actions/srmRoundQuestions.js

Lines changed: 9 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
/*
22
* Copyright (C) 2014 TopCoder Inc., All Rights Reserved.
3-
*
4-
* @version 1.2
5-
* @author isv
6-
*
7-
* - Implement the srm round questions / answers / survey api.
3+
*/
4+
/**
5+
* - Implement the srm round questions / answers / survey api.
86
* Changes in version 1.1 (Module Assembly - Web Arena - Match Configurations):
97
* - Updated getRoundQuestions to send roundId with response
10-
* Changes in 1.2:
11-
* - Added actions for modifying/deleting round question answers.
8+
*
9+
* @version 1.1
10+
* @author TCSASSEMBLER
1211
*/
1312

1413
/*jslint node: true, nomen: true, plusplus: true, stupid: true, unparam: true */
@@ -17,7 +16,6 @@ var async = require('async');
1716
var _ = require('underscore');
1817
var moment = require('moment');
1918
var IllegalArgumentError = require('../errors/IllegalArgumentError');
20-
var NotFoundError = require('../errors/NotFoundError');
2119

2220
var DATE_FORMAT = "YYYY-MM-DD HH:mm";
2321

@@ -329,8 +327,7 @@ function checkAnswerValues(api, text, sortOrder, correct, callback) {
329327
error = helper.checkStringParameter(text, "text", 250);
330328

331329
if (!error && _.isDefined(sortOrder)) {
332-
error = helper.checkPositiveInteger(sortOrder, "sortOrder")
333-
|| helper.checkMaxInt(sortOrder, "sortOrder");
330+
error = helper.checkPositiveInteger(sortOrder, "sortOrder");
334331
}
335332

336333
if (!error && _.isDefined(correct)) {
@@ -612,8 +609,8 @@ var modifyRoundQuestion = function (api, connection, dbConnectionMap, next) {
612609
*/
613610
var deleteRoundQuestion = function (api, connection, dbConnectionMap, next) {
614611
var helper = api.helper,
615-
sqlParams = {},
616-
questionId = Number(connection.params.questionId);
612+
sqlParams = {},
613+
questionId = Number(connection.params.questionId);
617614

618615
async.waterfall([
619616
function (cb) {
@@ -634,115 +631,6 @@ var deleteRoundQuestion = function (api, connection, dbConnectionMap, next) {
634631
});
635632
};
636633

637-
/**
638-
* Checks if answer with specified ID exists in database.
639-
*
640-
* @param api the api instance.
641-
* @param dbConnectionMap the database connection map.
642-
* @param answerId - the answerId parameter.
643-
* @param callback the callback method.
644-
*/
645-
function checkAnswerId(api, dbConnectionMap, answerId, callback) {
646-
var helper = api.helper,
647-
error = helper.checkIdParameter(answerId, "answerId");
648-
649-
async.waterfall([
650-
function (cb) {
651-
if (!error) {
652-
api.dataAccess.executeQuery("get_answer_id", {answerId: answerId}, dbConnectionMap, cb);
653-
} else {
654-
cb(null, null);
655-
}
656-
}, function (results, cb) {
657-
if (!error) {
658-
if (results.length === 0) {
659-
error = new NotFoundError("The answerId does not exist in database.");
660-
}
661-
}
662-
cb(error);
663-
}
664-
], function (err) {
665-
if (err) {
666-
callback(err);
667-
return;
668-
}
669-
670-
callback(null, error);
671-
});
672-
}
673-
674-
/**
675-
* Modify Round Question Answer.
676-
*
677-
* @param api the api instance.
678-
* @param connection the connection instance.
679-
* @param dbConnectionMap the database connection map.
680-
* @param next the callback method.
681-
*/
682-
var modifyRoundQuestionAnswer = function (api, connection, dbConnectionMap, next) {
683-
var helper = api.helper,
684-
sqlParams = {},
685-
answerId = Number(connection.params.answerId),
686-
text = connection.params.text,
687-
sortOrder = connection.params.sortOrder,
688-
correct = connection.params.correct;
689-
690-
async.waterfall([
691-
function (cb) {
692-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
693-
}, function (cb) {
694-
checkAnswerValues(api, text, sortOrder, correct, cb);
695-
}, function (error, cb) {
696-
checkAnswerId(api, dbConnectionMap, answerId, cb);
697-
}, function (error, cb) {
698-
sqlParams.answerId = answerId;
699-
sqlParams.answerText = text;
700-
sqlParams.sortOrder = sortOrder;
701-
sqlParams.correct = (correct === true || correct.toLowerCase() === "true") ? 1 : 0;
702-
api.dataAccess.executeQuery("update_answer", sqlParams, dbConnectionMap, cb);
703-
}
704-
], function (err) {
705-
if (err) {
706-
helper.handleError(api, connection, err);
707-
} else {
708-
connection.response = {"success": true};
709-
}
710-
next(connection, true);
711-
});
712-
};
713-
714-
/**
715-
* Delete Round Question Answer.
716-
*
717-
* @param api the api instance.
718-
* @param connection the connection instance.
719-
* @param dbConnectionMap the database connection map.
720-
* @param next the callback method.
721-
*/
722-
var deleteRoundQuestionAnswer = function (api, connection, dbConnectionMap, next) {
723-
var helper = api.helper,
724-
sqlParams = {},
725-
answerId = Number(connection.params.answerId);
726-
727-
async.waterfall([
728-
function (cb) {
729-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
730-
}, function (cb) {
731-
cb(helper.checkIdParameter(answerId, 'answerId'));
732-
}, function (cb) {
733-
sqlParams.answerId = answerId;
734-
api.dataAccess.executeQuery("delete_answer", sqlParams, dbConnectionMap, cb);
735-
}
736-
], function (err, result) {
737-
if (err) {
738-
helper.handleError(api, connection, err);
739-
} else {
740-
connection.response = {"success": result > 0};
741-
}
742-
next(connection, true);
743-
});
744-
};
745-
746634
/**
747635
* The API for get Round Questions API.
748636
*/
@@ -914,53 +802,3 @@ exports.deleteRoundQuestion = {
914802
}
915803
}
916804
};
917-
918-
/**
919-
* The API for Modify Round Question Answer API.
920-
*/
921-
exports.modifyRoundQuestionAnswer = {
922-
name: "modifyRoundQuestionAnswer",
923-
description: "Modify Round Question Answer",
924-
inputs: {
925-
required: ['answerId', 'text', 'sortOrder', 'correct'],
926-
optional: []
927-
},
928-
blockedConnectionTypes: [],
929-
outputExample: {},
930-
version: 'v2',
931-
transaction: 'write',
932-
databases: ["informixoltp"],
933-
run: function (api, connection, next) {
934-
if (connection.dbConnectionMap) {
935-
api.log("Execute modifyRoundQuestionAnswer#run", 'debug');
936-
modifyRoundQuestionAnswer(api, connection, connection.dbConnectionMap, next);
937-
} else {
938-
api.helper.handleNoConnection(api, connection, next);
939-
}
940-
}
941-
};
942-
943-
/**
944-
* The API for Delete Round Question Answer API.
945-
*/
946-
exports.deleteRoundQuestionAnswer = {
947-
name: "deleteRoundQuestionAnswer",
948-
description: "Delete Round Question Answer",
949-
inputs: {
950-
required: ['answerId'],
951-
optional: []
952-
},
953-
blockedConnectionTypes: [],
954-
outputExample: {},
955-
version: 'v2',
956-
transaction: 'write',
957-
databases: ["informixoltp"],
958-
run: function (api, connection, next) {
959-
if (connection.dbConnectionMap) {
960-
api.log("Execute deleteRoundQuestionAnswer#run", 'debug');
961-
deleteRoundQuestionAnswer(api, connection, connection.dbConnectionMap, next);
962-
} else {
963-
api.helper.handleNoConnection(api, connection, next);
964-
}
965-
}
966-
};

0 commit comments

Comments
 (0)