mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 09:51:13 -05:00
Fix edge function logging and types
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
||||
import { Novu } from "npm:@novu/api@1.6.0";
|
||||
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': '*',
|
||||
@@ -8,6 +9,8 @@ const corsHeaders = {
|
||||
};
|
||||
|
||||
serve(async (req) => {
|
||||
const tracking = startRequest('update-novu-preferences');
|
||||
|
||||
if (req.method === 'OPTIONS') {
|
||||
return new Response(null, { headers: corsHeaders });
|
||||
}
|
||||
@@ -29,7 +32,7 @@ serve(async (req) => {
|
||||
|
||||
const { userId, preferences } = await req.json();
|
||||
|
||||
console.log('Updating preferences for user:', userId);
|
||||
edgeLogger.info('Updating preferences for user', { userId, requestId: tracking.requestId });
|
||||
|
||||
// Validate input
|
||||
if (!userId) {
|
||||
@@ -94,7 +97,11 @@ serve(async (req) => {
|
||||
);
|
||||
results.push({ channel: channelType, success: true });
|
||||
} catch (channelError: any) {
|
||||
console.error(`Failed to update ${channelType} preference:`, channelError.message);
|
||||
edgeLogger.error('Failed to update channel preference', {
|
||||
channel: channelType,
|
||||
error: channelError.message,
|
||||
requestId: tracking.requestId
|
||||
});
|
||||
results.push({
|
||||
channel: channelType,
|
||||
success: false,
|
||||
@@ -109,7 +116,10 @@ serve(async (req) => {
|
||||
const allSucceeded = failedChannels.length === 0;
|
||||
|
||||
if (!allSucceeded) {
|
||||
console.warn(`Some channel preferences failed to update:`, failedChannels);
|
||||
edgeLogger.warn('Some channel preferences failed to update', {
|
||||
failedChannels: failedChannels.map(c => c.channel),
|
||||
requestId: tracking.requestId
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: false,
|
||||
@@ -124,7 +134,11 @@ serve(async (req) => {
|
||||
);
|
||||
}
|
||||
|
||||
console.log('All preferences updated successfully');
|
||||
const duration = endRequest(tracking);
|
||||
edgeLogger.info('All preferences updated successfully', {
|
||||
requestId: tracking.requestId,
|
||||
duration
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: true,
|
||||
@@ -136,7 +150,12 @@ serve(async (req) => {
|
||||
}
|
||||
);
|
||||
} catch (error: any) {
|
||||
console.error('Error updating Novu preferences:', error);
|
||||
const duration = endRequest(tracking);
|
||||
edgeLogger.error('Error updating Novu preferences', {
|
||||
error: error.message,
|
||||
requestId: tracking.requestId,
|
||||
duration
|
||||
});
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
|
||||
Reference in New Issue
Block a user