Added benchmark and hardware models; added routes and views for hardware

This commit is contained in:
2023-11-26 12:54:09 -05:00
parent e5602e660d
commit 2f016d3062
10 changed files with 181 additions and 2 deletions

21
src/models/benchmark.js Normal file
View File

@ -0,0 +1,21 @@
const { Sequelize } = require("sequelize");
module.exports = (sequelize) => {
const Benchmark = sequelize.define('Benchmark', {
name: {
type: Sequelize.STRING,
null: false,
},
description: {
type: Sequelize.TEXT,
},
scoring: {
type: Sequelize.STRING,
null: false,
},
},
{
tableName: 'benchmarks'
});
return Benchmark;
};

18
src/models/hardware.js Normal file
View File

@ -0,0 +1,18 @@
const { Sequelize } = require("sequelize");
module.exports = (sequelize) => {
const Hardware = sequelize.define('Hardware', {
name: {
type: Sequelize.STRING,
null: false,
},
type: {
type: Sequelize.STRING,
null: false,
},
},
{
tableName: 'hardware'
});
return Hardware;
};

View File

@ -6,5 +6,7 @@ const sequelize = new Sequelize({
});
const Project = require('./project')(sequelize);
const Hardware = require('./hardware')(sequelize);
const Benchmark = require('./benchmark')(sequelize);
module.exports = sequelize;

View File

@ -10,6 +10,8 @@ module.exports = (sequelize) => {
type: Sequelize.TEXT,
},
},
{});
{
tableName: 'projects'
});
return Project;
};

41
src/routes/hardware.js Normal file
View File

@ -0,0 +1,41 @@
const Hardware = require('../models').models.Hardware;
// GET /hardware - redirects to project list
exports.getIndex = async function(req, res) {
res.redirect('/hardware/list');
};
// GET /hardware/list - list of hardware
exports.getList = async function(req, res) {
var hardware = await Hardware.findAll();
res.render('hardware/list', {
hardware: hardware
});
};
// GET /hardware/:hardware_id - view information about a piece of hardware
exports.getView = async function(req, res) {
var hardware = await Hardware.findAll({
where: {
id: req.params.hardware_id
}
});
res.render('hardware/view', {
hardware: hardware[0]
});
};
// GET /hardware/add - add a new hardware
exports.getAdd = async function(req, res) {
res.render('hardware/add');
};
// POST /hardware/add - add the hardware to the database
exports.postAdd = async function(req, res) {
var hardware = await Hardware.create({
name: req.body.hardware_name,
type: req.body.hardware_type
});
res.redirect('/hardware');
};