mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 11:11:13 -05:00
Refactor: Continue implementation plan
This commit is contained in:
@@ -21,7 +21,7 @@ import { getErrorMessage } from './errorHandler';
|
||||
*/
|
||||
export async function invokeWithTracking<T = any>(
|
||||
functionName: string,
|
||||
payload: Record<string, unknown> = {},
|
||||
payload: any = {},
|
||||
userId?: string,
|
||||
parentRequestId?: string,
|
||||
traceId?: string
|
||||
@@ -71,7 +71,7 @@ export async function invokeWithTracking<T = any>(
|
||||
export async function invokeBatchWithTracking<T = any>(
|
||||
operations: Array<{
|
||||
functionName: string;
|
||||
payload: Record<string, unknown>;
|
||||
payload: any;
|
||||
}>,
|
||||
userId?: string
|
||||
): Promise<
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { supabase } from "@/integrations/supabase/client";
|
||||
import { invokeWithTracking } from "@/lib/edgeFunctionTracking";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { AppError } from "@/lib/errorHandler";
|
||||
import { z } from "zod";
|
||||
@@ -53,14 +54,16 @@ class NotificationService {
|
||||
return { success: false, error: 'Novu not configured' };
|
||||
}
|
||||
|
||||
const { data, error } = await supabase.functions.invoke('update-novu-subscriber', {
|
||||
body: validated,
|
||||
});
|
||||
const { data, error, requestId } = await invokeWithTracking(
|
||||
'update-novu-subscriber',
|
||||
validated
|
||||
);
|
||||
|
||||
if (error) {
|
||||
logger.error('Edge function error updating Novu subscriber', {
|
||||
action: 'update_novu_subscriber',
|
||||
userId: validated.subscriberId,
|
||||
requestId,
|
||||
error: error.message
|
||||
});
|
||||
throw new AppError(
|
||||
@@ -72,7 +75,8 @@ class NotificationService {
|
||||
|
||||
logger.info('Novu subscriber updated successfully', {
|
||||
action: 'update_novu_subscriber',
|
||||
userId: validated.subscriberId
|
||||
userId: validated.subscriberId,
|
||||
requestId
|
||||
});
|
||||
|
||||
return { success: true };
|
||||
@@ -107,14 +111,16 @@ class NotificationService {
|
||||
return { success: false, error: 'Novu not configured' };
|
||||
}
|
||||
|
||||
const { data, error } = await supabase.functions.invoke('create-novu-subscriber', {
|
||||
body: validated,
|
||||
});
|
||||
const { data, error, requestId } = await invokeWithTracking(
|
||||
'create-novu-subscriber',
|
||||
validated
|
||||
);
|
||||
|
||||
if (error) {
|
||||
logger.error('Edge function error creating Novu subscriber', {
|
||||
action: 'create_novu_subscriber',
|
||||
userId: validated.subscriberId,
|
||||
requestId,
|
||||
error: error.message
|
||||
});
|
||||
throw new AppError(
|
||||
@@ -151,7 +157,8 @@ class NotificationService {
|
||||
|
||||
logger.info('Novu subscriber created successfully', {
|
||||
action: 'create_novu_subscriber',
|
||||
userId: validated.subscriberId
|
||||
userId: validated.subscriberId,
|
||||
requestId
|
||||
});
|
||||
|
||||
return { success: true };
|
||||
@@ -191,17 +198,19 @@ class NotificationService {
|
||||
|
||||
// Update Novu preferences if enabled
|
||||
if (novuEnabled) {
|
||||
const { error: novuError } = await supabase.functions.invoke('update-novu-preferences', {
|
||||
body: {
|
||||
const { error: novuError, requestId } = await invokeWithTracking(
|
||||
'update-novu-preferences',
|
||||
{
|
||||
userId,
|
||||
preferences: validated,
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
if (novuError) {
|
||||
logger.error('Failed to update Novu preferences', {
|
||||
action: 'update_novu_preferences',
|
||||
userId,
|
||||
requestId,
|
||||
error: novuError.message
|
||||
});
|
||||
throw novuError;
|
||||
@@ -360,15 +369,17 @@ class NotificationService {
|
||||
return { success: false, error: 'Novu not configured' };
|
||||
}
|
||||
|
||||
const { data, error } = await supabase.functions.invoke('trigger-notification', {
|
||||
body: payload
|
||||
});
|
||||
const { data, error, requestId } = await invokeWithTracking(
|
||||
'trigger-notification',
|
||||
payload
|
||||
);
|
||||
|
||||
if (error) {
|
||||
logger.error('Failed to trigger notification', {
|
||||
action: 'trigger_notification',
|
||||
workflowId: payload.workflowId,
|
||||
subscriberId: payload.subscriberId,
|
||||
requestId,
|
||||
error: error.message
|
||||
});
|
||||
throw error;
|
||||
@@ -378,7 +389,8 @@ class NotificationService {
|
||||
action: 'trigger_notification',
|
||||
workflowId: payload.workflowId,
|
||||
subscriberId: payload.subscriberId,
|
||||
transactionId: data?.transactionId
|
||||
transactionId: data?.transactionId,
|
||||
requestId
|
||||
});
|
||||
|
||||
return { success: true };
|
||||
@@ -407,14 +419,16 @@ class NotificationService {
|
||||
action: string;
|
||||
}): Promise<void> {
|
||||
try {
|
||||
const { error } = await supabase.functions.invoke('notify-moderators-submission', {
|
||||
body: payload
|
||||
});
|
||||
const { error, requestId } = await invokeWithTracking(
|
||||
'notify-moderators-submission',
|
||||
payload
|
||||
);
|
||||
|
||||
if (error) {
|
||||
logger.error('Failed to notify moderators', {
|
||||
action: 'notify_moderators',
|
||||
submissionId: payload.submission_id,
|
||||
requestId,
|
||||
error: error.message
|
||||
});
|
||||
throw error;
|
||||
@@ -422,7 +436,8 @@ class NotificationService {
|
||||
|
||||
logger.info('Moderators notified successfully', {
|
||||
action: 'notify_moderators',
|
||||
submissionId: payload.submission_id
|
||||
submissionId: payload.submission_id,
|
||||
requestId
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Error notifying moderators', {
|
||||
|
||||
Reference in New Issue
Block a user