build a model to interact with sites table
This commit is contained in:
34
models/SiteModel.js
Normal file
34
models/SiteModel.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Model for managing sites table in the database.
|
||||
*/
|
||||
|
||||
const { supabase } = require('../auth');
|
||||
|
||||
class SiteModel {
|
||||
|
||||
static tableName = 'sites';
|
||||
|
||||
/**
|
||||
* Inserts a new site into the database.
|
||||
*
|
||||
* @param {string} name - The name of the site.
|
||||
* @param {string} domainName - The domain name of the site.
|
||||
*
|
||||
* @returns {Promise<Object>} - The result of the insert operation.
|
||||
*/
|
||||
async insertSite(name, domainName) {
|
||||
const { error } = await supabase.from(siteModel.tableName).insert({
|
||||
name: name,
|
||||
domain_name: domainName,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
console.error('Error inserting site:', error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SiteModel;
|
||||
Reference in New Issue
Block a user