mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 00:11:15 -05:00
Fix content submissions constraint violation
This commit is contained in:
@@ -22,8 +22,9 @@ export async function submitCompanyCreation(
|
|||||||
.from('content_submissions')
|
.from('content_submissions')
|
||||||
.insert([{
|
.insert([{
|
||||||
user_id: userId,
|
user_id: userId,
|
||||||
submission_type: 'company_create',
|
submission_type: companyType, // Use entity-specific type: 'manufacturer', 'designer', 'operator', or 'property_owner'
|
||||||
content: {
|
content: {
|
||||||
|
action: 'create',
|
||||||
name: data.name,
|
name: data.name,
|
||||||
slug: data.slug,
|
slug: data.slug,
|
||||||
description: data.description,
|
description: data.description,
|
||||||
@@ -46,13 +47,24 @@ export async function submitCompanyUpdate(
|
|||||||
data: CompanyFormData,
|
data: CompanyFormData,
|
||||||
userId: string
|
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
|
// All users submit for moderation
|
||||||
const { error } = await supabase
|
const { error } = await supabase
|
||||||
.from('content_submissions')
|
.from('content_submissions')
|
||||||
.insert([{
|
.insert([{
|
||||||
user_id: userId,
|
user_id: userId,
|
||||||
submission_type: 'company_edit',
|
submission_type: existingCompany.company_type, // Use entity-specific type from existing company
|
||||||
content: {
|
content: {
|
||||||
|
action: 'edit',
|
||||||
company_id: companyId,
|
company_id: companyId,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
slug: data.slug,
|
slug: data.slug,
|
||||||
|
|||||||
Reference in New Issue
Block a user