mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 16:11:13 -05:00
Approve timeline integration plan
This commit is contained in:
@@ -1081,3 +1081,52 @@ export async function submitTimelineEventUpdate(
|
||||
submissionId: submission.id,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a timeline event (only pending/own events)
|
||||
* @param eventId - Timeline event ID
|
||||
* @param userId - Current user ID
|
||||
* @throws Error if event not found or cannot be deleted
|
||||
*/
|
||||
export async function deleteTimelineEvent(
|
||||
eventId: string,
|
||||
userId: string
|
||||
): Promise<void> {
|
||||
// First verify the event exists and user has permission
|
||||
const { data: event, error: fetchError } = await supabase
|
||||
.from('entity_timeline_events')
|
||||
.select('created_by, approved_by')
|
||||
.eq('id', eventId)
|
||||
.single();
|
||||
|
||||
if (fetchError) {
|
||||
console.error('Error fetching timeline event:', fetchError);
|
||||
throw new Error('Timeline event not found');
|
||||
}
|
||||
|
||||
if (!event) {
|
||||
throw new Error('Timeline event not found');
|
||||
}
|
||||
|
||||
// Only allow deletion of own unapproved events
|
||||
if (event.created_by !== userId) {
|
||||
throw new Error('You can only delete your own timeline events');
|
||||
}
|
||||
|
||||
if (event.approved_by !== null) {
|
||||
throw new Error('Cannot delete approved timeline events');
|
||||
}
|
||||
|
||||
// Delete the event
|
||||
const { error: deleteError } = await supabase
|
||||
.from('entity_timeline_events')
|
||||
.delete()
|
||||
.eq('id', eventId);
|
||||
|
||||
if (deleteError) {
|
||||
console.error('Error deleting timeline event:', deleteError);
|
||||
throw new Error('Failed to delete timeline event');
|
||||
}
|
||||
|
||||
console.log('✅ Timeline event deleted:', eventId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user