mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 14:11:13 -05:00
Refactor: Unify moderation queue for all entities
This commit is contained in:
@@ -15,14 +15,15 @@ export interface CompanyFormData {
|
||||
export async function submitCompanyCreation(
|
||||
data: CompanyFormData,
|
||||
companyType: 'manufacturer' | 'designer' | 'operator' | 'property_owner',
|
||||
userId: string,
|
||||
isModerator: boolean
|
||||
userId: string
|
||||
) {
|
||||
if (isModerator) {
|
||||
// Moderators can create directly
|
||||
const { data: newCompany, error } = await supabase
|
||||
.from('companies')
|
||||
.insert({
|
||||
// All users submit for moderation
|
||||
const { error } = await supabase
|
||||
.from('content_submissions')
|
||||
.insert([{
|
||||
user_id: userId,
|
||||
submission_type: 'company_create',
|
||||
content: {
|
||||
name: data.name,
|
||||
slug: data.slug,
|
||||
description: data.description,
|
||||
@@ -30,50 +31,29 @@ export async function submitCompanyCreation(
|
||||
website_url: data.website_url,
|
||||
founded_year: data.founded_year,
|
||||
headquarters_location: data.headquarters_location,
|
||||
company_type: companyType
|
||||
})
|
||||
.select()
|
||||
.single();
|
||||
company_type: companyType,
|
||||
images: data.images as any // Include image assignments in submission
|
||||
} as any,
|
||||
status: 'pending'
|
||||
}]);
|
||||
|
||||
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: {
|
||||
name: data.name,
|
||||
slug: data.slug,
|
||||
description: data.description,
|
||||
person_type: data.person_type,
|
||||
website_url: data.website_url,
|
||||
founded_year: data.founded_year,
|
||||
headquarters_location: data.headquarters_location,
|
||||
company_type: companyType,
|
||||
images: data.images as any // Include image assignments in submission
|
||||
} as any,
|
||||
status: 'pending'
|
||||
}]);
|
||||
|
||||
if (error) throw error;
|
||||
return { company: null, submitted: true };
|
||||
}
|
||||
if (error) throw error;
|
||||
return { submitted: true };
|
||||
}
|
||||
|
||||
export async function submitCompanyUpdate(
|
||||
companyId: string,
|
||||
data: CompanyFormData,
|
||||
userId: string,
|
||||
isModerator: boolean
|
||||
userId: string
|
||||
) {
|
||||
if (isModerator) {
|
||||
// Moderators can update directly
|
||||
const { error } = await supabase
|
||||
.from('companies')
|
||||
.update({
|
||||
// All users submit for moderation
|
||||
const { error } = await supabase
|
||||
.from('content_submissions')
|
||||
.insert([{
|
||||
user_id: userId,
|
||||
submission_type: 'company_edit',
|
||||
content: {
|
||||
company_id: companyId,
|
||||
name: data.name,
|
||||
slug: data.slug,
|
||||
description: data.description,
|
||||
@@ -81,34 +61,11 @@ export async function submitCompanyUpdate(
|
||||
website_url: data.website_url,
|
||||
founded_year: data.founded_year,
|
||||
headquarters_location: data.headquarters_location,
|
||||
updated_at: new Date().toISOString()
|
||||
})
|
||||
.eq('id', companyId);
|
||||
images: data.images as any // Include image role assignments in submission
|
||||
} as any,
|
||||
status: 'pending'
|
||||
}]);
|
||||
|
||||
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,
|
||||
name: data.name,
|
||||
slug: data.slug,
|
||||
description: data.description,
|
||||
person_type: data.person_type,
|
||||
website_url: data.website_url,
|
||||
founded_year: data.founded_year,
|
||||
headquarters_location: data.headquarters_location,
|
||||
images: data.images as any // Include image role assignments in submission
|
||||
} as any,
|
||||
status: 'pending'
|
||||
}]);
|
||||
|
||||
if (error) throw error;
|
||||
return { submitted: true };
|
||||
}
|
||||
if (error) throw error;
|
||||
return { submitted: true };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user