mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 08:51:16 -05:00
Fix moderation queue issues
This commit is contained in:
@@ -163,15 +163,40 @@ export function buildModerationItem(
|
||||
id: submission.id,
|
||||
type: 'content_submission',
|
||||
content: submission.content,
|
||||
created_at: submission.created_at,
|
||||
user_id: submission.user_id,
|
||||
|
||||
// Handle both created_at (from view) and submitted_at (from realtime)
|
||||
created_at: submission.created_at || submission.submitted_at,
|
||||
submitted_at: submission.submitted_at,
|
||||
|
||||
// Support both user_id and submitter_id
|
||||
user_id: submission.user_id || submission.submitter_id,
|
||||
submitter_id: submission.submitter_id || submission.user_id,
|
||||
|
||||
status: submission.status,
|
||||
submission_type: submission.submission_type,
|
||||
user_profile: profile ? {
|
||||
|
||||
// Use new profile structure from view if available
|
||||
submitter_profile: submission.submitter_profile || (profile ? {
|
||||
user_id: submission.user_id || submission.submitter_id,
|
||||
username: profile.username,
|
||||
display_name: profile.display_name,
|
||||
avatar_url: profile.avatar_url,
|
||||
} : undefined,
|
||||
} : undefined),
|
||||
|
||||
reviewer_profile: submission.reviewer_profile,
|
||||
assigned_profile: submission.assigned_profile,
|
||||
|
||||
// Legacy support: create user_profile from submitter_profile
|
||||
user_profile: submission.submitter_profile ? {
|
||||
username: submission.submitter_profile.username,
|
||||
display_name: submission.submitter_profile.display_name,
|
||||
avatar_url: submission.submitter_profile.avatar_url,
|
||||
} : (profile ? {
|
||||
username: profile.username,
|
||||
display_name: profile.display_name,
|
||||
avatar_url: profile.avatar_url,
|
||||
} : undefined),
|
||||
|
||||
entity_name: entityName || (submission.content as SubmissionContent)?.name || 'Unknown',
|
||||
park_name: parkName,
|
||||
reviewed_at: submission.reviewed_at || undefined,
|
||||
|
||||
@@ -8,8 +8,16 @@
|
||||
import { z } from 'zod';
|
||||
import { logger } from '@/lib/logger';
|
||||
|
||||
// Profile schema
|
||||
// Profile schema (matches database JSONB structure)
|
||||
const ProfileSchema = z.object({
|
||||
user_id: z.string().uuid(),
|
||||
username: z.string(),
|
||||
display_name: z.string().optional().nullable(),
|
||||
avatar_url: z.string().optional().nullable(),
|
||||
});
|
||||
|
||||
// Legacy profile schema (for backward compatibility)
|
||||
const LegacyProfileSchema = z.object({
|
||||
username: z.string(),
|
||||
display_name: z.string().optional().nullable(),
|
||||
avatar_url: z.string().optional().nullable(),
|
||||
@@ -31,19 +39,42 @@ export const ModerationItemSchema = z.object({
|
||||
status: z.enum(['pending', 'approved', 'rejected', 'partially_approved', 'flagged']),
|
||||
type: z.string(),
|
||||
submission_type: z.string(),
|
||||
|
||||
// Accept both created_at and submitted_at for flexibility
|
||||
created_at: z.string(),
|
||||
submitted_at: z.string().optional(),
|
||||
updated_at: z.string().optional().nullable(),
|
||||
reviewed_at: z.string().optional().nullable(),
|
||||
|
||||
content: z.record(z.string(), z.any()),
|
||||
submitter_id: z.string().uuid(),
|
||||
|
||||
// User fields (support both old and new naming)
|
||||
submitter_id: z.string().uuid().optional(),
|
||||
user_id: z.string().uuid().optional(),
|
||||
|
||||
assigned_to: z.string().uuid().optional().nullable(),
|
||||
locked_until: z.string().optional().nullable(),
|
||||
reviewed_at: z.string().optional().nullable(),
|
||||
reviewed_by: z.string().uuid().optional().nullable(),
|
||||
reviewer_notes: z.string().optional().nullable(),
|
||||
submission_items: z.array(SubmissionItemSchema).optional(),
|
||||
|
||||
// Escalation fields
|
||||
escalated: z.boolean().optional().default(false),
|
||||
escalation_reason: z.string().optional().nullable(),
|
||||
|
||||
// Profile objects (new structure from view)
|
||||
submitter_profile: ProfileSchema.optional().nullable(),
|
||||
assigned_profile: ProfileSchema.optional().nullable(),
|
||||
reviewer_profile: ProfileSchema.optional().nullable(),
|
||||
|
||||
// Legacy profile support
|
||||
user_profile: LegacyProfileSchema.optional().nullable(),
|
||||
|
||||
// Submission items
|
||||
submission_items: z.array(SubmissionItemSchema).optional(),
|
||||
|
||||
// Entity names
|
||||
entity_name: z.string().optional(),
|
||||
park_name: z.string().optional(),
|
||||
});
|
||||
|
||||
export const ModerationItemArraySchema = z.array(ModerationItemSchema);
|
||||
|
||||
Reference in New Issue
Block a user