diff --git a/assets/scripts/test.coffee b/assets/scripts/test.coffee
index 2f93411..130a3d1 100644
--- a/assets/scripts/test.coffee
+++ b/assets/scripts/test.coffee
@@ -1,5 +1,18 @@
testId = $('#results-table').data('test-id')
+$ ->
+ $('#test-result-form').on 'submit', (e) ->
+ e.preventDefault()
+
+ form = $(this)
+ formData = $(this).serialize()
+ benchmarkId = $(this).find('[name="result_benchmark"]').val()
+
+ $.post '/api/v1/result/add', formData, (response) ->
+ if response == 'success'
+ fetchTestBenchmarkResults(testId, benchmarkId)
+ form[0].reset()
+
fetchTestBenchmarkResults = (testId, benchmarkId) ->
try
benchmarkSearchParams = new URLSearchParams
@@ -18,12 +31,14 @@ fetchTestBenchmarkResults = (testId, benchmarkId) ->
max_total = 0
for result in resultData
- avg_total += result.avg_score
- min_total += result.min_score
- max_total += result.max_score
+ avg_total += result.avgScore
+ min_total += result.minScore
+ max_total += result.maxScore
tableRow = $("#results-table tr[data-benchmark-id=#{benchmarkId}]")
+ tableRow.empty()
+
tableRow.append('
' + benchmarkData.name + ' | ')
tableRow.append('' + benchmarkData.scoring + ' | ')
tableRow.append('' + resultData.length + ' | ')
diff --git a/src/routes/api_v1.js b/src/routes/api_v1.js
index 5f5b16a..c85305e 100644
--- a/src/routes/api_v1.js
+++ b/src/routes/api_v1.js
@@ -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.'
+ });
+ }
+};
diff --git a/src/routes/index.js b/src/routes/index.js
index f5632f9..f417689 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -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);
};
diff --git a/views/test/view.twig b/views/test/view.twig
index ab25d24..c029b55 100644
--- a/views/test/view.twig
+++ b/views/test/view.twig
@@ -10,7 +10,7 @@