Added ability to load benchmark results when viewing a test

This commit is contained in:
2025-06-23 18:05:28 -04:00
parent a83f7e3b0b
commit 175bfa0dfd
5 changed files with 98 additions and 12 deletions

View File

@ -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
View 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.'
});
}
};

View File

@ -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);
};