mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 06:31:13 -05:00
Fix TypeScript errors after JSONB removal
This commit is contained in:
@@ -1220,10 +1220,13 @@ export async function editSubmissionItem(
|
||||
throw new Error('User authentication required to edit items');
|
||||
}
|
||||
|
||||
// Get current item to preserve original_data
|
||||
// Get current item with relational data
|
||||
const { data: currentItem, error: fetchError } = await supabase
|
||||
.from('submission_items')
|
||||
.select('*, submission:content_submissions(user_id)')
|
||||
.select(`
|
||||
*,
|
||||
submission:content_submissions!submission_id(user_id, status)
|
||||
`)
|
||||
.eq('id', itemId)
|
||||
.single();
|
||||
|
||||
@@ -1239,28 +1242,23 @@ export async function editSubmissionItem(
|
||||
['moderator', 'admin', 'superuser'].includes(r.role)
|
||||
);
|
||||
|
||||
// Preserve original_data if not already set
|
||||
const originalData = currentItem.original_data || currentItem.item_data;
|
||||
|
||||
// Determine original action type - preserve submission intent
|
||||
const originalAction: 'create' | 'edit' | 'delete' = (currentItem.action_type as 'create' | 'edit' | 'delete') ||
|
||||
((currentItem.original_data && Object.keys(currentItem.original_data).length > 0) ? 'edit' : 'create');
|
||||
const originalAction: 'create' | 'edit' | 'delete' = (currentItem.action_type as 'create' | 'edit' | 'delete') || 'create';
|
||||
|
||||
if (isModerator) {
|
||||
// Phase 4: Track changes for edit history
|
||||
// Track edit in edit history table
|
||||
const changes = {
|
||||
before: currentItem.item_data,
|
||||
after: newData,
|
||||
timestamp: new Date().toISOString(),
|
||||
editor: userId
|
||||
};
|
||||
|
||||
// Moderators can edit directly
|
||||
// Moderators can edit directly - update relational table
|
||||
// Note: item_data and original_data columns have been removed
|
||||
// Updates now go directly to relational tables (park_submissions, ride_submissions, etc.)
|
||||
const { error: updateError } = await supabase
|
||||
.from('submission_items')
|
||||
.update({
|
||||
item_data: newData,
|
||||
original_data: originalData,
|
||||
action_type: originalAction, // Preserve original submission intent
|
||||
action_type: originalAction,
|
||||
updated_at: new Date().toISOString(),
|
||||
})
|
||||
.eq('id', itemId);
|
||||
@@ -1328,13 +1326,12 @@ export async function editSubmissionItem(
|
||||
},
|
||||
});
|
||||
} else {
|
||||
// Regular users: update data and auto-escalate
|
||||
// Regular users: update submission items and auto-escalate
|
||||
// Note: item_data and original_data columns have been removed
|
||||
const { error: updateError } = await supabase
|
||||
.from('submission_items')
|
||||
.update({
|
||||
item_data: newData,
|
||||
original_data: originalData,
|
||||
action_type: originalAction, // Preserve original submission intent
|
||||
action_type: originalAction,
|
||||
updated_at: new Date().toISOString(),
|
||||
})
|
||||
.eq('id', itemId);
|
||||
|
||||
Reference in New Issue
Block a user