mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 09:31:12 -05:00
Add action_type to submission items
This commit is contained in:
@@ -133,17 +133,22 @@ async function detectPhotoChanges(submissionId: string): Promise<PhotoChange[]>
|
||||
* Detects what changed between original_data and item_data
|
||||
*/
|
||||
export async function detectChanges(
|
||||
item: { item_data?: any; original_data?: any; item_type: string },
|
||||
item: { item_data?: any; original_data?: any; item_type: string; action_type?: string },
|
||||
submissionId?: string
|
||||
): Promise<ChangesSummary> {
|
||||
const itemData = item.item_data || {};
|
||||
const originalData = item.original_data || {};
|
||||
|
||||
// Determine action type - special handling for photo_delete
|
||||
// Determine action type - prioritize explicit action_type field to preserve submission intent
|
||||
let action: 'create' | 'edit' | 'delete' = 'edit';
|
||||
|
||||
if (item.item_type === 'photo_delete' || itemData.action === 'delete' || itemData.deleted) {
|
||||
action = 'delete';
|
||||
} else if (item.action_type) {
|
||||
// Use explicit action_type if set (preserves original submission intent even after moderator edits)
|
||||
action = item.action_type as 'create' | 'edit' | 'delete';
|
||||
} else if (!originalData || Object.keys(originalData).length === 0) {
|
||||
// Fall back to inference for backwards compatibility
|
||||
action = 'create';
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ export interface SubmissionItemWithDeps {
|
||||
item_type: string;
|
||||
item_data: any;
|
||||
original_data: any;
|
||||
action_type?: 'create' | 'edit' | 'delete';
|
||||
status: 'pending' | 'approved' | 'rejected';
|
||||
depends_on: string | null;
|
||||
order_index: number;
|
||||
@@ -1050,6 +1051,10 @@ export async function editSubmissionItem(
|
||||
// Preserve original_data if not already set
|
||||
const originalData = currentItem.original_data || currentItem.item_data;
|
||||
|
||||
// Determine original action type - preserve submission intent
|
||||
const originalAction = currentItem.action_type ||
|
||||
(currentItem.original_data && Object.keys(currentItem.original_data).length > 0) ? 'edit' : 'create';
|
||||
|
||||
if (isModerator) {
|
||||
// Moderators can edit directly
|
||||
const { error: updateError } = await supabase
|
||||
@@ -1057,6 +1062,7 @@ export async function editSubmissionItem(
|
||||
.update({
|
||||
item_data: newData,
|
||||
original_data: originalData,
|
||||
action_type: originalAction, // Preserve original submission intent
|
||||
updated_at: new Date().toISOString(),
|
||||
})
|
||||
.eq('id', itemId);
|
||||
@@ -1083,6 +1089,7 @@ export async function editSubmissionItem(
|
||||
.update({
|
||||
item_data: newData,
|
||||
original_data: originalData,
|
||||
action_type: originalAction, // Preserve original submission intent
|
||||
updated_at: new Date().toISOString(),
|
||||
})
|
||||
.eq('id', itemId);
|
||||
|
||||
Reference in New Issue
Block a user