subscribe update
This commit is contained in:
58
src/services/SupabaseService.js
Normal file
58
src/services/SupabaseService.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const { createClient } = require('@supabase/supabase-js');
|
||||
|
||||
class SupabaseService {
|
||||
constructor() {
|
||||
const supabaseUrl = process.env.SUPABASE_URL;
|
||||
const supabaseKey = process.env.SUPABASE_KEY;
|
||||
|
||||
if (!supabaseUrl || !supabaseKey) {
|
||||
console.error('Supabase URL or key is missing. Please check your .env file.');
|
||||
this.supabase = null;
|
||||
} else {
|
||||
this.supabase = createClient(supabaseUrl, supabaseKey);
|
||||
}
|
||||
}
|
||||
|
||||
async getSubscriptions(guildId) {
|
||||
if (!this.supabase) {
|
||||
console.error('Supabase client is not initialized.');
|
||||
return [];
|
||||
}
|
||||
const { data, error } = await this.supabase
|
||||
.from('subscriptions')
|
||||
.select('*')
|
||||
.eq('guild_id', guildId);
|
||||
|
||||
if (error) throw error;
|
||||
return data;
|
||||
}
|
||||
|
||||
async addSubscription(guildId, gameName, channelId) {
|
||||
if (!this.supabase) {
|
||||
console.error('Supabase client is not initialized.');
|
||||
return null;
|
||||
}
|
||||
const { data, error } = await this.supabase
|
||||
.from('subscriptions')
|
||||
.insert({ guild_id: guildId, game_name: gameName, channel_id: channelId });
|
||||
|
||||
if (error) throw error;
|
||||
return data;
|
||||
}
|
||||
|
||||
async removeSubscription(guildId, gameName) {
|
||||
if (!this.supabase) {
|
||||
console.error('Supabase client is not initialized.');
|
||||
return null;
|
||||
}
|
||||
const { data, error } = await this.supabase
|
||||
.from('subscriptions')
|
||||
.delete()
|
||||
.match({ guild_id: guildId, game_name: gameName });
|
||||
|
||||
if (error) throw error;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SupabaseService;
|
||||
Reference in New Issue
Block a user