Browse Source

Refactor: Improve edge function logging

gpt-engineer-app[bot] 1 month ago
parent
commit
0ff7c13657

+ 11 - 1
supabase/functions/purge-articles/index.ts

@@ -1,3 +1,10 @@
+/**
+ * Purge Articles Edge Function
+ * Version: 2.0
+ * Last updated: 2025-01-20
+ * Purpose: Automatically purge old articles and send email reports to admins
+ */
+
 import { serve } from "https://deno.land/std@0.177.0/http/server.ts";
 import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
 
@@ -7,13 +14,16 @@ const corsHeaders = {
 };
 
 serve(async (req) => {
+  console.log('🚀 Purge-articles function invoked at', new Date().toISOString());
+  
   // Handle CORS preflight requests
   if (req.method === 'OPTIONS') {
+    console.log('📝 CORS preflight request handled');
     return new Response(null, { headers: corsHeaders });
   }
 
   try {
-    console.log('Starting automatic article purge...');
+    console.log('🗑️ Starting automatic article purge...');
 
     // Create Supabase client
     const supabaseUrl = Deno.env.get('SUPABASE_URL')!;

+ 13 - 3
supabase/functions/send-purge-report/index.ts

@@ -1,3 +1,10 @@
+/**
+ * Send Purge Report Edge Function
+ * Version: 2.0
+ * Last updated: 2025-01-20
+ * Purpose: Send email reports about article purge operations to admin users
+ */
+
 import { serve } from "https://deno.land/std@0.177.0/http/server.ts";
 import { Resend } from "npm:resend@2.0.0";
 
@@ -15,17 +22,20 @@ interface PurgeReportRequest {
 }
 
 const handler = async (req: Request): Promise<Response> => {
+  console.log('📧 Send-purge-report function invoked at', new Date().toISOString());
+  
   // Handle CORS preflight requests
   if (req.method === "OPTIONS") {
+    console.log('📝 CORS preflight request handled');
     return new Response(null, { headers: corsHeaders });
   }
 
   try {
     const { deletedCount, adminEmails, timestamp }: PurgeReportRequest = await req.json();
 
-    console.log('Sending purge report email...');
-    console.log('Deleted count:', deletedCount);
-    console.log('Admin emails:', adminEmails);
+    console.log('📨 Preparing to send purge report email...');
+    console.log(`📊 Report details: ${deletedCount} articles deleted, ${adminEmails?.length || 0} admins to notify`);
+    console.log('📧 Admin emails:', adminEmails);
 
     const emailDate = new Date(timestamp);
     const formattedDate = emailDate.toLocaleDateString('fr-FR', {