Fix content submissions constraint violation

This commit is contained in:
gpt-engineer-app[bot]
2025-10-01 20:11:12 +00:00
parent d100e0188b
commit db839ef957

View File

@@ -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,