From 7a1607f14962a05c3f18e6a13ea809439843a69a 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 18:15:56 +0000 Subject: [PATCH] Fix company type distribution logic --- supabase/functions/seed-test-data/index.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/supabase/functions/seed-test-data/index.ts b/supabase/functions/seed-test-data/index.ts index 911cf2fa..46e18438 100644 --- a/supabase/functions/seed-test-data/index.ts +++ b/supabase/functions/seed-test-data/index.ts @@ -376,18 +376,22 @@ Deno.serve(async (req) => { console.info(`✓ Selected company types (${selectedCompanyTypes.length}):`, 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++) { const compType = selectedCompanyTypes[typeIndex]; const pluralType = pluralizeCompanyType(compType); - // Calculate fair distribution: remaining companies / remaining types - const remainingCompanies = plan.companies - companiesCreatedTotal; - const remainingTypes = selectedCompanyTypes.length - typeIndex; - const count = Math.ceil(remainingCompanies / remainingTypes); + // 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} (${remainingCompanies} remaining, ${remainingTypes} types left)`); + console.info(`✓ Generating ${count} companies of type ${compType}`); for (let i = 0; i < count; i++) { console.info(` Creating company ${i + 1}/${count} (type: ${compType})`);