Remove name from insert method - this is removed from db schema
This commit is contained in:
@@ -17,9 +17,9 @@ class SiteModel {
|
|||||||
*
|
*
|
||||||
* @returns {Promise<Object>} - The result of the insert operation.
|
* @returns {Promise<Object>} - The result of the insert operation.
|
||||||
*/
|
*/
|
||||||
async insert(name, domainName) {
|
async insert(domainName) {
|
||||||
// validate inputs
|
// validate inputs
|
||||||
if (!name || !domainName) {
|
if (!domainName) {
|
||||||
throw new Error('Name and domain name are required to insert a site.');
|
throw new Error('Name and domain name are required to insert a site.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +34,6 @@ class SiteModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { data, error } = await supabase.from(SiteModel.tableName).insert({
|
const { data, error } = await supabase.from(SiteModel.tableName).insert({
|
||||||
name: name,
|
|
||||||
domain_name: domainName,
|
domain_name: domainName,
|
||||||
}).select();
|
}).select();
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,29 @@ 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', async function(req, res, next) {
|
||||||
|
const domainName = req.params.domain;
|
||||||
|
let site = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
site = 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!site || site.length === 0) {
|
||||||
|
return res.status(404).send('Site not found');
|
||||||
|
} else {
|
||||||
|
res.json(site[0]); // Return the first match
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POST create a new site.
|
* POST create a new site.
|
||||||
*
|
*
|
||||||
@@ -50,7 +73,7 @@ router.post('/add', async function(req, res, next) {
|
|||||||
|
|
||||||
// insert method passes a lot of validation errors to the caller
|
// insert method passes a lot of validation errors to the caller
|
||||||
try {
|
try {
|
||||||
newSite = await siteModel.insert(domain, domain);
|
newSite = await siteModel.insert(domain);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating site:', error);
|
console.error('Error creating site:', error);
|
||||||
return res.status(400).send('Error creating site: ' + error.message);
|
return res.status(400).send('Error creating site: ' + error.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user