mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 22:51:12 -05:00
Implement the plan
This commit is contained in:
@@ -548,6 +548,81 @@ export async function submitRideModelCreation(
|
||||
return { submitted: true, submissionId: submissionData.id };
|
||||
}
|
||||
|
||||
/**
|
||||
* ⚠️ CRITICAL SECURITY PATTERN ⚠️
|
||||
*
|
||||
* Submits a ride model update through the moderation queue.
|
||||
* This is the ONLY correct way to update ride models.
|
||||
*/
|
||||
export async function submitRideModelUpdate(
|
||||
rideModelId: string,
|
||||
data: RideModelFormData,
|
||||
userId: string
|
||||
): Promise<{ submitted: boolean; submissionId: string }> {
|
||||
// Fetch existing ride model
|
||||
const { data: existingModel, error: fetchError } = await supabase
|
||||
.from('ride_models')
|
||||
.select('*')
|
||||
.eq('id', rideModelId)
|
||||
.single();
|
||||
|
||||
if (fetchError) throw new Error(`Failed to fetch ride model: ${fetchError.message}`);
|
||||
if (!existingModel) throw new Error('Ride model not found');
|
||||
|
||||
// Upload any pending local images first
|
||||
let processedImages = data.images;
|
||||
if (data.images?.uploaded && data.images.uploaded.length > 0) {
|
||||
try {
|
||||
const uploadedImages = await uploadPendingImages(data.images.uploaded);
|
||||
processedImages = {
|
||||
...data.images,
|
||||
uploaded: uploadedImages
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Failed to upload images for ride model update:', error);
|
||||
throw new Error('Failed to upload images. Please check your connection and try again.');
|
||||
}
|
||||
}
|
||||
|
||||
// Create the main submission record
|
||||
const { data: submissionData, error: submissionError } = await supabase
|
||||
.from('content_submissions')
|
||||
.insert({
|
||||
user_id: userId,
|
||||
submission_type: 'ride_model',
|
||||
content: {
|
||||
action: 'edit',
|
||||
ride_model_id: rideModelId
|
||||
},
|
||||
status: 'pending'
|
||||
})
|
||||
.select()
|
||||
.single();
|
||||
|
||||
if (submissionError) throw submissionError;
|
||||
|
||||
// Create the submission item with actual ride model data
|
||||
const { error: itemError } = await supabase
|
||||
.from('submission_items')
|
||||
.insert({
|
||||
submission_id: submissionData.id,
|
||||
item_type: 'ride_model',
|
||||
action_type: 'edit',
|
||||
item_data: {
|
||||
...data,
|
||||
ride_model_id: rideModelId,
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
original_data: JSON.parse(JSON.stringify(existingModel)),
|
||||
status: 'pending',
|
||||
order_index: 0
|
||||
});
|
||||
|
||||
if (itemError) throw itemError;
|
||||
|
||||
return { submitted: true, submissionId: submissionData.id };
|
||||
}
|
||||
|
||||
/**
|
||||
* ⚠️ CRITICAL SECURITY PATTERN ⚠️
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user