Approve timeline integration plan

This commit is contained in:
gpt-engineer-app[bot]
2025-10-15 19:44:17 +00:00
parent dfc89bd43b
commit 625ba1a8e2
13 changed files with 494 additions and 96 deletions

View File

@@ -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);
}