Fix insert request
This commit is contained in:
@@ -17,10 +17,10 @@ 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(name, domainName) {
|
||||||
const { error } = await supabase.from(siteModel.tableName).insert({
|
const { data, error } = await supabase.from(SiteModel.tableName).insert({
|
||||||
name: name,
|
name: name,
|
||||||
domain_name: domainName,
|
domain_name: domainName,
|
||||||
});
|
}).select();
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('Error inserting site:', error);
|
console.error('Error inserting site:', error);
|
||||||
|
|||||||
@@ -40,13 +40,15 @@ router.get('/:id', async function(req, res, next) {
|
|||||||
* // TODO: Implement error handling for duplicate domains
|
* // TODO: Implement error handling for duplicate domains
|
||||||
* // TODO: Ability to add additional site properties (e.g., name, description)
|
* // TODO: Ability to add additional site properties (e.g., name, description)
|
||||||
*/
|
*/
|
||||||
router.post('/add/:domain', function(req, res, next) {
|
router.post('/add', async function(req, res, next) {
|
||||||
const domain = req.params.domain;
|
const domain = req.body.domain;
|
||||||
|
|
||||||
const newSite = siteModel.insert(domain);
|
const newSite = await siteModel.insert(domain, domain);
|
||||||
|
|
||||||
|
console.log('New site created:', newSite);
|
||||||
|
|
||||||
if (!newSite) {
|
if (!newSite) {
|
||||||
return res.status(400).send('Error creating site');
|
res.status(400).send('Error creating site');
|
||||||
} else {
|
} else {
|
||||||
res.status(201).json(newSite);
|
res.status(201).json(newSite);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user