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

Commit 2a661e4

Browse files
committed
Merge pull request #382 from clevertension/dev
TC API - Get Round Term API
2 parents 012de41 + 015af47 commit 2a661e4

File tree

7 files changed

+516
-2
lines changed

7 files changed

+516
-2
lines changed

actions/srmRoundComponentsAndTerms.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,47 @@ var setRoundTerms = function (api, connection, dbConnectionMap, next) {
300300
});
301301
};
302302

303+
/**
304+
* Gets round terms.
305+
*
306+
* @param api the api instance.
307+
* @param connection the connection instance
308+
* @param dbConnectionMap the database connection map
309+
* @param next the callback method
310+
*/
311+
var getRoundTerms = function (api, connection, dbConnectionMap, next) {
312+
var helper = api.helper,
313+
sqlParams = {},
314+
roundId = Number(connection.params.roundId),
315+
roundTermsContent = '';
316+
317+
async.waterfall([
318+
function (cb) {
319+
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
320+
}, function (cb) {
321+
cb(helper.checkIdParameter(roundId, "roundId"));
322+
}, function (cb) {
323+
sqlParams.round_id = roundId;
324+
api.dataAccess.executeQuery("get_round_terms", sqlParams, dbConnectionMap, cb);
325+
}, function (results, cb) {
326+
if (!results || results.length === 0) {
327+
var error = new IllegalArgumentError("The round terms can't be found with such roundId = " + roundId);
328+
cb(error);
329+
} else {
330+
roundTermsContent = results[0].terms_content;
331+
cb();
332+
}
333+
}
334+
], function (err) {
335+
if (err) {
336+
helper.handleError(api, connection, err);
337+
} else {
338+
connection.response = {"roundTermsContent": roundTermsContent};
339+
}
340+
next(connection, true);
341+
});
342+
};
343+
303344
/**
304345
* The API for Set Round Components.
305346
*/
@@ -349,3 +390,28 @@ exports.setRoundTerms = {
349390
}
350391
}
351392
};
393+
394+
/**
395+
* The API for Get Round Terms.
396+
*/
397+
exports.getRoundTerms = {
398+
name: "getRoundTerms",
399+
description: "Get Round Terms",
400+
inputs: {
401+
required: ['roundId'],
402+
optional: []
403+
},
404+
blockedConnectionTypes: [],
405+
outputExample: {},
406+
version: 'v2',
407+
transaction: 'read',
408+
databases: ["informixoltp"],
409+
run: function (api, connection, next) {
410+
if (connection.dbConnectionMap) {
411+
api.log("Execute getRoundTerms#run", 'debug');
412+
getRoundTerms(api, connection, connection.dbConnectionMap, next);
413+
} else {
414+
api.helper.handleNoConnection(api, connection, next);
415+
}
416+
}
417+
};

apiary.apib

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9107,6 +9107,57 @@ Request
91079107
"description":"Servers are up but overloaded. Try again later."
91089108
}
91099109

9110+
## Get round terms of use [/data/srm/rounds/:roundId/terms]
9111+
### Get round terms of use by round id [GET]
9112+
9113+
- Only when jwt passed can we get the round terms of use.
9114+
9115+
+ Parameters
9116+
+ roundId (required, number, `13672`) ... The id of round
9117+
9118+
+ Request
9119+
9120+
+ Headers
9121+
9122+
Authorization : Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZHwxMzI0NTYiLCJleHAiOjEzOTM3MDM1NzEsImF1ZCI6InRvcGNvZGVyIiwiaWF0IjoxMzkzNjQzNTcxfQ.F2iohKp2nwjQeGqrBD1wn42GJUD0r28aGjhDle7KujA
9123+
9124+
+ Response 200 (application/json)
9125+
9126+
{
9127+
"roundTermsContent": "The round terms content..."
9128+
}
9129+
+ Response 401 (application/json)
9130+
9131+
{
9132+
"name":"Unauthorized",
9133+
"value":"401",
9134+
"description":"Authentication credentials were missing or incorrect."
9135+
}
9136+
9137+
+ Response 404 (application/json)
9138+
9139+
{
9140+
"name":"Not Found",
9141+
"value":"404",
9142+
"description":"This message will explain why the URI requested is invalid or the resource does not exist."
9143+
}
9144+
9145+
+ Response 500 (application/json)
9146+
9147+
{
9148+
"name":"Internal Server Error",
9149+
"value":"500",
9150+
"description":"Unknown server error. Please contact support."
9151+
}
9152+
9153+
+ Response 503 (application/json)
9154+
9155+
{
9156+
"name":"Service Unavailable",
9157+
"value":"503",
9158+
"description":"Servers are up but overloaded. Try again later."
9159+
}
9160+
91109161
## Agree terms of use [/terms/{termsOfUseId}/agree]
91119162
### Agree terms of use by id [POST]
91129163

0 commit comments

Comments
 (0)