Added license view and edit functions
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@ -20,3 +20,55 @@ exports.postAdd = async function(req, res) {
|
||||
|
||||
res.redirect('/');
|
||||
};
|
||||
|
||||
// GET - /license/{id}
|
||||
exports.getLicense = async function(req, res) {
|
||||
const license = await License.findAll({
|
||||
where: {
|
||||
id: req.params.id,
|
||||
},
|
||||
});
|
||||
|
||||
res.render('license/view.twig', {
|
||||
license: license[0],
|
||||
});
|
||||
};
|
||||
|
||||
// GET - /license/{id}/edit
|
||||
exports.getEdit = async function(req, res) {
|
||||
const license = await License.findAll({
|
||||
where: {
|
||||
id: req.params.id,
|
||||
},
|
||||
});
|
||||
|
||||
res.render('license/edit.twig', {
|
||||
license: license[0],
|
||||
});
|
||||
};
|
||||
|
||||
// POST - /license/{id}/edit
|
||||
exports.postEdit = async function(req, res) {
|
||||
// fetch license from DB
|
||||
const licenseSearch = await License.findAll({
|
||||
where: {
|
||||
id: req.params.id,
|
||||
},
|
||||
});
|
||||
|
||||
// retrieve the license record from the array for ease of use
|
||||
const license = licenseSearch[0];
|
||||
|
||||
// update license attributes
|
||||
license.name = req.body.license_name;
|
||||
license.key = req.body.license_key;
|
||||
license.manufacturer = req.body.license_manufacturer;
|
||||
license.purchasedFrom = req.body.license_purchase_from;
|
||||
license.purchasedAt = req.body.license_purchase_date;
|
||||
|
||||
// save attribute changes
|
||||
await license.save();
|
||||
|
||||
// redirect user to license page
|
||||
res.redirect('/license/' + license.id);
|
||||
};
|
||||
|
Reference in New Issue
Block a user