mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 17:11:23 -05:00
Fix edge function console statements
This commit is contained in:
@@ -86,14 +86,14 @@ export function CoasterStatsEditor({
|
|||||||
onChange(newStats.map((stat, i) => ({ ...stat, display_order: i })));
|
onChange(newStats.map((stat, i) => ({ ...stat, display_order: i })));
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateStat = (index: number, field: keyof CoasterStat, value: any) => {
|
const updateStat = (index: number, field: keyof CoasterStat, value: string | number | boolean | null | undefined) => {
|
||||||
const newStats = [...stats];
|
const newStats = [...stats];
|
||||||
|
|
||||||
// Ensure unit is metric when updating unit field
|
// Ensure unit is metric when updating unit field
|
||||||
if (field === 'unit' && value) {
|
if (field === 'unit' && value && typeof value === 'string') {
|
||||||
try {
|
try {
|
||||||
validateMetricUnit(value, 'Unit');
|
validateMetricUnit(value, 'Unit');
|
||||||
newStats[index] = { ...newStats[index], [field]: value };
|
newStats[index] = { ...newStats[index], unit: value };
|
||||||
// Clear error for this index
|
// Clear error for this index
|
||||||
setUnitErrors(prev => {
|
setUnitErrors(prev => {
|
||||||
const updated = { ...prev };
|
const updated = { ...prev };
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export function FormerNamesEditor({ names, onChange, currentName }: FormerNamesE
|
|||||||
onChange(newNames.map((name, i) => ({ ...name, order_index: i })));
|
onChange(newNames.map((name, i) => ({ ...name, order_index: i })));
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateName = (index: number, field: keyof FormerName, value: any) => {
|
const updateName = (index: number, field: keyof FormerName, value: string | number | Date | null | undefined) => {
|
||||||
const newNames = [...names];
|
const newNames = [...names];
|
||||||
newNames[index] = { ...newNames[index], [field]: value };
|
newNames[index] = { ...newNames[index], [field]: value };
|
||||||
onChange(newNames);
|
onChange(newNames);
|
||||||
|
|||||||
@@ -64,14 +64,14 @@ export function TechnicalSpecsEditor({
|
|||||||
onChange(newSpecs.map((spec, i) => ({ ...spec, display_order: i })));
|
onChange(newSpecs.map((spec, i) => ({ ...spec, display_order: i })));
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateSpec = (index: number, field: keyof TechnicalSpec, value: any) => {
|
const updateSpec = (index: number, field: keyof TechnicalSpec, value: string | number | boolean | null | undefined) => {
|
||||||
const newSpecs = [...specs];
|
const newSpecs = [...specs];
|
||||||
|
|
||||||
// Ensure unit is metric when updating unit field
|
// Ensure unit is metric when updating unit field
|
||||||
if (field === 'unit' && value) {
|
if (field === 'unit' && value && typeof value === 'string') {
|
||||||
try {
|
try {
|
||||||
validateMetricUnit(value, 'Unit');
|
validateMetricUnit(value, 'Unit');
|
||||||
newSpecs[index] = { ...newSpecs[index], [field]: value };
|
newSpecs[index] = { ...newSpecs[index], unit: value };
|
||||||
// Clear error for this index
|
// Clear error for this index
|
||||||
setUnitErrors(prev => {
|
setUnitErrors(prev => {
|
||||||
const updated = { ...prev };
|
const updated = { ...prev };
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export function TurnstileCaptcha({
|
|||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [key, setKey] = useState(0);
|
const [key, setKey] = useState(0);
|
||||||
const turnstileRef = useRef<any>(null);
|
const turnstileRef = useRef(null);
|
||||||
|
|
||||||
const handleSuccess = (token: string) => {
|
const handleSuccess = (token: string) => {
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|||||||
@@ -11,9 +11,11 @@ interface AdminErrorBoundaryProps {
|
|||||||
section?: string; // e.g., "Moderation", "Users", "Settings"
|
section?: string; // e.g., "Moderation", "Users", "Settings"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ErrorWithId = Error & { errorId: string };
|
||||||
|
|
||||||
interface AdminErrorBoundaryState {
|
interface AdminErrorBoundaryState {
|
||||||
hasError: boolean;
|
hasError: boolean;
|
||||||
error: Error | null;
|
error: ErrorWithId | null;
|
||||||
errorInfo: ErrorInfo | null;
|
errorInfo: ErrorInfo | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +45,7 @@ export class AdminErrorBoundary extends Component<AdminErrorBoundaryProps, Admin
|
|||||||
static getDerivedStateFromError(error: Error): Partial<AdminErrorBoundaryState> {
|
static getDerivedStateFromError(error: Error): Partial<AdminErrorBoundaryState> {
|
||||||
return {
|
return {
|
||||||
hasError: true,
|
hasError: true,
|
||||||
error,
|
error: error as ErrorWithId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +62,7 @@ export class AdminErrorBoundary extends Component<AdminErrorBoundaryProps, Admin
|
|||||||
errorId,
|
errorId,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setState({ errorInfo, error: { ...error, errorId } as any });
|
this.setState({ errorInfo, error: { ...error, errorId } as ErrorWithId });
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRetry = () => {
|
handleRetry = () => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
||||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
|
||||||
import { startRequest, endRequest } from "../_shared/logger.ts";
|
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
const corsHeaders = {
|
||||||
'Access-Control-Allow-Origin': '*',
|
'Access-Control-Allow-Origin': '*',
|
||||||
@@ -21,7 +21,7 @@ serve(async (req) => {
|
|||||||
Deno.env.get('SUPABASE_SERVICE_ROLE_KEY') ?? ''
|
Deno.env.get('SUPABASE_SERVICE_ROLE_KEY') ?? ''
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('Processing scheduled account deletions...', { requestId: tracking.requestId });
|
edgeLogger.info('Processing scheduled account deletions', { action: 'scheduled_deletions', requestId: tracking.requestId });
|
||||||
|
|
||||||
// Find confirmed deletion requests that are past their scheduled date
|
// Find confirmed deletion requests that are past their scheduled date
|
||||||
const { data: pendingDeletions, error: fetchError } = await supabaseAdmin
|
const { data: pendingDeletions, error: fetchError } = await supabaseAdmin
|
||||||
@@ -35,7 +35,7 @@ serve(async (req) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!pendingDeletions || pendingDeletions.length === 0) {
|
if (!pendingDeletions || pendingDeletions.length === 0) {
|
||||||
console.log('No deletions to process');
|
edgeLogger.info('No deletions to process', { action: 'scheduled_deletions', requestId: tracking.requestId });
|
||||||
|
|
||||||
endRequest(tracking, 200);
|
endRequest(tracking, 200);
|
||||||
|
|
||||||
@@ -57,14 +57,14 @@ serve(async (req) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Found ${pendingDeletions.length} deletion(s) to process`);
|
edgeLogger.info('Found deletions to process', { action: 'scheduled_deletions', count: pendingDeletions.length, requestId: tracking.requestId });
|
||||||
|
|
||||||
let successCount = 0;
|
let successCount = 0;
|
||||||
let errorCount = 0;
|
let errorCount = 0;
|
||||||
|
|
||||||
for (const deletion of pendingDeletions) {
|
for (const deletion of pendingDeletions) {
|
||||||
try {
|
try {
|
||||||
console.log(`Processing deletion for user: ${deletion.user_id}`);
|
edgeLogger.info('Processing deletion for user', { action: 'scheduled_deletions', userId: deletion.user_id });
|
||||||
|
|
||||||
// Get user email for confirmation email
|
// Get user email for confirmation email
|
||||||
const { data: userData } = await supabaseAdmin.auth.admin.getUserById(deletion.user_id);
|
const { data: userData } = await supabaseAdmin.auth.admin.getUserById(deletion.user_id);
|
||||||
@@ -100,7 +100,7 @@ serve(async (req) => {
|
|||||||
|
|
||||||
if (cloudflareAccountId && cloudflareApiToken) {
|
if (cloudflareAccountId && cloudflareApiToken) {
|
||||||
try {
|
try {
|
||||||
console.log(`Deleting avatar image: ${profile.avatar_image_id}`);
|
edgeLogger.info('Deleting avatar image', { action: 'scheduled_deletions', avatarId: profile.avatar_image_id });
|
||||||
const deleteResponse = await fetch(
|
const deleteResponse = await fetch(
|
||||||
`https://api.cloudflare.com/client/v4/accounts/${cloudflareAccountId}/images/v1/${profile.avatar_image_id}`,
|
`https://api.cloudflare.com/client/v4/accounts/${cloudflareAccountId}/images/v1/${profile.avatar_image_id}`,
|
||||||
{
|
{
|
||||||
@@ -112,12 +112,12 @@ serve(async (req) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!deleteResponse.ok) {
|
if (!deleteResponse.ok) {
|
||||||
console.error('Failed to delete avatar from Cloudflare:', await deleteResponse.text());
|
edgeLogger.error('Failed to delete avatar from Cloudflare', { action: 'scheduled_deletions', error: await deleteResponse.text() });
|
||||||
} else {
|
} else {
|
||||||
console.log('Avatar deleted from Cloudflare successfully');
|
edgeLogger.info('Avatar deleted from Cloudflare successfully', { action: 'scheduled_deletions' });
|
||||||
}
|
}
|
||||||
} catch (avatarError) {
|
} catch (avatarError) {
|
||||||
console.error('Error deleting avatar from Cloudflare:', avatarError);
|
edgeLogger.error('Error deleting avatar from Cloudflare', { action: 'scheduled_deletions', error: avatarError });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ serve(async (req) => {
|
|||||||
|
|
||||||
// Remove from Novu before deleting auth user
|
// Remove from Novu before deleting auth user
|
||||||
try {
|
try {
|
||||||
console.log(`Removing Novu subscriber: ${deletion.user_id}`);
|
edgeLogger.info('Removing Novu subscriber', { action: 'scheduled_deletions', userId: deletion.user_id });
|
||||||
|
|
||||||
const { error: novuError } = await supabaseAdmin.functions.invoke(
|
const { error: novuError } = await supabaseAdmin.functions.invoke(
|
||||||
'remove-novu-subscriber',
|
'remove-novu-subscriber',
|
||||||
@@ -143,13 +143,13 @@ serve(async (req) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (novuError) {
|
if (novuError) {
|
||||||
console.error('Failed to remove Novu subscriber:', novuError);
|
edgeLogger.error('Failed to remove Novu subscriber', { action: 'scheduled_deletions', error: novuError });
|
||||||
} else {
|
} else {
|
||||||
console.log('Novu subscriber removed successfully');
|
edgeLogger.info('Novu subscriber removed successfully', { action: 'scheduled_deletions' });
|
||||||
}
|
}
|
||||||
} catch (novuError) {
|
} catch (novuError) {
|
||||||
// Non-blocking - log but continue with deletion
|
// Non-blocking - log but continue with deletion
|
||||||
console.error('Error removing Novu subscriber:', novuError);
|
edgeLogger.error('Error removing Novu subscriber', { action: 'scheduled_deletions', error: novuError });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update deletion request status
|
// Update deletion request status
|
||||||
@@ -190,20 +190,20 @@ serve(async (req) => {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
} catch (emailError) {
|
} catch (emailError) {
|
||||||
console.error('Failed to send confirmation email:', emailError);
|
edgeLogger.error('Failed to send confirmation email', { action: 'scheduled_deletions', error: emailError });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
successCount++;
|
successCount++;
|
||||||
console.log(`Successfully deleted account for user: ${deletion.user_id}`);
|
edgeLogger.info('Successfully deleted account for user', { action: 'scheduled_deletions', userId: deletion.user_id });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errorCount++;
|
errorCount++;
|
||||||
console.error(`Failed to delete account for user ${deletion.user_id}:`, error);
|
edgeLogger.error('Failed to delete account for user', { action: 'scheduled_deletions', userId: deletion.user_id, error });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Processed ${successCount} deletion(s) successfully, ${errorCount} error(s)`);
|
edgeLogger.info('Processed deletions', { action: 'scheduled_deletions', successCount, errorCount, requestId: tracking.requestId });
|
||||||
|
|
||||||
endRequest(tracking, 200);
|
endRequest(tracking, 200);
|
||||||
|
|
||||||
@@ -225,7 +225,7 @@ serve(async (req) => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error processing scheduled deletions:', error);
|
edgeLogger.error('Error processing scheduled deletions', { action: 'scheduled_deletions', error: error.message, requestId: tracking.requestId });
|
||||||
|
|
||||||
endRequest(tracking, 500, error.message);
|
endRequest(tracking, 500, error.message);
|
||||||
|
|
||||||
|
|||||||
@@ -501,7 +501,7 @@ serve(withRateLimit(async (req) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (setUserIdError) {
|
if (setUserIdError) {
|
||||||
console.error('[APPROVAL] Failed to set user context:', { error: setUserIdError.message });
|
edgeLogger.error('Failed to set user context', { action: 'approval_set_context', error: setUserIdError.message, requestId: tracking.requestId });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set submission ID for version tracking
|
// Set submission ID for version tracking
|
||||||
@@ -512,7 +512,7 @@ serve(withRateLimit(async (req) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (setSubmissionIdError) {
|
if (setSubmissionIdError) {
|
||||||
console.error('[APPROVAL] Failed to set submission context:', { error: setSubmissionIdError.message });
|
edgeLogger.error('Failed to set submission context', { action: 'approval_set_context', error: setSubmissionIdError.message, requestId: tracking.requestId });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve dependencies in item data
|
// Resolve dependencies in item data
|
||||||
@@ -702,7 +702,7 @@ serve(withRateLimit(async (req) => {
|
|||||||
.eq('id', submissionId);
|
.eq('id', submissionId);
|
||||||
|
|
||||||
if (updateError) {
|
if (updateError) {
|
||||||
console.error('[APPROVAL] Failed to update submission status:', { error: updateError.message });
|
edgeLogger.error('Failed to update submission status', { action: 'approval_update_status', error: updateError.message, requestId: tracking.requestId });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log audit trail for submission action
|
// Log audit trail for submission action
|
||||||
@@ -731,7 +731,7 @@ serve(withRateLimit(async (req) => {
|
|||||||
});
|
});
|
||||||
} catch (auditError) {
|
} catch (auditError) {
|
||||||
// Log but don't fail the operation
|
// Log but don't fail the operation
|
||||||
console.error('[AUDIT] Failed to log admin action:', auditError);
|
edgeLogger.error('Failed to log admin action', { action: 'approval_audit_log', error: auditError, requestId: tracking.requestId });
|
||||||
}
|
}
|
||||||
|
|
||||||
const duration = endRequest(tracking);
|
const duration = endRequest(tracking);
|
||||||
@@ -754,10 +754,10 @@ serve(withRateLimit(async (req) => {
|
|||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const duration = endRequest(tracking);
|
const duration = endRequest(tracking);
|
||||||
const errorMessage = error instanceof Error ? error.message : 'An unexpected error occurred';
|
const errorMessage = error instanceof Error ? error.message : 'An unexpected error occurred';
|
||||||
console.error('[APPROVAL ERROR] Process failed:', {
|
edgeLogger.error('Approval process failed', {
|
||||||
|
action: 'approval_process_error',
|
||||||
error: errorMessage,
|
error: errorMessage,
|
||||||
userId: authenticatedUserId,
|
userId: authenticatedUserId,
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
requestId: tracking.requestId,
|
requestId: tracking.requestId,
|
||||||
duration
|
duration
|
||||||
});
|
});
|
||||||
@@ -1059,7 +1059,7 @@ async function createPark(supabase: any, data: any): Promise<string> {
|
|||||||
|
|
||||||
// Check if this is an edit (has park_id) or a new creation
|
// Check if this is an edit (has park_id) or a new creation
|
||||||
if (data.park_id) {
|
if (data.park_id) {
|
||||||
console.log(`Updating existing park ${data.park_id}`);
|
edgeLogger.info('Updating existing park', { action: 'approval_update_park', parkId: data.park_id });
|
||||||
parkId = data.park_id;
|
parkId = data.park_id;
|
||||||
delete data.park_id; // Remove ID from update data
|
delete data.park_id; // Remove ID from update data
|
||||||
|
|
||||||
@@ -1073,7 +1073,7 @@ async function createPark(supabase: any, data: any): Promise<string> {
|
|||||||
|
|
||||||
if (error) throw new Error(`Failed to update park: ${error.message}`);
|
if (error) throw new Error(`Failed to update park: ${error.message}`);
|
||||||
} else {
|
} else {
|
||||||
console.log('Creating new park');
|
edgeLogger.info('Creating new park', { action: 'approval_create_park' });
|
||||||
const normalizedData = normalizeStatusValue(data);
|
const normalizedData = normalizeStatusValue(data);
|
||||||
const sanitizedData = sanitizeDateFields(normalizedData);
|
const sanitizedData = sanitizeDateFields(normalizedData);
|
||||||
const filteredData = filterDatabaseFields(sanitizedData, PARK_FIELDS);
|
const filteredData = filterDatabaseFields(sanitizedData, PARK_FIELDS);
|
||||||
@@ -1089,7 +1089,7 @@ async function createPark(supabase: any, data: any): Promise<string> {
|
|||||||
|
|
||||||
// Insert photos into photos table
|
// Insert photos into photos table
|
||||||
if (uploadedPhotos.length > 0 && submitterId) {
|
if (uploadedPhotos.length > 0 && submitterId) {
|
||||||
console.log(`Inserting ${uploadedPhotos.length} photos for park ${parkId}`);
|
edgeLogger.info('Inserting photos for park', { action: 'approval_insert_photos', photoCount: uploadedPhotos.length, parkId });
|
||||||
for (let i = 0; i < uploadedPhotos.length; i++) {
|
for (let i = 0; i < uploadedPhotos.length; i++) {
|
||||||
const photo = uploadedPhotos[i];
|
const photo = uploadedPhotos[i];
|
||||||
if (photo.cloudflare_id && photo.url) {
|
if (photo.cloudflare_id && photo.url) {
|
||||||
@@ -1106,7 +1106,7 @@ async function createPark(supabase: any, data: any): Promise<string> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (photoError) {
|
if (photoError) {
|
||||||
console.error(`Failed to insert photo ${i}:`, photoError);
|
edgeLogger.error('Failed to insert photo', { action: 'approval_insert_photo', photoIndex: i, error: photoError.message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1160,7 +1160,7 @@ async function createRide(supabase: any, data: any): Promise<string> {
|
|||||||
|
|
||||||
// Check if this is an edit (has ride_id) or a new creation
|
// Check if this is an edit (has ride_id) or a new creation
|
||||||
if (data.ride_id) {
|
if (data.ride_id) {
|
||||||
console.log(`Updating existing ride ${data.ride_id}`);
|
edgeLogger.info('Updating existing ride', { action: 'approval_update_ride', rideId: data.ride_id });
|
||||||
rideId = data.ride_id;
|
rideId = data.ride_id;
|
||||||
delete data.ride_id; // Remove ID from update data
|
delete data.ride_id; // Remove ID from update data
|
||||||
|
|
||||||
@@ -1176,17 +1176,17 @@ async function createRide(supabase: any, data: any): Promise<string> {
|
|||||||
|
|
||||||
// Update park ride counts after successful ride update
|
// Update park ride counts after successful ride update
|
||||||
if (parkId) {
|
if (parkId) {
|
||||||
console.log(`Updating ride counts for park ${parkId}`);
|
edgeLogger.info('Updating ride counts for park', { action: 'approval_update_counts', parkId });
|
||||||
const { error: countError } = await supabase.rpc('update_park_ride_counts', {
|
const { error: countError } = await supabase.rpc('update_park_ride_counts', {
|
||||||
target_park_id: parkId
|
target_park_id: parkId
|
||||||
});
|
});
|
||||||
|
|
||||||
if (countError) {
|
if (countError) {
|
||||||
console.error('Failed to update park counts:', countError);
|
edgeLogger.error('Failed to update park counts', { action: 'approval_update_counts', error: countError.message, parkId });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('Creating new ride');
|
edgeLogger.info('Creating new ride', { action: 'approval_create_ride' });
|
||||||
const normalizedData = normalizeStatusValue(data);
|
const normalizedData = normalizeStatusValue(data);
|
||||||
const sanitizedData = sanitizeDateFields(normalizedData);
|
const sanitizedData = sanitizeDateFields(normalizedData);
|
||||||
const filteredData = filterDatabaseFields(sanitizedData, RIDE_FIELDS);
|
const filteredData = filterDatabaseFields(sanitizedData, RIDE_FIELDS);
|
||||||
@@ -1201,20 +1201,20 @@ async function createRide(supabase: any, data: any): Promise<string> {
|
|||||||
|
|
||||||
// Update park ride counts after successful ride creation
|
// Update park ride counts after successful ride creation
|
||||||
if (parkId) {
|
if (parkId) {
|
||||||
console.log(`Updating ride counts for park ${parkId}`);
|
edgeLogger.info('Updating ride counts for park', { action: 'approval_update_counts', parkId });
|
||||||
const { error: countError } = await supabase.rpc('update_park_ride_counts', {
|
const { error: countError } = await supabase.rpc('update_park_ride_counts', {
|
||||||
target_park_id: parkId
|
target_park_id: parkId
|
||||||
});
|
});
|
||||||
|
|
||||||
if (countError) {
|
if (countError) {
|
||||||
console.error('Failed to update park counts:', countError);
|
edgeLogger.error('Failed to update park counts', { action: 'approval_update_counts', error: countError.message, parkId });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert photos into photos table
|
// Insert photos into photos table
|
||||||
if (uploadedPhotos.length > 0 && submitterId) {
|
if (uploadedPhotos.length > 0 && submitterId) {
|
||||||
console.log(`Inserting ${uploadedPhotos.length} photos for ride ${rideId}`);
|
edgeLogger.info('Inserting photos for ride', { action: 'approval_insert_photos', photoCount: uploadedPhotos.length, rideId });
|
||||||
for (let i = 0; i < uploadedPhotos.length; i++) {
|
for (let i = 0; i < uploadedPhotos.length; i++) {
|
||||||
const photo = uploadedPhotos[i];
|
const photo = uploadedPhotos[i];
|
||||||
if (photo.cloudflare_id && photo.url) {
|
if (photo.cloudflare_id && photo.url) {
|
||||||
@@ -1231,7 +1231,7 @@ async function createRide(supabase: any, data: any): Promise<string> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (photoError) {
|
if (photoError) {
|
||||||
console.error(`Failed to insert photo ${i}:`, photoError);
|
edgeLogger.error('Failed to insert photo', { action: 'approval_insert_photo', photoIndex: i, error: photoError.message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1239,7 +1239,7 @@ async function createRide(supabase: any, data: any): Promise<string> {
|
|||||||
|
|
||||||
// Insert technical specifications
|
// Insert technical specifications
|
||||||
if (technicalSpecifications.length > 0) {
|
if (technicalSpecifications.length > 0) {
|
||||||
console.log(`Inserting ${technicalSpecifications.length} technical specs for ride ${rideId}`);
|
edgeLogger.info('Inserting technical specs for ride', { action: 'approval_insert_specs', specCount: technicalSpecifications.length, rideId });
|
||||||
const techSpecsToInsert = technicalSpecifications.map((spec: any) => ({
|
const techSpecsToInsert = technicalSpecifications.map((spec: any) => ({
|
||||||
ride_id: rideId,
|
ride_id: rideId,
|
||||||
spec_name: spec.spec_name,
|
spec_name: spec.spec_name,
|
||||||
@@ -1254,13 +1254,13 @@ async function createRide(supabase: any, data: any): Promise<string> {
|
|||||||
.insert(techSpecsToInsert);
|
.insert(techSpecsToInsert);
|
||||||
|
|
||||||
if (techSpecError) {
|
if (techSpecError) {
|
||||||
console.error('Failed to insert technical specifications:', techSpecError);
|
edgeLogger.error('Failed to insert technical specifications', { action: 'approval_insert_specs', error: techSpecError.message, rideId });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert coaster statistics
|
// Insert coaster statistics
|
||||||
if (coasterStatistics.length > 0) {
|
if (coasterStatistics.length > 0) {
|
||||||
console.log(`Inserting ${coasterStatistics.length} coaster stats for ride ${rideId}`);
|
edgeLogger.info('Inserting coaster stats for ride', { action: 'approval_insert_stats', statCount: coasterStatistics.length, rideId });
|
||||||
const statsToInsert = coasterStatistics.map((stat: any) => ({
|
const statsToInsert = coasterStatistics.map((stat: any) => ({
|
||||||
ride_id: rideId,
|
ride_id: rideId,
|
||||||
stat_name: stat.stat_name,
|
stat_name: stat.stat_name,
|
||||||
@@ -1276,13 +1276,13 @@ async function createRide(supabase: any, data: any): Promise<string> {
|
|||||||
.insert(statsToInsert);
|
.insert(statsToInsert);
|
||||||
|
|
||||||
if (statsError) {
|
if (statsError) {
|
||||||
console.error('Failed to insert coaster statistics:', statsError);
|
edgeLogger.error('Failed to insert coaster statistics', { action: 'approval_insert_stats', error: statsError.message, rideId });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert name history
|
// Insert name history
|
||||||
if (nameHistory.length > 0) {
|
if (nameHistory.length > 0) {
|
||||||
console.log(`Inserting ${nameHistory.length} former names for ride ${rideId}`);
|
edgeLogger.info('Inserting name history for ride', { action: 'approval_insert_names', nameCount: nameHistory.length, rideId });
|
||||||
const namesToInsert = nameHistory.map((name: any) => ({
|
const namesToInsert = nameHistory.map((name: any) => ({
|
||||||
ride_id: rideId,
|
ride_id: rideId,
|
||||||
former_name: name.former_name,
|
former_name: name.former_name,
|
||||||
@@ -1298,7 +1298,7 @@ async function createRide(supabase: any, data: any): Promise<string> {
|
|||||||
.insert(namesToInsert);
|
.insert(namesToInsert);
|
||||||
|
|
||||||
if (namesError) {
|
if (namesError) {
|
||||||
console.error('Failed to insert name history:', namesError);
|
edgeLogger.error('Failed to insert name history', { action: 'approval_insert_names', error: namesError.message, rideId });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1332,7 +1332,7 @@ async function createCompany(supabase: any, data: any, companyType: string): Pro
|
|||||||
const companyId = data.company_id || data.id;
|
const companyId = data.company_id || data.id;
|
||||||
|
|
||||||
if (companyId) {
|
if (companyId) {
|
||||||
console.log(`Updating existing company ${companyId}`);
|
edgeLogger.info('Updating existing company', { action: 'approval_update_company', companyId });
|
||||||
const updateData = sanitizeDateFields({ ...data, company_type: companyType });
|
const updateData = sanitizeDateFields({ ...data, company_type: companyType });
|
||||||
delete updateData.company_id;
|
delete updateData.company_id;
|
||||||
delete updateData.id; // Remove ID from update data
|
delete updateData.id; // Remove ID from update data
|
||||||
@@ -1346,7 +1346,7 @@ async function createCompany(supabase: any, data: any, companyType: string): Pro
|
|||||||
if (error) throw new Error(`Failed to update company: ${error.message}`);
|
if (error) throw new Error(`Failed to update company: ${error.message}`);
|
||||||
return companyId;
|
return companyId;
|
||||||
} else {
|
} else {
|
||||||
console.log('Creating new company');
|
edgeLogger.info('Creating new company', { action: 'approval_create_company' });
|
||||||
const companyData = sanitizeDateFields({ ...data, company_type: companyType });
|
const companyData = sanitizeDateFields({ ...data, company_type: companyType });
|
||||||
const filteredData = filterDatabaseFields(companyData, COMPANY_FIELDS);
|
const filteredData = filterDatabaseFields(companyData, COMPANY_FIELDS);
|
||||||
const { data: company, error } = await supabase
|
const { data: company, error } = await supabase
|
||||||
@@ -1371,7 +1371,7 @@ async function createRideModel(supabase: any, data: any): Promise<string> {
|
|||||||
|
|
||||||
// Check if this is an edit (has ride_model_id) or a new creation
|
// Check if this is an edit (has ride_model_id) or a new creation
|
||||||
if (data.ride_model_id) {
|
if (data.ride_model_id) {
|
||||||
console.log(`Updating existing ride model ${data.ride_model_id}`);
|
edgeLogger.info('Updating existing ride model', { action: 'approval_update_model', rideModelId: data.ride_model_id });
|
||||||
rideModelId = data.ride_model_id;
|
rideModelId = data.ride_model_id;
|
||||||
delete data.ride_model_id; // Remove ID from update data
|
delete data.ride_model_id; // Remove ID from update data
|
||||||
|
|
||||||
@@ -1384,7 +1384,7 @@ async function createRideModel(supabase: any, data: any): Promise<string> {
|
|||||||
|
|
||||||
if (error) throw new Error(`Failed to update ride model: ${error.message}`);
|
if (error) throw new Error(`Failed to update ride model: ${error.message}`);
|
||||||
} else {
|
} else {
|
||||||
console.log('Creating new ride model');
|
edgeLogger.info('Creating new ride model', { action: 'approval_create_model' });
|
||||||
|
|
||||||
// Validate required fields
|
// Validate required fields
|
||||||
if (!data.manufacturer_id) {
|
if (!data.manufacturer_id) {
|
||||||
@@ -1408,7 +1408,7 @@ async function createRideModel(supabase: any, data: any): Promise<string> {
|
|||||||
|
|
||||||
// Insert technical specifications
|
// Insert technical specifications
|
||||||
if (technicalSpecifications.length > 0) {
|
if (technicalSpecifications.length > 0) {
|
||||||
console.log(`Inserting ${technicalSpecifications.length} technical specs for ride model ${rideModelId}`);
|
edgeLogger.info('Inserting technical specs for ride model', { action: 'approval_insert_model_specs', specCount: technicalSpecifications.length, rideModelId });
|
||||||
const techSpecsToInsert = technicalSpecifications.map((spec: any) => ({
|
const techSpecsToInsert = technicalSpecifications.map((spec: any) => ({
|
||||||
ride_model_id: rideModelId,
|
ride_model_id: rideModelId,
|
||||||
spec_name: spec.spec_name,
|
spec_name: spec.spec_name,
|
||||||
@@ -1423,7 +1423,7 @@ async function createRideModel(supabase: any, data: any): Promise<string> {
|
|||||||
.insert(techSpecsToInsert);
|
.insert(techSpecsToInsert);
|
||||||
|
|
||||||
if (techSpecError) {
|
if (techSpecError) {
|
||||||
console.error('Failed to insert technical specifications:', techSpecError);
|
edgeLogger.error('Failed to insert technical specifications', { action: 'approval_insert_model_specs', error: techSpecError.message, rideModelId });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1448,7 +1448,7 @@ async function approvePhotos(supabase: any, data: any, submissionItemId: string)
|
|||||||
|
|
||||||
const { error } = await supabase.from('photos').insert(photoData);
|
const { error } = await supabase.from('photos').insert(photoData);
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('Failed to insert photo:', error);
|
edgeLogger.error('Failed to insert photo', { action: 'approval_insert_photo', error: error.message });
|
||||||
throw new Error(`Failed to insert photo: ${error.message}`);
|
throw new Error(`Failed to insert photo: ${error.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1460,7 +1460,7 @@ function extractImageId(url: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function editPhoto(supabase: any, data: any): Promise<void> {
|
async function editPhoto(supabase: any, data: any): Promise<void> {
|
||||||
console.log(`Editing photo ${data.photo_id}`);
|
edgeLogger.info('Editing photo', { action: 'approval_edit_photo', photoId: data.photo_id });
|
||||||
const { error } = await supabase
|
const { error } = await supabase
|
||||||
.from('photos')
|
.from('photos')
|
||||||
.update({
|
.update({
|
||||||
@@ -1472,7 +1472,7 @@ async function editPhoto(supabase: any, data: any): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function deletePhoto(supabase: any, data: any): Promise<void> {
|
async function deletePhoto(supabase: any, data: any): Promise<void> {
|
||||||
console.log(`Deleting photo ${data.photo_id}`);
|
edgeLogger.info('Deleting photo', { action: 'approval_delete_photo', photoId: data.photo_id });
|
||||||
const { error } = await supabase
|
const { error } = await supabase
|
||||||
.from('photos')
|
.from('photos')
|
||||||
.delete()
|
.delete()
|
||||||
@@ -1493,7 +1493,7 @@ async function createTimelineEvent(
|
|||||||
const eventId = data.id || data.event_id;
|
const eventId = data.id || data.event_id;
|
||||||
|
|
||||||
if (eventId) {
|
if (eventId) {
|
||||||
console.log(`Updating existing timeline event ${eventId}`);
|
edgeLogger.info('Updating existing timeline event', { action: 'approval_update_timeline', eventId });
|
||||||
|
|
||||||
// Prepare update data (exclude ID and audit fields)
|
// Prepare update data (exclude ID and audit fields)
|
||||||
const updateData: any = {
|
const updateData: any = {
|
||||||
@@ -1524,7 +1524,7 @@ async function createTimelineEvent(
|
|||||||
if (error) throw new Error(`Failed to update timeline event: ${error.message}`);
|
if (error) throw new Error(`Failed to update timeline event: ${error.message}`);
|
||||||
return eventId;
|
return eventId;
|
||||||
} else {
|
} else {
|
||||||
console.log('Creating new timeline event');
|
edgeLogger.info('Creating new timeline event', { action: 'approval_create_timeline' });
|
||||||
|
|
||||||
const eventData = {
|
const eventData = {
|
||||||
entity_id: data.entity_id,
|
entity_id: data.entity_id,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
||||||
import { Novu } from "npm:@novu/api@1.6.0";
|
import { Novu } from "npm:@novu/api@1.6.0";
|
||||||
import { startRequest, endRequest } from "../_shared/logger.ts";
|
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
const corsHeaders = {
|
||||||
'Access-Control-Allow-Origin': '*',
|
'Access-Control-Allow-Origin': '*',
|
||||||
@@ -43,27 +43,27 @@ serve(async (req) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Removing subscriber from "users" topic:', { subscriberId, requestId: tracking.requestId });
|
edgeLogger.info('Removing subscriber from users topic', { action: 'remove_novu_subscriber', subscriberId, requestId: tracking.requestId });
|
||||||
|
|
||||||
// Remove subscriber from "users" topic
|
// Remove subscriber from "users" topic
|
||||||
try {
|
try {
|
||||||
await novu.topics.removeSubscribers('users', {
|
await novu.topics.removeSubscribers('users', {
|
||||||
subscribers: [subscriberId],
|
subscribers: [subscriberId],
|
||||||
});
|
});
|
||||||
console.log('Successfully removed subscriber from "users" topic', { subscriberId });
|
edgeLogger.info('Successfully removed subscriber from users topic', { action: 'remove_novu_subscriber', subscriberId });
|
||||||
} catch (topicError: any) {
|
} catch (topicError: any) {
|
||||||
console.error('Failed to remove subscriber from "users" topic:', topicError.message, { subscriberId });
|
edgeLogger.error('Failed to remove subscriber from users topic', { action: 'remove_novu_subscriber', subscriberId, error: topicError.message });
|
||||||
// Continue - we still want to delete the subscriber if requested
|
// Continue - we still want to delete the subscriber if requested
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optionally delete the subscriber entirely from Novu
|
// Optionally delete the subscriber entirely from Novu
|
||||||
if (deleteSubscriber) {
|
if (deleteSubscriber) {
|
||||||
try {
|
try {
|
||||||
console.log('Deleting subscriber from Novu:', { subscriberId });
|
edgeLogger.info('Deleting subscriber from Novu', { action: 'remove_novu_subscriber', subscriberId });
|
||||||
await novu.subscribers.delete(subscriberId);
|
await novu.subscribers.delete(subscriberId);
|
||||||
console.log('Successfully deleted subscriber from Novu', { subscriberId });
|
edgeLogger.info('Successfully deleted subscriber from Novu', { action: 'remove_novu_subscriber', subscriberId });
|
||||||
} catch (deleteError: any) {
|
} catch (deleteError: any) {
|
||||||
console.error('Failed to delete subscriber from Novu:', deleteError.message, { subscriberId });
|
edgeLogger.error('Failed to delete subscriber from Novu', { action: 'remove_novu_subscriber', subscriberId, error: deleteError.message });
|
||||||
throw deleteError;
|
throw deleteError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ serve(async (req) => {
|
|||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
||||||
console.error('Error removing Novu subscriber:', errorMessage, { requestId: tracking.requestId });
|
edgeLogger.error('Error removing Novu subscriber', { action: 'remove_novu_subscriber', error: errorMessage, requestId: tracking.requestId });
|
||||||
|
|
||||||
endRequest(tracking, 500, errorMessage);
|
endRequest(tracking, 500, errorMessage);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
||||||
import { Novu } from "npm:@novu/api@1.6.0";
|
import { Novu } from "npm:@novu/api@1.6.0";
|
||||||
import { startRequest, endRequest } from "../_shared/logger.ts";
|
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
||||||
|
|
||||||
const corsHeaders = {
|
const corsHeaders = {
|
||||||
'Access-Control-Allow-Origin': '*',
|
'Access-Control-Allow-Origin': '*',
|
||||||
@@ -35,7 +35,7 @@ serve(async (req) => {
|
|||||||
data?: Record<string, unknown>;
|
data?: Record<string, unknown>;
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('Updating Novu subscriber:', { subscriberId, email, firstName, requestId: tracking.requestId });
|
edgeLogger.info('Updating Novu subscriber', { action: 'update_novu_subscriber', subscriberId, email, firstName, requestId: tracking.requestId });
|
||||||
|
|
||||||
const subscriber = await novu.subscribers.update(subscriberId, {
|
const subscriber = await novu.subscribers.update(subscriberId, {
|
||||||
email,
|
email,
|
||||||
@@ -46,7 +46,7 @@ serve(async (req) => {
|
|||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Subscriber updated successfully:', subscriber.data);
|
edgeLogger.info('Subscriber updated successfully', { action: 'update_novu_subscriber', subscriberId: subscriber.data._id });
|
||||||
|
|
||||||
endRequest(tracking, 200);
|
endRequest(tracking, 200);
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ serve(async (req) => {
|
|||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
||||||
console.error('Error updating Novu subscriber:', errorMessage);
|
edgeLogger.error('Error updating Novu subscriber', { action: 'update_novu_subscriber', error: errorMessage, requestId: tracking.requestId });
|
||||||
|
|
||||||
endRequest(tracking, 500, errorMessage);
|
endRequest(tracking, 500, errorMessage);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user