From b256b6f9abc14d3cdf3a416ed1dc2b54a2ee5958 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Fri, 10 Oct 2025 17:52:50 +0000 Subject: [PATCH] Fix company count calculation --- supabase/functions/seed-test-data/index.ts | 125 ++++++++++++--------- 1 file changed, 69 insertions(+), 56 deletions(-) diff --git a/supabase/functions/seed-test-data/index.ts b/supabase/functions/seed-test-data/index.ts index 578fe13c..30ad5903 100644 --- a/supabase/functions/seed-test-data/index.ts +++ b/supabase/functions/seed-test-data/index.ts @@ -358,66 +358,79 @@ Deno.serve(async (req) => { console.info('Plan calls for companies:', plan.companies); const companyTypes = ['manufacturer', 'operator', 'designer', 'property_owner']; - for (const compType of companyTypes) { + + // First, determine which company types are selected + const selectedCompanyTypes = companyTypes.filter(compType => + entityTypes.includes(pluralizeCompanyType(compType)) + ); + + console.info(`✓ Selected company types (${selectedCompanyTypes.length}):`, selectedCompanyTypes); + + let companiesCreatedTotal = 0; + + for (let typeIndex = 0; typeIndex < selectedCompanyTypes.length; typeIndex++) { + const compType = selectedCompanyTypes[typeIndex]; const pluralType = pluralizeCompanyType(compType); - const shouldGenerate = entityTypes.includes(pluralType); - console.info(`Checking ${compType} → ${pluralType}: ${shouldGenerate}`); - if (shouldGenerate) { - const count = Math.floor(plan.companies / 4); - console.info(`✓ Generating ${count} companies of type ${compType}`); - 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}`, - slug: `test-${compType}-${i + 1}`, - company_type: compType - }; + // Calculate fair distribution: remaining companies / remaining types + const remainingCompanies = plan.companies - companiesCreatedTotal; + const remainingTypes = selectedCompanyTypes.length - typeIndex; + const count = Math.ceil(remainingCompanies / remainingTypes); + + console.info(`✓ Generating ${count} companies of type ${compType} (${remainingCompanies} remaining, ${remainingTypes} types left)`); + + 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}`, + 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++; + 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++; + companiesCreatedTotal++; } }