feat: Complete match notification service implementation
This commit is contained in:
@@ -4,9 +4,9 @@ const { createMatchRequestEmbed } = require('../utils/embedBuilders');
|
||||
const { createMatchActionRow } = require('../utils/componentBuilders');
|
||||
|
||||
class NotificationService {
|
||||
constructor(bot, supabaseService) {
|
||||
constructor(bot, supabase) {
|
||||
this.bot = bot;
|
||||
this.supabaseService = supabaseService;
|
||||
this.supabase = supabase;
|
||||
this.app = express();
|
||||
this.app.use(express.json());
|
||||
this.setupRoutes();
|
||||
@@ -49,12 +49,19 @@ class NotificationService {
|
||||
return res.status(400).json({ error: 'Invalid match data' });
|
||||
}
|
||||
|
||||
const subscriptions = await this.supabaseService.getSubscriptions();
|
||||
const relevantSubscriptions = subscriptions.filter(sub => sub.game_name === matchData.game_name);
|
||||
const { data: subscriptions, error } = await this.supabase
|
||||
.from('active_subscriptions')
|
||||
.select('*')
|
||||
.eq('game_name', matchData.game_name);
|
||||
|
||||
for (const subscription of relevantSubscriptions) {
|
||||
if (error) {
|
||||
console.error('Error fetching subscriptions:', error);
|
||||
return res.status(500).json({ error: 'Failed to fetch subscriptions' });
|
||||
}
|
||||
|
||||
for (const subscription of (subscriptions || [])) {
|
||||
try {
|
||||
const channel = await this.bot.client.channels.fetch(subscription.channel_id);
|
||||
const channel = await this.bot.client.channels.fetch(subscription.notification_channel_id);
|
||||
const embed = createMatchRequestEmbed(matchData);
|
||||
const actionRow = createMatchActionRow(matchData.game_name);
|
||||
|
||||
@@ -63,7 +70,7 @@ class NotificationService {
|
||||
components: [actionRow]
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`Error sending notification to channel ${subscription.channel_id}:`, error);
|
||||
console.error(`Error sending notification to channel ${subscription.notification_channel_id}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user