Added ability to add benchmark results to a test
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const Benchmark = require('../models').models.Benchmark;
|
||||
const Result = require('../models').models.Result;
|
||||
const Test = require('../models').models.Test;
|
||||
|
||||
// GET /api/v1/benchmark/details
|
||||
exports.getBenchmarkDetails = async function(req, res) {
|
||||
@@ -37,3 +38,26 @@ exports.getResultList = async function(req, res) {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// POST /api/v1/result/add - add a benchmark result to the database
|
||||
exports.postResultAdd = async function(req, res) {
|
||||
try {
|
||||
const result = await Result.create({
|
||||
avgScore: req.body.result_avg,
|
||||
minScore: req.body.result_min,
|
||||
maxScore: req.body.result_max
|
||||
});
|
||||
|
||||
let benchmark = await Benchmark.findByPk(req.body.result_benchmark);
|
||||
result.setBenchmark(benchmark);
|
||||
|
||||
let test = await Test.findByPk(req.body.result_test);
|
||||
result.setTest(test);
|
||||
|
||||
res.json('success');
|
||||
} catch (err) {
|
||||
res.status(500).json({
|
||||
error: 'Internal server error occurred while adding result.'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@@ -34,5 +34,6 @@ module.exports = function(app) {
|
||||
// API v1 routes
|
||||
app.get('/api/v1/benchmark/details', apiv1Routes.getBenchmarkDetails);
|
||||
app.get('/api/v1/result/list', apiv1Routes.getResultList);
|
||||
app.post('/api/v1/result/add', apiv1Routes.postResultAdd);
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user