mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 11:51:14 -05:00
Fix remaining console statements
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
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': '*',
|
||||
@@ -89,7 +90,7 @@ async function registerTestEntity(
|
||||
});
|
||||
|
||||
if (error && error.code !== '23505') { // Ignore unique constraint violations
|
||||
console.error(`Error registering ${entityType} ${slug}:`, error);
|
||||
edgeLogger.error(`Error registering ${entityType} ${slug}`, { error: error.message, entityType, slug });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +104,7 @@ async function getExistingTestEntities(
|
||||
.eq('entity_type', entityType);
|
||||
|
||||
if (error) {
|
||||
console.error(`Error fetching existing ${entityType}:`, error);
|
||||
edgeLogger.error(`Error fetching existing ${entityType}`, { error: error.message, entityType });
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -121,7 +122,7 @@ async function getPendingSubmissionItems(
|
||||
.eq('status', 'pending');
|
||||
|
||||
if (error) {
|
||||
console.error(`Error fetching pending ${itemType} items:`, error);
|
||||
edgeLogger.error(`Error fetching pending ${itemType} items`, { error: error.message, itemType });
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -129,6 +130,8 @@ async function getPendingSubmissionItems(
|
||||
}
|
||||
|
||||
Deno.serve(async (req) => {
|
||||
const tracking = startRequest();
|
||||
|
||||
if (req.method === 'OPTIONS') {
|
||||
return new Response(null, { headers: corsHeaders });
|
||||
}
|
||||
@@ -176,12 +179,17 @@ Deno.serve(async (req) => {
|
||||
stage
|
||||
}: SeedOptions = await req.json();
|
||||
|
||||
console.info('=== SEED DATA GENERATION DEBUG ===');
|
||||
console.info('Received entityTypes:', JSON.stringify(entityTypes));
|
||||
console.info('entityTypes is array:', Array.isArray(entityTypes));
|
||||
console.info('entityTypes length:', entityTypes?.length);
|
||||
console.info('Preset:', preset);
|
||||
console.info('===================================');
|
||||
edgeLogger.info('Seed data generation started', {
|
||||
requestId: tracking.requestId,
|
||||
entityTypes,
|
||||
preset,
|
||||
fieldDensity,
|
||||
includeDependencies,
|
||||
includeConflicts,
|
||||
includeVersionChains,
|
||||
includeEscalated,
|
||||
includeExpiredLocks
|
||||
});
|
||||
|
||||
const plan = PRESETS[preset];
|
||||
if (!plan) {
|
||||
@@ -212,7 +220,7 @@ Deno.serve(async (req) => {
|
||||
|
||||
// Load existing test entities from registry if includeDependencies is true
|
||||
if (includeDependencies) {
|
||||
console.log('Loading existing test entities from registry...');
|
||||
edgeLogger.info('Loading existing test entities from registry', { requestId: tracking.requestId });
|
||||
|
||||
const existingOperators = await getExistingTestEntities(supabase, 'operator');
|
||||
const existingOwners = await getExistingTestEntities(supabase, 'property_owner');
|
||||
@@ -260,8 +268,19 @@ Deno.serve(async (req) => {
|
||||
pendingParks.forEach(item => createdSubmissionItems.park.push(item.id));
|
||||
pendingRideModels.forEach(item => createdSubmissionItems.ride_model.push(item.id));
|
||||
|
||||
console.log(`Loaded ${existingOperators.length} operators, ${existingOwners.length} owners, ${existingManufacturers.length} manufacturers, ${existingDesigners.length} designers, ${existingParks.length} parks`);
|
||||
console.log(`Loaded ${pendingOperators.length} pending operators, ${pendingOwners.length} pending owners, ${pendingManufacturers.length} pending manufacturers, ${pendingDesigners.length} pending designers, ${pendingParks.length} pending parks`);
|
||||
edgeLogger.info('Loaded existing entities', {
|
||||
requestId: tracking.requestId,
|
||||
operators: existingOperators.length,
|
||||
owners: existingOwners.length,
|
||||
manufacturers: existingManufacturers.length,
|
||||
designers: existingDesigners.length,
|
||||
parks: existingParks.length,
|
||||
pendingOperators: pendingOperators.length,
|
||||
pendingOwners: pendingOwners.length,
|
||||
pendingManufacturers: pendingManufacturers.length,
|
||||
pendingDesigners: pendingDesigners.length,
|
||||
pendingParks: pendingParks.length
|
||||
});
|
||||
|
||||
// Add pending parks' slugs to createdParks for ride generation
|
||||
pendingParks.forEach(item => {
|
||||
@@ -271,7 +290,7 @@ Deno.serve(async (req) => {
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`Total parks available for rides: ${createdParks.length}`);
|
||||
edgeLogger.info('Parks available for rides', { requestId: tracking.requestId, count: createdParks.length });
|
||||
}
|
||||
|
||||
// Helper to create submission
|
||||
@@ -316,7 +335,7 @@ Deno.serve(async (req) => {
|
||||
|
||||
const { error: subError } = await supabase.from('content_submissions').insert(submissionData);
|
||||
if (subError) {
|
||||
console.error(`Error inserting content_submission for type ${type}:`, subError);
|
||||
edgeLogger.error('Error inserting content_submission', { type, error: subError.message });
|
||||
throw subError;
|
||||
}
|
||||
|
||||
@@ -350,8 +369,7 @@ Deno.serve(async (req) => {
|
||||
|
||||
const { data: insertedData, error: typeError } = await supabase.from(table).insert(typeData).select('id').single();
|
||||
if (typeError) {
|
||||
console.error(`Error inserting into ${table} for type ${type}:`, typeError);
|
||||
console.error('Data being inserted:', JSON.stringify(typeData, null, 2));
|
||||
edgeLogger.error('Error inserting into type table', { table, type, error: typeError.message, data: typeData });
|
||||
throw typeError;
|
||||
}
|
||||
return { submissionId, itemId, typeId: insertedData?.id };
|
||||
@@ -373,10 +391,6 @@ Deno.serve(async (req) => {
|
||||
|
||||
// Create companies FIRST so parks can reference operators/owners
|
||||
if (!stage || stage === 'companies') {
|
||||
console.info('=== COMPANY GENERATION CHECK ===');
|
||||
console.info('Entity types array:', JSON.stringify(entityTypes));
|
||||
console.info('Plan calls for companies:', plan.companies);
|
||||
|
||||
const companyTypes = ['manufacturer', 'operator', 'designer', 'property_owner'];
|
||||
|
||||
// First, determine which company types are selected
|
||||
@@ -384,14 +398,17 @@ Deno.serve(async (req) => {
|
||||
entityTypes.includes(pluralizeCompanyType(compType))
|
||||
);
|
||||
|
||||
console.info(`✓ Selected company types (${selectedCompanyTypes.length}):`, selectedCompanyTypes);
|
||||
edgeLogger.info('Company generation started', {
|
||||
requestId: tracking.requestId,
|
||||
entityTypes,
|
||||
planCompanies: plan.companies,
|
||||
selectedCompanyTypes
|
||||
});
|
||||
|
||||
// Calculate fair distribution: base amount per type + extras
|
||||
const basePerType = Math.floor(plan.companies / selectedCompanyTypes.length);
|
||||
const extras = plan.companies % selectedCompanyTypes.length;
|
||||
|
||||
console.info(`Distribution plan: ${basePerType} base per type, ${extras} extra(s) to first types`);
|
||||
|
||||
let companiesCreatedTotal = 0;
|
||||
|
||||
for (let typeIndex = 0; typeIndex < selectedCompanyTypes.length; typeIndex++) {
|
||||
@@ -401,10 +418,9 @@ Deno.serve(async (req) => {
|
||||
// Each type gets base amount, first N types get +1 extra
|
||||
const count = basePerType + (typeIndex < extras ? 1 : 0);
|
||||
|
||||
console.info(`✓ Generating ${count} companies of type ${compType}`);
|
||||
edgeLogger.info('Creating companies', { requestId: tracking.requestId, compType, count });
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
console.info(` Creating company ${i + 1}/${count} (type: ${compType})`);
|
||||
const level = getPopulationLevel(fieldDensity, i);
|
||||
const companyData: any = {
|
||||
name: `Test ${compType.replace('_', ' ')} ${i + 1}`,
|
||||
@@ -461,8 +477,8 @@ Deno.serve(async (req) => {
|
||||
|
||||
// Create parks
|
||||
if ((!stage || stage === 'parks') && entityTypes.includes('parks')) {
|
||||
edgeLogger.info('Creating parks', { requestId: tracking.requestId, count: plan.parks });
|
||||
for (let i = 0; i < plan.parks; i++) {
|
||||
console.log(` Creating park ${i + 1}/${plan.parks}`);
|
||||
const level = getPopulationLevel(fieldDensity, i);
|
||||
const shouldConflict = includeConflicts && createdParkSlugs.length > 0 && Math.random() < 0.15;
|
||||
const shouldVersionChain = includeVersionChains && createdParkSlugs.length > 0 && Math.random() < 0.15;
|
||||
@@ -824,20 +840,33 @@ Deno.serve(async (req) => {
|
||||
|
||||
const executionTime = Date.now() - startTime;
|
||||
|
||||
edgeLogger.info('Seed data generation completed', {
|
||||
requestId: tracking.requestId,
|
||||
duration: executionTime,
|
||||
summary,
|
||||
stage: stage || 'all'
|
||||
});
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: true,
|
||||
summary,
|
||||
time: (executionTime / 1000).toFixed(2),
|
||||
stage: stage || 'all'
|
||||
stage: stage || 'all',
|
||||
requestId: tracking.requestId
|
||||
}),
|
||||
{ headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
|
||||
);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Seed error:', error);
|
||||
const duration = endRequest(tracking);
|
||||
edgeLogger.error('Seed error', {
|
||||
requestId: tracking.requestId,
|
||||
duration,
|
||||
error: error.message
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({ error: error.message }),
|
||||
JSON.stringify({ error: error.message, requestId: tracking.requestId }),
|
||||
{ status: 500, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user