mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 08:11:12 -05:00
feat: Implement notification edge functions
This commit is contained in:
@@ -448,6 +448,125 @@ class NotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger a system announcement to all users via the "users" topic
|
||||
* Requires admin or superuser role
|
||||
*/
|
||||
async sendSystemAnnouncement(payload: {
|
||||
title: string;
|
||||
message: string;
|
||||
severity: 'info' | 'warning' | 'critical';
|
||||
actionUrl?: string;
|
||||
}): Promise<{ success: boolean; error?: string; announcementId?: string }> {
|
||||
try {
|
||||
const novuEnabled = await this.isNovuEnabled();
|
||||
if (!novuEnabled) {
|
||||
logger.warn('Novu not configured, skipping system announcement', {
|
||||
action: 'send_system_announcement',
|
||||
title: payload.title
|
||||
});
|
||||
return { success: false, error: 'Novu not configured' };
|
||||
}
|
||||
|
||||
const { data, error, requestId } = await invokeWithTracking(
|
||||
'notify-system-announcement',
|
||||
payload
|
||||
);
|
||||
|
||||
if (error) {
|
||||
logger.error('Failed to send system announcement', {
|
||||
action: 'send_system_announcement',
|
||||
title: payload.title,
|
||||
requestId,
|
||||
error: error.message
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
|
||||
logger.info('System announcement sent successfully', {
|
||||
action: 'send_system_announcement',
|
||||
title: payload.title,
|
||||
announcementId: data?.announcementId,
|
||||
requestId
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
announcementId: data?.announcementId
|
||||
};
|
||||
} catch (error: unknown) {
|
||||
logger.error('Error sending system announcement', {
|
||||
action: 'send_system_announcement',
|
||||
title: payload.title,
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
});
|
||||
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to send system announcement'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify moderators about a new report via the "moderation-reports" topic
|
||||
*/
|
||||
async notifyModeratorsReport(payload: {
|
||||
reportId: string;
|
||||
reportType: string;
|
||||
reportedEntityType: string;
|
||||
reportedEntityId: string;
|
||||
reporterName: string;
|
||||
reason: string;
|
||||
entityPreview: string;
|
||||
reportedAt: string;
|
||||
}): Promise<{ success: boolean; error?: string }> {
|
||||
try {
|
||||
const novuEnabled = await this.isNovuEnabled();
|
||||
if (!novuEnabled) {
|
||||
logger.warn('Novu not configured, skipping report notification', {
|
||||
action: 'notify_moderators_report',
|
||||
reportId: payload.reportId
|
||||
});
|
||||
return { success: false, error: 'Novu not configured' };
|
||||
}
|
||||
|
||||
const { data, error, requestId } = await invokeWithTracking(
|
||||
'notify-moderators-report',
|
||||
payload
|
||||
);
|
||||
|
||||
if (error) {
|
||||
logger.error('Failed to notify moderators about report', {
|
||||
action: 'notify_moderators_report',
|
||||
reportId: payload.reportId,
|
||||
requestId,
|
||||
error: error.message
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
|
||||
logger.info('Moderators notified about report successfully', {
|
||||
action: 'notify_moderators_report',
|
||||
reportId: payload.reportId,
|
||||
requestId
|
||||
});
|
||||
|
||||
return { success: true };
|
||||
} catch (error: unknown) {
|
||||
logger.error('Error notifying moderators about report', {
|
||||
action: 'notify_moderators_report',
|
||||
reportId: payload.reportId,
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
});
|
||||
|
||||
return {
|
||||
success: false,
|
||||
error: 'Failed to notify moderators about report'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if notifications are enabled
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user