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');
|
const { createMatchActionRow } = require('../utils/componentBuilders');
|
||||||
|
|
||||||
class NotificationService {
|
class NotificationService {
|
||||||
constructor(bot, supabaseService) {
|
constructor(bot, supabase) {
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
this.supabaseService = supabaseService;
|
this.supabase = supabase;
|
||||||
this.app = express();
|
this.app = express();
|
||||||
this.app.use(express.json());
|
this.app.use(express.json());
|
||||||
this.setupRoutes();
|
this.setupRoutes();
|
||||||
@@ -49,12 +49,19 @@ class NotificationService {
|
|||||||
return res.status(400).json({ error: 'Invalid match data' });
|
return res.status(400).json({ error: 'Invalid match data' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const subscriptions = await this.supabaseService.getSubscriptions();
|
const { data: subscriptions, error } = await this.supabase
|
||||||
const relevantSubscriptions = subscriptions.filter(sub => sub.game_name === matchData.game_name);
|
.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 {
|
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 embed = createMatchRequestEmbed(matchData);
|
||||||
const actionRow = createMatchActionRow(matchData.game_name);
|
const actionRow = createMatchActionRow(matchData.game_name);
|
||||||
|
|
||||||
@@ -63,7 +70,7 @@ class NotificationService {
|
|||||||
components: [actionRow]
|
components: [actionRow]
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} 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