Fix moderation queue issues

This commit is contained in:
gpt-engineer-app[bot]
2025-11-03 16:43:21 +00:00
parent 47b317b7c0
commit eee4b1c626
7 changed files with 220 additions and 27 deletions

View File

@@ -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);