mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 14:11:13 -05:00
Fix superuser release locks RPC
This commit is contained in:
@@ -1290,13 +1290,37 @@ export async function editSubmissionItem(
|
||||
if (updateError) throw updateError;
|
||||
|
||||
// Phase 4: Record edit history
|
||||
const { error: historyError } = await supabase
|
||||
const { data: historyData, error: historyError } = await supabase
|
||||
.from('item_edit_history')
|
||||
.insert({
|
||||
item_id: itemId,
|
||||
editor_id: userId,
|
||||
changes: changes,
|
||||
});
|
||||
edited_by: userId,
|
||||
changed_fields: Object.keys(changes),
|
||||
edit_reason: 'Direct edit by moderator',
|
||||
})
|
||||
.select('id')
|
||||
.single();
|
||||
|
||||
// Insert field changes relationally (NO JSON!)
|
||||
if (!historyError && historyData) {
|
||||
const fieldChanges = Object.entries(changes).map(([fieldName, change]: [string, any]) => ({
|
||||
edit_history_id: historyData.id,
|
||||
field_name: fieldName,
|
||||
old_value: String(change.old ?? ''),
|
||||
new_value: String(change.new ?? ''),
|
||||
}));
|
||||
|
||||
const { error: fieldChangesError } = await supabase
|
||||
.from('item_field_changes')
|
||||
.insert(fieldChanges);
|
||||
|
||||
if (fieldChangesError) {
|
||||
handleNonCriticalError(fieldChangesError, {
|
||||
action: 'Record Field Changes',
|
||||
metadata: { editHistoryId: historyData.id }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (historyError) {
|
||||
handleNonCriticalError(historyError, {
|
||||
@@ -1435,9 +1459,17 @@ export async function fetchEditHistory(itemId: string) {
|
||||
.from('item_edit_history')
|
||||
.select(`
|
||||
id,
|
||||
changes,
|
||||
item_id,
|
||||
edited_at,
|
||||
editor:profiles!item_edit_history_editor_id_fkey (
|
||||
edit_reason,
|
||||
changed_fields,
|
||||
field_changes:item_field_changes(
|
||||
id,
|
||||
field_name,
|
||||
old_value,
|
||||
new_value
|
||||
),
|
||||
editor:profiles!item_edit_history_edited_by_fkey(
|
||||
user_id,
|
||||
username,
|
||||
display_name,
|
||||
|
||||
Reference in New Issue
Block a user