Merge branch 'feature/integrate-playwright' into feature/dashboard
This commit is contained in:
@@ -21,8 +21,14 @@ router.get('/', async function(req, res, next) {
|
||||
*/
|
||||
router.get('/:id', async function(req, res, next) {
|
||||
const siteId = req.params.id;
|
||||
let site = null;
|
||||
|
||||
const site = await siteModel.getById(siteId);
|
||||
try {
|
||||
site = await siteModel.getById(siteId);
|
||||
} catch (error) {
|
||||
console.error('Error fetching site by ID:', error);
|
||||
return res.status(400).send('Error fetching site: ' + error.message);
|
||||
}
|
||||
|
||||
if (!site) {
|
||||
return res.status(404).send('Site not found');
|
||||
@@ -31,22 +37,52 @@ 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: Implement validation for domain name format
|
||||
* // TODO: Implement error handling for duplicate domains
|
||||
* // TODO: Ability to add additional site properties (e.g., name, description)
|
||||
*/
|
||||
router.post('/add/:domain', function(req, res, next) {
|
||||
const domain = req.params.domain;
|
||||
|
||||
const newSite = siteModel.insert(domain);
|
||||
router.post('/add', async function(req, res, next) {
|
||||
const domain = req.body.domain;
|
||||
let newSite = null;
|
||||
|
||||
// insert method passes a lot of validation errors to the caller
|
||||
try {
|
||||
newSite = await siteModel.insert(domain);
|
||||
} catch (error) {
|
||||
console.error('Error creating site:', error);
|
||||
return res.status(400).send('Error creating site: ' + error.message);
|
||||
}
|
||||
|
||||
if (!newSite) {
|
||||
return res.status(400).send('Error creating site');
|
||||
res.status(400).send('Error creating site');
|
||||
} else {
|
||||
res.status(201).json(newSite);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user