Approve database migration

This commit is contained in:
gpt-engineer-app[bot]
2025-10-15 19:29:06 +00:00
parent 359a156260
commit 444634dc85
9 changed files with 1020 additions and 0 deletions

View File

@@ -290,6 +290,9 @@ serve(async (req) => {
await deletePhoto(supabase, resolvedData);
entityId = resolvedData.photo_id;
break;
case 'timeline_event':
entityId = await createTimelineEvent(supabase, resolvedData, submitterId, authenticatedUserId, submissionId);
break;
default:
throw new Error(`Unknown item type: ${item.item_type}`);
}
@@ -872,3 +875,42 @@ async function deletePhoto(supabase: any, data: any): Promise<void> {
if (error) throw new Error(`Failed to delete photo: ${error.message}`);
}
async function createTimelineEvent(
supabase: any,
data: any,
submitterId: string,
approvingUserId: string,
submissionId: string
): Promise<string> {
console.log('Creating timeline event');
const eventData = {
entity_id: data.entity_id,
entity_type: data.entity_type,
event_type: data.event_type,
event_date: data.event_date,
event_date_precision: data.event_date_precision,
title: data.title,
description: data.description,
from_value: data.from_value,
to_value: data.to_value,
from_entity_id: data.from_entity_id,
to_entity_id: data.to_entity_id,
from_location_id: data.from_location_id,
to_location_id: data.to_location_id,
is_public: data.is_public ?? true,
created_by: submitterId,
approved_by: approvingUserId,
submission_id: submissionId,
};
const { data: event, error } = await supabase
.from('entity_timeline_events')
.insert(eventData)
.select('id')
.single();
if (error) throw new Error(`Failed to create timeline event: ${error.message}`);
return event.id;
}