Refactor routes and views for improved clarity and functionality

- Commented out console log in the home route to reduce clutter in logs.
- Updated formatting and consistency in the sites route, including removing unused domain fetching functionality.
- Added form action to the add-form view for submitting new sites, ensuring the input field is properly named for backend processing.
This commit is contained in:
Keith Solomon
2025-05-25 17:53:13 -05:00
parent 88a6969f2f
commit 4020b33293
5 changed files with 29 additions and 1526 deletions

View File

@@ -6,7 +6,7 @@ const sitesModel = new SiteModel();
/* GET home page. */
router.get('/', async function(req, res, next) {
const sites = await sitesModel.getAll();
console.log('Sites:', sites);
// console.log('Sites:', sites);
res.render('index', { title: 'Playwright Testing Dashboard', sites: sites });
});

View File

@@ -5,10 +5,10 @@ const siteModel = new SiteModel();
/**
* GET sites listing.
*
*
* Returns a list of all sites in JSON format.
*/
router.get('/', async function(req, res, next) {
router.get('/', async function (req, res, next) {
const sites = await siteModel.getAll();
res.json(sites);
@@ -16,10 +16,10 @@ router.get('/', async function(req, res, next) {
/**
* GET site by ID.
*
*
* Returns a specific site by its ID in JSON format.
*/
router.get('/:id', async function(req, res, next) {
router.get('/:id', async function (req, res, next) {
const siteId = req.params.id;
let site = null;
@@ -37,39 +37,14 @@ router.get('/:id', async function(req, res, next) {
}
});
/**
* GET site by domain name.
*
* Returns a specific site by its domain name in JSON format.
*/
router.get('/domain/:domain', async function(req, res, next) {
const domainName = req.params.domain;
let sites = null;
try {
sites = await siteModel.getByDomainName(domainName);
} catch (error) {
console.error('Error fetching site by domain name:', error);
return res.status(400).send('Error fetching site: ' + error.message);
}
console.log('Site found:', sites);
if (!sites || sites.length === 0) {
return res.status(404).send('Site not found');
} else {
res.json(sites[0]); // Return the first match
}
});
/**
* POST create a new site.
*
*
* Creates a new site with the provided domain name.
*
*
* // TODO: Ability to add additional site properties (e.g., name, description)
*/
router.post('/add', async function(req, res, next) {
router.post('/add', async function (req, res, next) {
const domain = req.body.domain;
let newSite = null;
@@ -90,7 +65,7 @@ router.post('/add', async function(req, res, next) {
/**
* PUT update an existing site.
*
*
* Updates an existing site with the provided ID and new data.
*/
@@ -103,4 +78,4 @@ router.post('/add', async function(req, res, next) {
// TODO: Implement delete functionality
module.exports = router;
module.exports = router;