mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 17:31:15 -05:00
Refactor: Approve lovable tool use
This commit is contained in:
@@ -70,6 +70,43 @@ function getPopulationLevel(fieldDensity: string, index: number): number {
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Registry helper functions for cascading test data
|
||||
async function registerTestEntity(
|
||||
supabase: any,
|
||||
entityType: string,
|
||||
slug: string,
|
||||
entityId: string,
|
||||
sessionId: string
|
||||
) {
|
||||
const { error } = await supabase.from('test_data_registry').insert({
|
||||
entity_type: entityType,
|
||||
entity_slug: slug,
|
||||
entity_id: entityId,
|
||||
test_session_id: sessionId
|
||||
});
|
||||
|
||||
if (error && error.code !== '23505') { // Ignore unique constraint violations
|
||||
console.error(`Error registering ${entityType} ${slug}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
async function getExistingTestEntities(
|
||||
supabase: any,
|
||||
entityType: string
|
||||
): Promise<Array<{ slug: string; entity_id: string }>> {
|
||||
const { data, error } = await supabase
|
||||
.from('test_data_registry')
|
||||
.select('entity_slug, entity_id')
|
||||
.eq('entity_type', entityType);
|
||||
|
||||
if (error) {
|
||||
console.error(`Error fetching existing ${entityType}:`, error);
|
||||
return [];
|
||||
}
|
||||
|
||||
return data || [];
|
||||
}
|
||||
|
||||
Deno.serve(async (req) => {
|
||||
if (req.method === 'OPTIONS') {
|
||||
return new Response(null, { headers: corsHeaders });
|
||||
@@ -126,12 +163,36 @@ Deno.serve(async (req) => {
|
||||
}
|
||||
|
||||
const startTime = Date.now();
|
||||
const sessionId = crypto.randomUUID(); // Unique ID for this generation session
|
||||
const summary = { parks: 0, rides: 0, companies: 0, rideModels: 0, photos: 0, totalPhotoItems: 0, conflicts: 0, versionChains: 0 };
|
||||
const createdParks: string[] = [];
|
||||
const createdCompanies: Record<string, string[]> = { manufacturer: [], operator: [], designer: [], property_owner: [] };
|
||||
const createdParkSlugs: string[] = [];
|
||||
const createdRideSlugs: string[] = [];
|
||||
|
||||
// Load existing test entities from registry if includeDependencies is true
|
||||
if (includeDependencies) {
|
||||
console.log('Loading existing test entities from registry...');
|
||||
|
||||
const existingOperators = await getExistingTestEntities(supabase, 'operator');
|
||||
const existingOwners = await getExistingTestEntities(supabase, 'property_owner');
|
||||
const existingManufacturers = await getExistingTestEntities(supabase, 'manufacturer');
|
||||
const existingDesigners = await getExistingTestEntities(supabase, 'designer');
|
||||
const existingParks = await getExistingTestEntities(supabase, 'park');
|
||||
const existingRideModels = await getExistingTestEntities(supabase, 'ride_model');
|
||||
|
||||
existingOperators.forEach(op => createdCompanies.operator.push(op.slug));
|
||||
existingOwners.forEach(own => createdCompanies.property_owner.push(own.slug));
|
||||
existingManufacturers.forEach(mfg => createdCompanies.manufacturer.push(mfg.slug));
|
||||
existingDesigners.forEach(des => createdCompanies.designer.push(des.slug));
|
||||
existingParks.forEach(park => {
|
||||
createdParks.push(park.slug);
|
||||
createdParkSlugs.push(park.slug);
|
||||
});
|
||||
|
||||
console.log(`Loaded ${existingOperators.length} operators, ${existingOwners.length} owners, ${existingManufacturers.length} manufacturers, ${existingDesigners.length} designers, ${existingParks.length} parks`);
|
||||
}
|
||||
|
||||
// Helper to create submission
|
||||
async function createSubmission(userId: string, type: string, itemData: any, options: { escalated?: boolean; expiredLock?: boolean } = {}) {
|
||||
const submissionId = crypto.randomUUID();
|
||||
@@ -265,6 +326,18 @@ Deno.serve(async (req) => {
|
||||
};
|
||||
|
||||
await createSubmission(user.id, 'park', parkData, options);
|
||||
|
||||
// Register newly created park in the registry
|
||||
const { data: approvedPark } = await supabase
|
||||
.from('parks')
|
||||
.select('id')
|
||||
.eq('slug', slug)
|
||||
.maybeSingle();
|
||||
|
||||
if (approvedPark) {
|
||||
await registerTestEntity(supabase, 'park', slug, approvedPark.id, sessionId);
|
||||
}
|
||||
|
||||
createdParks.push(slug);
|
||||
if (!shouldConflict && !shouldVersionChain) {
|
||||
createdParkSlugs.push(slug);
|
||||
@@ -310,7 +383,20 @@ Deno.serve(async (req) => {
|
||||
}
|
||||
|
||||
await createSubmission(user.id, compType, companyData);
|
||||
createdCompanies[compType].push(`test-${compType}-${i + 1}`);
|
||||
|
||||
// Register newly created company in the registry
|
||||
const companySlug = `test-${compType}-${i + 1}`;
|
||||
const { data: approvedCompany } = await supabase
|
||||
.from('companies')
|
||||
.select('id')
|
||||
.eq('slug', companySlug)
|
||||
.maybeSingle();
|
||||
|
||||
if (approvedCompany) {
|
||||
await registerTestEntity(supabase, compType, companySlug, approvedCompany.id, sessionId);
|
||||
}
|
||||
|
||||
createdCompanies[compType].push(companySlug);
|
||||
summary.companies++;
|
||||
}
|
||||
}
|
||||
@@ -422,6 +508,17 @@ Deno.serve(async (req) => {
|
||||
}
|
||||
}
|
||||
|
||||
// Register newly created ride in the registry
|
||||
const { data: approvedRide } = await supabase
|
||||
.from('rides')
|
||||
.select('id')
|
||||
.eq('slug', slug)
|
||||
.maybeSingle();
|
||||
|
||||
if (approvedRide) {
|
||||
await registerTestEntity(supabase, 'ride', slug, approvedRide.id, sessionId);
|
||||
}
|
||||
|
||||
if (!shouldConflict && !shouldVersionChain) {
|
||||
createdRideSlugs.push(slug);
|
||||
}
|
||||
@@ -459,6 +556,19 @@ Deno.serve(async (req) => {
|
||||
}
|
||||
|
||||
await createSubmission(user.id, 'ride_model', modelData);
|
||||
|
||||
// Register newly created ride model in the registry
|
||||
const modelSlug = `test-model-${i + 1}`;
|
||||
const { data: approvedModel } = await supabase
|
||||
.from('ride_models')
|
||||
.select('id')
|
||||
.eq('slug', modelSlug)
|
||||
.maybeSingle();
|
||||
|
||||
if (approvedModel) {
|
||||
await registerTestEntity(supabase, 'ride_model', modelSlug, approvedModel.id, sessionId);
|
||||
}
|
||||
|
||||
summary.rideModels++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user