mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 23:11:13 -05:00
Refactor: Continue implementation plan
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
||||
import { Novu } from "npm:@novu/api@1.6.0";
|
||||
import { startRequest, endRequest } from "../_shared/logger.ts";
|
||||
|
||||
const corsHeaders = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, x-request-id',
|
||||
};
|
||||
|
||||
serve(async (req) => {
|
||||
@@ -11,6 +12,8 @@ serve(async (req) => {
|
||||
return new Response(null, { headers: corsHeaders });
|
||||
}
|
||||
|
||||
const tracking = startRequest('update-novu-subscriber');
|
||||
|
||||
try {
|
||||
const novuApiKey = Deno.env.get('NOVU_API_KEY');
|
||||
|
||||
@@ -32,7 +35,7 @@ serve(async (req) => {
|
||||
data?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
console.log('Updating Novu subscriber:', { subscriberId, email, firstName });
|
||||
console.log('Updating Novu subscriber:', { subscriberId, email, firstName, requestId: tracking.requestId });
|
||||
|
||||
const subscriber = await novu.subscribers.update(subscriberId, {
|
||||
email,
|
||||
@@ -45,13 +48,20 @@ serve(async (req) => {
|
||||
|
||||
console.log('Subscriber updated successfully:', subscriber.data);
|
||||
|
||||
endRequest(tracking, 200);
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: true,
|
||||
subscriberId: subscriber.data._id,
|
||||
requestId: tracking.requestId
|
||||
}),
|
||||
{
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
||||
headers: {
|
||||
...corsHeaders,
|
||||
'Content-Type': 'application/json',
|
||||
'X-Request-ID': tracking.requestId
|
||||
},
|
||||
status: 200,
|
||||
}
|
||||
);
|
||||
@@ -59,13 +69,20 @@ serve(async (req) => {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
||||
console.error('Error updating Novu subscriber:', errorMessage);
|
||||
|
||||
endRequest(tracking, 500, errorMessage);
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: false,
|
||||
error: errorMessage,
|
||||
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