Fix: Reorder company generation before parks

This commit is contained in:
gpt-engineer-app[bot]
2025-10-10 17:27:55 +00:00
parent d9af90143d
commit b155d8c327

View File

@@ -334,6 +334,65 @@ Deno.serve(async (req) => {
return { submissionId, itemId, typeId: null };
}
// Create companies FIRST so parks can reference operators/owners
const companyTypes = ['manufacturer', 'operator', 'designer', 'property_owner'];
for (const compType of companyTypes) {
if (entityTypes.includes(compType + 's') || entityTypes.includes(compType === 'manufacturer' ? 'manufacturers' : compType === 'property_owner' ? 'property_owners' : compType + 's')) {
const count = Math.floor(plan.companies / 4);
for (let i = 0; i < count; i++) {
const level = getPopulationLevel(fieldDensity, i);
const companyData: any = {
name: `Test ${compType.replace('_', ' ')} ${i + 1}`,
slug: `test-${compType}-${i + 1}`,
company_type: compType
};
if (level >= 1) {
companyData.description = `Leading ${compType.replace('_', ' ')} in the amusement industry.`;
companyData.person_type = compType === 'designer' && Math.random() > 0.5 ? 'individual' : 'company';
}
if (level >= 2) {
companyData.founded_year = randomInt(1950, 2020);
const location = randomItem(CITIES);
companyData.headquarters_location = `${location.city}, ${location.country}`;
}
if (level >= 3) {
companyData.website_url = `https://test-${compType}-${i + 1}.example.com`;
companyData.logo_url = `https://imagedelivery.net/test/${compType}-${i + 1}/logo`;
}
if (level >= 4) {
companyData.card_image_id = `test-${compType}-card-${i + 1}`;
companyData.card_image_url = `https://imagedelivery.net/test/${compType}-${i + 1}/card`;
companyData.banner_image_id = `test-${compType}-banner-${i + 1}`;
companyData.banner_image_url = `https://imagedelivery.net/test/${compType}-${i + 1}/banner`;
}
const { itemId } = await createSubmission(user.id, compType, companyData);
// Track created submission item
createdSubmissionItems[compType].push(itemId);
// 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, itemId, sessionId);
}
createdCompanies[compType].push(companySlug);
summary.companies++;
}
}
}
// Create parks
if (entityTypes.includes('parks')) {
for (let i = 0; i < plan.parks; i++) {
@@ -429,64 +488,6 @@ Deno.serve(async (req) => {
}
}
// Create companies
const companyTypes = ['manufacturer', 'operator', 'designer', 'property_owner'];
for (const compType of companyTypes) {
if (entityTypes.includes(compType + 's') || entityTypes.includes(compType === 'manufacturer' ? 'manufacturers' : compType === 'property_owner' ? 'property_owners' : compType + 's')) {
const count = Math.floor(plan.companies / 4);
for (let i = 0; i < count; i++) {
const level = getPopulationLevel(fieldDensity, i);
const companyData: any = {
name: `Test ${compType.replace('_', ' ')} ${i + 1}`,
slug: `test-${compType}-${i + 1}`,
company_type: compType
};
if (level >= 1) {
companyData.description = `Leading ${compType.replace('_', ' ')} in the amusement industry.`;
companyData.person_type = compType === 'designer' && Math.random() > 0.5 ? 'individual' : 'company';
}
if (level >= 2) {
companyData.founded_year = randomInt(1950, 2020);
const location = randomItem(CITIES);
companyData.headquarters_location = `${location.city}, ${location.country}`;
}
if (level >= 3) {
companyData.website_url = `https://test-${compType}-${i + 1}.example.com`;
companyData.logo_url = `https://imagedelivery.net/test/${compType}-${i + 1}/logo`;
}
if (level >= 4) {
companyData.card_image_id = `test-${compType}-card-${i + 1}`;
companyData.card_image_url = `https://imagedelivery.net/test/${compType}-${i + 1}/card`;
companyData.banner_image_id = `test-${compType}-banner-${i + 1}`;
companyData.banner_image_url = `https://imagedelivery.net/test/${compType}-${i + 1}/banner`;
}
const { itemId } = await createSubmission(user.id, compType, companyData);
// Track created submission item
createdSubmissionItems[compType].push(itemId);
// 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, itemId, sessionId);
}
createdCompanies[compType].push(companySlug);
summary.companies++;
}
}
}
// Create rides
if (entityTypes.includes('rides') && includeDependencies && createdParks.length > 0) {