Fix remaining console statements

This commit is contained in:
gpt-engineer-app[bot]
2025-11-03 19:24:38 +00:00
parent ba6bb8a317
commit 99ceacfe0c
12 changed files with 225 additions and 118 deletions

View File

@@ -1,6 +1,7 @@
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
import { Novu } from "npm:@novu/api@1.6.0";
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
const corsHeaders = {
'Access-Control-Allow-Origin': '*',
@@ -12,10 +13,6 @@ const TOPICS = {
MODERATION_REPORTS: 'moderation-reports',
} as const;
// Simple request tracking
const startRequest = () => ({ requestId: crypto.randomUUID(), start: Date.now() });
const endRequest = (tracking: { start: number }) => Date.now() - tracking.start;
serve(async (req) => {
const tracking = startRequest();
@@ -35,7 +32,10 @@ serve(async (req) => {
const novu = new Novu({ secretKey: novuApiKey });
const supabase = createClient(supabaseUrl, supabaseServiceKey);
console.log('Starting moderator sync to Novu topics...');
edgeLogger.info('Starting moderator sync to Novu topics', {
requestId: tracking.requestId,
action: 'sync_moderators'
});
// Get all moderators, admins, and superusers
const { data: moderatorRoles, error: rolesError } = await supabase
@@ -50,7 +50,10 @@ serve(async (req) => {
// Get unique user IDs (a user might have multiple moderator-level roles)
const uniqueUserIds = [...new Set(moderatorRoles.map(r => r.user_id))];
console.log(`Found ${uniqueUserIds.length} unique moderators to sync`);
edgeLogger.info('Found unique moderators to sync', {
requestId: tracking.requestId,
count: uniqueUserIds.length
});
const topics = [TOPICS.MODERATION_SUBMISSIONS, TOPICS.MODERATION_REPORTS];
const results = {
@@ -62,11 +65,15 @@ serve(async (req) => {
try {
// Ensure topic exists (Novu will create it if it doesn't)
await novu.topics.create({ key: topicKey, name: topicKey });
console.log(`Topic ${topicKey} ready`);
edgeLogger.info('Topic ready', { requestId: tracking.requestId, topicKey });
} catch (error: any) {
// Topic might already exist, which is fine
if (!error.message?.includes('already exists')) {
console.warn(`Note about topic ${topicKey}:`, error.message);
edgeLogger.warn('Note about topic', {
requestId: tracking.requestId,
topicKey,
error: error.message
});
}
}
@@ -83,10 +90,19 @@ serve(async (req) => {
subscribers: batch,
});
successCount += batch.length;
console.log(`Added batch of ${batch.length} users to ${topicKey}`);
edgeLogger.info('Added batch of users to topic', {
requestId: tracking.requestId,
topicKey,
batchSize: batch.length
});
} catch (error: any) {
errorCount += batch.length;
console.error(`Error adding batch to ${topicKey}:`, error.message);
edgeLogger.error('Error adding batch to topic', {
requestId: tracking.requestId,
topicKey,
batchSize: batch.length,
error: error.message
});
}
}
@@ -98,7 +114,11 @@ serve(async (req) => {
}
const duration = endRequest(tracking);
console.log('Sync completed:', results, { requestId: tracking.requestId, duration });
edgeLogger.info('Sync completed', {
requestId: tracking.requestId,
duration,
results
});
return new Response(
JSON.stringify({
@@ -118,7 +138,11 @@ serve(async (req) => {
);
} catch (error: any) {
const duration = endRequest(tracking);
console.error('Error syncing moderators to topics:', error, { requestId: tracking.requestId, duration });
edgeLogger.error('Error syncing moderators to topics', {
requestId: tracking.requestId,
duration,
error: error.message
});
return new Response(
JSON.stringify({