feat: Implement company management plan

This commit is contained in:
gpt-engineer-app[bot]
2025-09-30 03:01:53 +00:00
parent 93f86fc503
commit 556d1c5a97
11 changed files with 1938 additions and 9 deletions

86
src/lib/companyHelpers.ts Normal file
View File

@@ -0,0 +1,86 @@
import { supabase } from '@/integrations/supabase/client';
export interface CompanyFormData {
name: string;
slug: string;
description?: string;
person_type: 'company' | 'individual' | 'firm' | 'organization';
website_url?: string;
founded_year?: number;
headquarters_location?: string;
}
export async function submitCompanyCreation(
data: CompanyFormData,
companyType: 'manufacturer' | 'designer' | 'operator' | 'property_owner',
userId: string,
isModerator: boolean
) {
if (isModerator) {
// Moderators can create directly
const { data: newCompany, error } = await supabase
.from('companies')
.insert({
...data,
company_type: companyType
})
.select()
.single();
if (error) throw error;
return { company: newCompany, submitted: false };
} else {
// Regular users submit for moderation
const { error } = await supabase
.from('content_submissions')
.insert({
user_id: userId,
submission_type: 'company_create',
content: {
...data,
company_type: companyType
},
status: 'pending'
});
if (error) throw error;
return { company: null, submitted: true };
}
}
export async function submitCompanyUpdate(
companyId: string,
data: CompanyFormData,
userId: string,
isModerator: boolean
) {
if (isModerator) {
// Moderators can update directly
const { error } = await supabase
.from('companies')
.update({
...data,
updated_at: new Date().toISOString()
})
.eq('id', companyId);
if (error) throw error;
return { submitted: false };
} else {
// Regular users submit for moderation
const { error } = await supabase
.from('content_submissions')
.insert({
user_id: userId,
submission_type: 'company_edit',
content: {
company_id: companyId,
...data
},
status: 'pending'
});
if (error) throw error;
return { submitted: true };
}
}