From db839ef95716504225f7cdd84729120b5eff7e12 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Wed, 1 Oct 2025 20:11:12 +0000 Subject: [PATCH] Fix content submissions constraint violation --- src/lib/companyHelpers.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/lib/companyHelpers.ts b/src/lib/companyHelpers.ts index 1f3b5db5..bee6e59c 100644 --- a/src/lib/companyHelpers.ts +++ b/src/lib/companyHelpers.ts @@ -22,8 +22,9 @@ export async function submitCompanyCreation( .from('content_submissions') .insert([{ user_id: userId, - submission_type: 'company_create', + submission_type: companyType, // Use entity-specific type: 'manufacturer', 'designer', 'operator', or 'property_owner' content: { + action: 'create', name: data.name, slug: data.slug, description: data.description, @@ -46,13 +47,24 @@ export async function submitCompanyUpdate( data: CompanyFormData, userId: string ) { + // Fetch existing company to get its type + const { data: existingCompany, error: fetchError } = await supabase + .from('companies') + .select('company_type') + .eq('id', companyId) + .single(); + + if (fetchError) throw fetchError; + if (!existingCompany) throw new Error('Company not found'); + // All users submit for moderation const { error } = await supabase .from('content_submissions') .insert([{ user_id: userId, - submission_type: 'company_edit', + submission_type: existingCompany.company_type, // Use entity-specific type from existing company content: { + action: 'edit', company_id: companyId, name: data.name, slug: data.slug,