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

Added auto_end parameter to fill in database #395

Merged
merged 6 commits into from
Dec 29, 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
12 changes: 9 additions & 3 deletions actions/srmRoundManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,13 @@ function checkContestRound(helper, obj) {
helper.checkNumber(obj.roomAssignment.p, 'roomAssignment.p') ||
helper.checkString(obj.name, 'name') ||
helper.checkString(obj.status, 'status') ||
helper.checkString(obj.short_name, 'short_name');
helper.checkString(obj.short_name, 'short_name') ||
helper.checkBoolean(obj.auto_end, 'auto_end');
if (!error) {
obj.roomAssignment.isByDivision = obj.roomAssignment.isByDivision ? 1 : 0;
obj.roomAssignment.isByRegion = obj.roomAssignment.isByRegion ? 1 : 0;
obj.roomAssignment.isFinal = obj.roomAssignment.isFinal ? 1 : 0;
obj.auto_end = obj.auto_end ? 1 : 0;
}
return error;
}
Expand All @@ -399,7 +401,7 @@ exports.createSRMContestRound = {
inputs: {
required: ['contest_id', 'type', 'invitationalType', 'region',
'registrationLimit', 'roomAssignment', 'name', 'status', 'short_name'],
optional: []
optional: ['auto_end']
},
blockedConnectionTypes: [],
outputExample: {},
Expand All @@ -412,6 +414,9 @@ exports.createSRMContestRound = {
params = connection.params || {},
helper = api.helper;

if (_.isUndefined(params.auto_end)) {
params.auto_end = false;
}
if (!connection.dbConnectionMap) {
helper.handleNoConnection(api, connection, next);
return;
Expand Down Expand Up @@ -445,7 +450,8 @@ exports.createSRMContestRound = {
region_id: params.region.region_id,
name: params.name,
status: params.status,
short_name: params.short_name
short_name: params.short_name,
auto_end: params.auto_end
},
dbConnectionMap, cbx);
}
Expand Down
2 changes: 2 additions & 0 deletions actions/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ var getTermsOfUse = function (api, connection, dbConnectionMap, next) {
return;
}

sqlParams.userId = connection.caller.userId;

async.waterfall([
function (cb) {
// validate termsOfUseId parameter and set sql parameter
Expand Down
1 change: 1 addition & 0 deletions apiary.apib
Original file line number Diff line number Diff line change
Expand Up @@ -7338,6 +7338,7 @@ Request
* type (required, object) round's type, it's id should be set.
* region (required, object) round's region, it's id should be set.
* roomAssignment (required, object) round's roomAssginment, with field codersPerRoom(integer), type(integer), isByDivision, isByRegion, isFinal(boolean), p(Number).
* auto_end (optional, boolean) auto end flag

+ Response 200 (application/json)

Expand Down
4 changes: 3 additions & 1 deletion queries/get_terms_of_use
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ SELECT tou.terms_of_use_id as terms_of_use_id,
touat.name as agreeability_type,
tou.terms_text as text,
touat.terms_of_use_agreeability_type_id as agreeability_type_id,
toudtx.docusign_template_id as docusign_template_id
toudtx.docusign_template_id as docusign_template_id,
(utuox.user_id IS NOT NULL) as agreed
FROM terms_of_use tou
INNER JOIN terms_of_use_agreeability_type_lu touat ON touat.terms_of_use_agreeability_type_id = tou.terms_of_use_agreeability_type_id
LEFT JOIN terms_of_use_docusign_template_xref toudtx ON toudtx.terms_of_use_id = tou.terms_of_use_id
LEFT JOIN user_terms_of_use_xref utuox ON utuox.terms_of_use_id = tou.terms_of_use_id AND utuox.user_id = @userId@
WHERE tou.terms_of_use_id = @termsOfUseId@
4 changes: 2 additions & 2 deletions queries/insert_srm_contest_round
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
INSERT INTO round (round_id, contest_id, round_type_id, registration_limit, invitational, region_id, name, status, short_name)
VALUES (@round_id@, @contest_id@, @round_type_id@, @registration_limit@, @invitational@, @region_id@, '@name@', '@status@', '@short_name@')
INSERT INTO round (round_id, contest_id, round_type_id, registration_limit, invitational, region_id, name, status, short_name, auto_end)
VALUES (@round_id@, @contest_id@, @round_type_id@, @registration_limit@, @invitational@, @region_id@, '@name@', '@status@', '@short_name@', @auto_end@)
32 changes: 30 additions & 2 deletions test/test.srmRoundManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ describe('SRM Round Management APIs', function () {
clearDb(done);
});


describe("List Round for Contest", function () {
describe("Invalid request", function () {
/**
Expand Down Expand Up @@ -660,6 +659,36 @@ describe('SRM Round Management APIs', function () {
});


/**
* Check 400 response if auto_end is a string(not true or false)
*/
it("should return 400 when auto_end is not boolean(1,0,true,false)", function (done) {
var rrequest = requestClone(goodRequest);
rrequest.auto_end = "a";
assertFail({
oldRoundId: 1,
json: rrequest,
auth: testHelper.getAdminJwt(),
status: 400,
message: 'auto_end should be 0, 1, true or false.'
}, done);
});

/**
* Check 400 response if invitationalType is number(not 0 or 1)
*/
it("should return 400 when auto_end is not boolean(1,0,true,false)", function (done) {
var rrequest = requestClone(goodRequest);
rrequest.auto_end = 10;
assertFail({
oldRoundId: 1,
json: rrequest,
auth: testHelper.getAdminJwt(),
status: 400,
message: 'auto_end should be 0, 1, true or false.'
}, done);
});

/**
* Check 400 response if contest_id too big
*/
Expand Down Expand Up @@ -1304,7 +1333,6 @@ describe('SRM Round Management APIs', function () {

});


describe("Modify SRM Contest Round", function () {

/**
Expand Down
3 changes: 2 additions & 1 deletion test/test_files/srmRoundManagement/good_modify_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
},
"name": "create round",
"status": "A",
"short_name": "create round short name"
"short_name": "create round short name",
"auto_end": 1
}
3 changes: 2 additions & 1 deletion test/test_files/srmRoundManagement/good_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
},
"name": "create round",
"status": "A",
"short_name": "create round short name"
"short_name": "create round short name",
"auto_end": 1
}