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