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

Commit 5e3cc2e

Browse files
committed
Added auto_end parameter to fill in database
1 parent 45daf54 commit 5e3cc2e

File tree

6 files changed

+46
-9
lines changed

6 files changed

+46
-9
lines changed

actions/srmRoundManagement.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,13 @@ function checkContestRound(helper, obj) {
376376
helper.checkNumber(obj.roomAssignment.p, 'roomAssignment.p') ||
377377
helper.checkString(obj.name, 'name') ||
378378
helper.checkString(obj.status, 'status') ||
379-
helper.checkString(obj.short_name, 'short_name');
379+
helper.checkString(obj.short_name, 'short_name') ||
380+
helper.checkBoolean(obj.auto_end, 'auto_end');
380381
if (!error) {
381382
obj.roomAssignment.isByDivision = obj.roomAssignment.isByDivision ? 1 : 0;
382383
obj.roomAssignment.isByRegion = obj.roomAssignment.isByRegion ? 1 : 0;
383384
obj.roomAssignment.isFinal = obj.roomAssignment.isFinal ? 1 : 0;
385+
obj.auto_end = obj.auto_end ? 1 : 0;
384386
}
385387
return error;
386388
}
@@ -399,7 +401,7 @@ exports.createSRMContestRound = {
399401
inputs: {
400402
required: ['contest_id', 'type', 'invitationalType', 'region',
401403
'registrationLimit', 'roomAssignment', 'name', 'status', 'short_name'],
402-
optional: []
404+
optional: ['auto_end']
403405
},
404406
blockedConnectionTypes: [],
405407
outputExample: {},
@@ -412,6 +414,9 @@ exports.createSRMContestRound = {
412414
params = connection.params || {},
413415
helper = api.helper;
414416

417+
if (_.isUndefined(params.auto_end)) {
418+
params.auto_end = false;
419+
}
415420
if (!connection.dbConnectionMap) {
416421
helper.handleNoConnection(api, connection, next);
417422
return;
@@ -445,7 +450,8 @@ exports.createSRMContestRound = {
445450
region_id: params.region.region_id,
446451
name: params.name,
447452
status: params.status,
448-
short_name: params.short_name
453+
short_name: params.short_name,
454+
auto_end: params.auto_end
449455
},
450456
dbConnectionMap, cbx);
451457
}

apiary.apib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7338,6 +7338,7 @@ Request
73387338
* type (required, object) round's type, it's id should be set.
73397339
* region (required, object) round's region, it's id should be set.
73407340
* roomAssignment (required, object) round's roomAssginment, with field codersPerRoom(integer), type(integer), isByDivision, isByRegion, isFinal(boolean), p(Number).
7341+
* auto_end (optional, boolean) auto end flag
73417342

73427343
+ Response 200 (application/json)
73437344

queries/insert_srm_contest_round

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
INSERT INTO round (round_id, contest_id, round_type_id, registration_limit, invitational, region_id, name, status, short_name)
2-
VALUES (@round_id@, @contest_id@, @round_type_id@, @registration_limit@, @invitational@, @region_id@, '@name@', '@status@', '@short_name@')
1+
INSERT INTO round (round_id, contest_id, round_type_id, registration_limit, invitational, region_id, name, status, short_name, auto_end)
2+
VALUES (@round_id@, @contest_id@, @round_type_id@, @registration_limit@, @invitational@, @region_id@, '@name@', '@status@', '@short_name@', @auto_end@)

test/test.srmRoundManagement.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ describe('SRM Round Management APIs', function () {
129129
clearDb(done);
130130
});
131131

132-
133132
describe("List Round for Contest", function () {
134133
describe("Invalid request", function () {
135134
/**
@@ -660,6 +659,36 @@ describe('SRM Round Management APIs', function () {
660659
});
661660

662661

662+
/**
663+
* Check 400 response if auto_end is a string(not true or false)
664+
*/
665+
it("should return 400 when auto_end is not boolean(1,0,true,false)", function (done) {
666+
var rrequest = requestClone(goodRequest);
667+
rrequest.auto_end = "a";
668+
assertFail({
669+
oldRoundId: 1,
670+
json: rrequest,
671+
auth: testHelper.getAdminJwt(),
672+
status: 400,
673+
message: 'auto_end should be 0, 1, true or false.'
674+
}, done);
675+
});
676+
677+
/**
678+
* Check 400 response if invitationalType is number(not 0 or 1)
679+
*/
680+
it("should return 400 when auto_end is not boolean(1,0,true,false)", function (done) {
681+
var rrequest = requestClone(goodRequest);
682+
rrequest.auto_end = 10;
683+
assertFail({
684+
oldRoundId: 1,
685+
json: rrequest,
686+
auth: testHelper.getAdminJwt(),
687+
status: 400,
688+
message: 'auto_end should be 0, 1, true or false.'
689+
}, done);
690+
});
691+
663692
/**
664693
* Check 400 response if contest_id too big
665694
*/
@@ -1304,7 +1333,6 @@ describe('SRM Round Management APIs', function () {
13041333

13051334
});
13061335

1307-
13081336
describe("Modify SRM Contest Round", function () {
13091337

13101338
/**

test/test_files/srmRoundManagement/good_modify_request.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
},
1616
"name": "create round",
1717
"status": "A",
18-
"short_name": "create round short name"
18+
"short_name": "create round short name",
19+
"auto_end": 1
1920
}

test/test_files/srmRoundManagement/good_request.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
},
1515
"name": "create round",
1616
"status": "A",
17-
"short_name": "create round short name"
17+
"short_name": "create round short name",
18+
"auto_end": 1
1819
}

0 commit comments

Comments
 (0)