mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 17:31:13 -05:00
Refactor: Implement milestone moderation fixes
This commit is contained in:
@@ -1167,30 +1167,7 @@ export async function submitTimelineEventUpdate(
|
||||
throw new Error('Failed to fetch original timeline event');
|
||||
}
|
||||
|
||||
// Create submission
|
||||
const content: Json = {
|
||||
action: 'edit',
|
||||
event_id: eventId,
|
||||
entity_type: originalEvent.entity_type,
|
||||
};
|
||||
|
||||
const { data: submission, error: submissionError } = await supabase
|
||||
.from('content_submissions')
|
||||
.insert({
|
||||
user_id: userId,
|
||||
submission_type: 'milestone',
|
||||
content,
|
||||
status: 'pending',
|
||||
approval_mode: 'full',
|
||||
})
|
||||
.select()
|
||||
.single();
|
||||
|
||||
if (submissionError || !submission) {
|
||||
throw new Error('Failed to create timeline event update submission');
|
||||
}
|
||||
|
||||
// Create submission item
|
||||
// Prepare item data
|
||||
const itemData: Record<string, any> = {
|
||||
entity_type: originalEvent.entity_type,
|
||||
entity_id: originalEvent.entity_id,
|
||||
@@ -1205,28 +1182,41 @@ export async function submitTimelineEventUpdate(
|
||||
to_entity_id: data.to_entity_id,
|
||||
from_location_id: data.from_location_id,
|
||||
to_location_id: data.to_location_id,
|
||||
is_public: true, // All timeline events are public
|
||||
is_public: true,
|
||||
};
|
||||
|
||||
const { error: itemError } = await supabase
|
||||
.from('submission_items')
|
||||
.insert({
|
||||
submission_id: submission.id,
|
||||
item_type: 'milestone',
|
||||
action_type: 'edit',
|
||||
item_data: itemData as unknown as Json,
|
||||
original_data: originalEvent as unknown as Json,
|
||||
status: 'pending',
|
||||
order_index: 0,
|
||||
});
|
||||
// Use atomic RPC function to create submission and item together
|
||||
const { data: result, error: rpcError } = await supabase.rpc(
|
||||
'create_submission_with_items',
|
||||
{
|
||||
p_user_id: userId,
|
||||
p_submission_type: 'milestone',
|
||||
p_content: {
|
||||
action: 'edit',
|
||||
event_id: eventId,
|
||||
entity_type: originalEvent.entity_type,
|
||||
} as unknown as Json,
|
||||
p_items: [
|
||||
{
|
||||
item_type: 'milestone',
|
||||
action_type: 'edit',
|
||||
item_data: itemData,
|
||||
original_data: originalEvent,
|
||||
status: 'pending',
|
||||
order_index: 0,
|
||||
}
|
||||
] as unknown as Json[],
|
||||
}
|
||||
);
|
||||
|
||||
if (itemError) {
|
||||
throw new Error('Failed to submit timeline event update item');
|
||||
if (rpcError || !result) {
|
||||
console.error('Failed to create timeline event update:', rpcError);
|
||||
throw new Error('Failed to submit timeline event update');
|
||||
}
|
||||
|
||||
return {
|
||||
submitted: true,
|
||||
submissionId: submission.id,
|
||||
submissionId: result,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user