mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 14:31:12 -05:00
Fix edge function console statements
This commit is contained in:
@@ -501,7 +501,7 @@ serve(withRateLimit(async (req) => {
|
||||
});
|
||||
|
||||
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
|
||||
@@ -512,7 +512,7 @@ serve(withRateLimit(async (req) => {
|
||||
});
|
||||
|
||||
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
|
||||
@@ -702,7 +702,7 @@ serve(withRateLimit(async (req) => {
|
||||
.eq('id', submissionId);
|
||||
|
||||
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
|
||||
@@ -731,7 +731,7 @@ serve(withRateLimit(async (req) => {
|
||||
});
|
||||
} catch (auditError) {
|
||||
// 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);
|
||||
@@ -754,10 +754,10 @@ serve(withRateLimit(async (req) => {
|
||||
} catch (error: unknown) {
|
||||
const duration = endRequest(tracking);
|
||||
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,
|
||||
userId: authenticatedUserId,
|
||||
timestamp: new Date().toISOString(),
|
||||
requestId: tracking.requestId,
|
||||
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
|
||||
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;
|
||||
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}`);
|
||||
} else {
|
||||
console.log('Creating new park');
|
||||
edgeLogger.info('Creating new park', { action: 'approval_create_park' });
|
||||
const normalizedData = normalizeStatusValue(data);
|
||||
const sanitizedData = sanitizeDateFields(normalizedData);
|
||||
const filteredData = filterDatabaseFields(sanitizedData, PARK_FIELDS);
|
||||
@@ -1089,7 +1089,7 @@ async function createPark(supabase: any, data: any): Promise<string> {
|
||||
|
||||
// Insert photos into photos table
|
||||
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++) {
|
||||
const photo = uploadedPhotos[i];
|
||||
if (photo.cloudflare_id && photo.url) {
|
||||
@@ -1106,7 +1106,7 @@ async function createPark(supabase: any, data: any): Promise<string> {
|
||||
});
|
||||
|
||||
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
|
||||
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;
|
||||
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
|
||||
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', {
|
||||
target_park_id: parkId
|
||||
});
|
||||
|
||||
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 {
|
||||
console.log('Creating new ride');
|
||||
edgeLogger.info('Creating new ride', { action: 'approval_create_ride' });
|
||||
const normalizedData = normalizeStatusValue(data);
|
||||
const sanitizedData = sanitizeDateFields(normalizedData);
|
||||
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
|
||||
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', {
|
||||
target_park_id: parkId
|
||||
});
|
||||
|
||||
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
|
||||
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++) {
|
||||
const photo = uploadedPhotos[i];
|
||||
if (photo.cloudflare_id && photo.url) {
|
||||
@@ -1231,7 +1231,7 @@ async function createRide(supabase: any, data: any): Promise<string> {
|
||||
});
|
||||
|
||||
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
|
||||
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) => ({
|
||||
ride_id: rideId,
|
||||
spec_name: spec.spec_name,
|
||||
@@ -1254,13 +1254,13 @@ async function createRide(supabase: any, data: any): Promise<string> {
|
||||
.insert(techSpecsToInsert);
|
||||
|
||||
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
|
||||
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) => ({
|
||||
ride_id: rideId,
|
||||
stat_name: stat.stat_name,
|
||||
@@ -1276,13 +1276,13 @@ async function createRide(supabase: any, data: any): Promise<string> {
|
||||
.insert(statsToInsert);
|
||||
|
||||
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
|
||||
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) => ({
|
||||
ride_id: rideId,
|
||||
former_name: name.former_name,
|
||||
@@ -1298,7 +1298,7 @@ async function createRide(supabase: any, data: any): Promise<string> {
|
||||
.insert(namesToInsert);
|
||||
|
||||
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;
|
||||
|
||||
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 });
|
||||
delete updateData.company_id;
|
||||
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}`);
|
||||
return companyId;
|
||||
} else {
|
||||
console.log('Creating new company');
|
||||
edgeLogger.info('Creating new company', { action: 'approval_create_company' });
|
||||
const companyData = sanitizeDateFields({ ...data, company_type: companyType });
|
||||
const filteredData = filterDatabaseFields(companyData, COMPANY_FIELDS);
|
||||
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
|
||||
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;
|
||||
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}`);
|
||||
} else {
|
||||
console.log('Creating new ride model');
|
||||
edgeLogger.info('Creating new ride model', { action: 'approval_create_model' });
|
||||
|
||||
// Validate required fields
|
||||
if (!data.manufacturer_id) {
|
||||
@@ -1408,7 +1408,7 @@ async function createRideModel(supabase: any, data: any): Promise<string> {
|
||||
|
||||
// Insert technical specifications
|
||||
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) => ({
|
||||
ride_model_id: rideModelId,
|
||||
spec_name: spec.spec_name,
|
||||
@@ -1423,7 +1423,7 @@ async function createRideModel(supabase: any, data: any): Promise<string> {
|
||||
.insert(techSpecsToInsert);
|
||||
|
||||
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);
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
@@ -1460,7 +1460,7 @@ function extractImageId(url: string): string {
|
||||
}
|
||||
|
||||
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
|
||||
.from('photos')
|
||||
.update({
|
||||
@@ -1472,7 +1472,7 @@ async function editPhoto(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
|
||||
.from('photos')
|
||||
.delete()
|
||||
@@ -1493,7 +1493,7 @@ async function createTimelineEvent(
|
||||
const eventId = data.id || data.event_id;
|
||||
|
||||
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)
|
||||
const updateData: any = {
|
||||
@@ -1524,7 +1524,7 @@ async function createTimelineEvent(
|
||||
if (error) throw new Error(`Failed to update timeline event: ${error.message}`);
|
||||
return eventId;
|
||||
} else {
|
||||
console.log('Creating new timeline event');
|
||||
edgeLogger.info('Creating new timeline event', { action: 'approval_create_timeline' });
|
||||
|
||||
const eventData = {
|
||||
entity_id: data.entity_id,
|
||||
|
||||
Reference in New Issue
Block a user