Added ability to load benchmark results when viewing a test
This commit is contained in:
@ -26,8 +26,4 @@ Benchmark.hasMany(Result);
|
||||
Result.belongsTo(Test);
|
||||
Test.hasMany(Result);
|
||||
|
||||
// Result/Hardware many-to-one
|
||||
Result.belongsTo(Hardware);
|
||||
Hardware.hasMany(Result);
|
||||
|
||||
module.exports = sequelize;
|
||||
|
39
src/routes/api_v1.js
Normal file
39
src/routes/api_v1.js
Normal file
@ -0,0 +1,39 @@
|
||||
const Benchmark = require('../models').models.Benchmark;
|
||||
const Result = require('../models').models.Result;
|
||||
|
||||
// GET /api/v1/benchmark/details
|
||||
exports.getBenchmarkDetails = async function(req, res) {
|
||||
try {
|
||||
const benchmark = await Benchmark.findByPk(req.query.benchmark_id);
|
||||
|
||||
if (!benchmark) {
|
||||
return res.status(404).json({
|
||||
error: 'Benchmark not found.'
|
||||
})
|
||||
}
|
||||
|
||||
res.json(benchmark);
|
||||
} catch (err) {
|
||||
res.status(500).json({
|
||||
error: 'Internal server error occurred while fetching benchmark details.'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// GET /api/v1/result/list - list of results for a test
|
||||
exports.getResultList = async function(req, res) {
|
||||
try {
|
||||
var results = await Result.findAll({
|
||||
where: {
|
||||
TestId: req.query.test_id,
|
||||
BenchmarkId: req.query.benchmark_id
|
||||
}
|
||||
});
|
||||
|
||||
res.json(results);
|
||||
} catch (err) {
|
||||
res.status(500).json({
|
||||
error: 'Internal server error occurred while fetching benchmark results.'
|
||||
});
|
||||
}
|
||||
};
|
@ -3,6 +3,7 @@ const topRoutes = require('./toplevel');
|
||||
const testRoutes = require('./test');
|
||||
const hardwareRoutes = require('./hardware');
|
||||
const benchmarkRoutes = require('./benchmark');
|
||||
const apiv1Routes = require('./api_v1');
|
||||
|
||||
module.exports = function(app) {
|
||||
|
||||
@ -30,4 +31,8 @@ module.exports = function(app) {
|
||||
app.post('/test/add', testRoutes.postAdd);
|
||||
app.get('/test/:test_id', testRoutes.getView);
|
||||
|
||||
// API v1 routes
|
||||
app.get('/api/v1/benchmark/details', apiv1Routes.getBenchmarkDetails);
|
||||
app.get('/api/v1/result/list', apiv1Routes.getResultList);
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user