mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 12:11:17 -05:00
Implement 5-day plan
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
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 { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||
|
||||
const corsHeaders = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
@@ -19,8 +20,15 @@ interface NotificationPayload {
|
||||
}
|
||||
|
||||
serve(async (req) => {
|
||||
const tracking = startRequest();
|
||||
|
||||
if (req.method === 'OPTIONS') {
|
||||
return new Response(null, { headers: corsHeaders });
|
||||
return new Response(null, {
|
||||
headers: {
|
||||
...corsHeaders,
|
||||
'X-Request-ID': tracking.requestId
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -42,7 +50,9 @@ serve(async (req) => {
|
||||
is_escalated
|
||||
} = payload;
|
||||
|
||||
console.log('Notifying moderators about submission via topic:', {
|
||||
edgeLogger.info('Notifying moderators about submission via topic', {
|
||||
action: 'notify_moderators',
|
||||
requestId: tracking.requestId,
|
||||
submission_id,
|
||||
submission_type,
|
||||
content_preview
|
||||
@@ -78,14 +88,25 @@ serve(async (req) => {
|
||||
.single();
|
||||
|
||||
if (workflowError || !workflow) {
|
||||
console.error('Error fetching workflow:', workflowError);
|
||||
const duration = endRequest(tracking);
|
||||
edgeLogger.error('Error fetching workflow', {
|
||||
action: 'notify_moderators',
|
||||
requestId: tracking.requestId,
|
||||
duration,
|
||||
error: workflowError
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: false,
|
||||
error: 'Workflow not found or not active'
|
||||
error: 'Workflow not found or not active',
|
||||
requestId: tracking.requestId
|
||||
}),
|
||||
{
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
||||
headers: {
|
||||
...corsHeaders,
|
||||
'Content-Type': 'application/json',
|
||||
'X-Request-ID': tracking.requestId
|
||||
},
|
||||
status: 500,
|
||||
}
|
||||
);
|
||||
@@ -112,6 +133,10 @@ serve(async (req) => {
|
||||
hasPhotos: has_photos,
|
||||
itemCount: item_count,
|
||||
isEscalated: is_escalated,
|
||||
|
||||
// Request tracking
|
||||
requestId: tracking.requestId,
|
||||
traceId: tracking.traceId,
|
||||
};
|
||||
|
||||
// Send ONE notification to the moderation-submissions topic
|
||||
@@ -125,21 +150,39 @@ serve(async (req) => {
|
||||
});
|
||||
|
||||
if (error) {
|
||||
console.error('Failed to notify moderators via topic:', error);
|
||||
const duration = endRequest(tracking);
|
||||
edgeLogger.error('Failed to notify moderators via topic', {
|
||||
action: 'notify_moderators',
|
||||
requestId: tracking.requestId,
|
||||
duration,
|
||||
error: error.message
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: false,
|
||||
error: 'Failed to send notification to topic',
|
||||
details: error.message
|
||||
details: error.message,
|
||||
requestId: tracking.requestId
|
||||
}),
|
||||
{
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
||||
headers: {
|
||||
...corsHeaders,
|
||||
'Content-Type': 'application/json',
|
||||
'X-Request-ID': tracking.requestId
|
||||
},
|
||||
status: 500,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
console.log('Successfully notified all moderators via topic:', data);
|
||||
const duration = endRequest(tracking);
|
||||
edgeLogger.info('Successfully notified all moderators via topic', {
|
||||
action: 'notify_moderators',
|
||||
requestId: tracking.requestId,
|
||||
traceId: tracking.traceId,
|
||||
duration,
|
||||
transactionId: data?.transactionId
|
||||
});
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
@@ -147,22 +190,38 @@ serve(async (req) => {
|
||||
message: 'Moderator notifications sent via topic',
|
||||
topicKey: 'moderation-submissions',
|
||||
transactionId: data?.transactionId,
|
||||
requestId: tracking.requestId,
|
||||
}),
|
||||
{
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
||||
headers: {
|
||||
...corsHeaders,
|
||||
'Content-Type': 'application/json',
|
||||
'X-Request-ID': tracking.requestId
|
||||
},
|
||||
status: 200,
|
||||
}
|
||||
);
|
||||
} catch (error: any) {
|
||||
console.error('Error in notify-moderators-submission:', error);
|
||||
const duration = endRequest(tracking);
|
||||
edgeLogger.error('Error in notify-moderators-submission', {
|
||||
action: 'notify_moderators',
|
||||
requestId: tracking.requestId,
|
||||
duration,
|
||||
error: error.message
|
||||
});
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: false,
|
||||
error: error.message,
|
||||
requestId: tracking.requestId,
|
||||
}),
|
||||
{
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
||||
headers: {
|
||||
...corsHeaders,
|
||||
'Content-Type': 'application/json',
|
||||
'X-Request-ID': tracking.requestId
|
||||
},
|
||||
status: 500,
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user