Fix data structure and add backward compatibility

This commit is contained in:
gpt-engineer-app[bot]
2025-09-29 18:21:51 +00:00
parent aaa1c633f6
commit 1b6da4fffa
2 changed files with 38 additions and 12 deletions

View File

@@ -169,11 +169,25 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
for (const submission of submissionsWithEntities) {
if (submission.submission_type === 'photo' && submission.content && typeof submission.content === 'object') {
const contentObj = submission.content as any;
const context = contentObj.context;
const rideId = contentObj.ride_id;
const parkId = contentObj.park_id;
if (context === 'ride' && rideId) {
// Handle both old format (context as object) and new format (context as string)
let contextType = null;
let rideId = null;
let parkId = null;
if (typeof contentObj.context === 'object' && contentObj.context !== null) {
// OLD FORMAT: context is an object like {ride_id: "...", park_id: "..."}
rideId = contentObj.context.ride_id;
parkId = contentObj.context.park_id;
contextType = rideId ? 'ride' : parkId ? 'park' : null;
} else if (typeof contentObj.context === 'string') {
// NEW FORMAT: context is a string, IDs are at top level
contextType = contentObj.context;
rideId = contentObj.ride_id;
parkId = contentObj.park_id;
}
if (contextType === 'ride' && rideId) {
const { data: rideData } = await supabase
.from('rides')
.select(`
@@ -189,7 +203,7 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
(submission as any).entity_name = rideData.name;
(submission as any).park_name = rideData.parks?.name;
}
} else if (context === 'park' && parkId) {
} else if (contextType === 'park' && parkId) {
const { data: parkData } = await supabase
.from('parks')
.select('name')
@@ -852,15 +866,27 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
<div className="mt-3 pt-3 border-t text-xs text-muted-foreground">
<div className="flex justify-between">
<span className="font-medium">Context:</span>
<span className="capitalize">{item.content.content.context}</span>
<span className="capitalize">
{typeof item.content.content.context === 'object'
? (item.content.content.context.ride_id ? 'ride' :
item.content.content.context.park_id ? 'park' : 'unknown')
: item.content.content.context}
</span>
</div>
{item.entity_name && (
<div className="flex justify-between">
<span className="font-medium text-xs">{item.content.content.context === 'ride' ? 'Ride:' : 'Park:'}</span>
<span className="font-medium text-xs">
{(typeof item.content.content.context === 'object'
? (item.content.content.context.ride_id ? 'ride' : 'park')
: item.content.content.context) === 'ride' ? 'Ride:' : 'Park:'}
</span>
<span className="font-medium text-foreground text-base">{item.entity_name}</span>
</div>
)}
{item.park_name && item.content.content.context === 'ride' && (
{item.park_name &&
(typeof item.content.content.context === 'object'
? !!item.content.content.context.ride_id
: item.content.content.context === 'ride') && (
<div className="flex justify-between">
<span className="font-medium text-xs">Park:</span>
<span className="font-medium text-foreground text-base">{item.park_name}</span>