fix: transform pending tickets data to match frontend expectations

Updated the getPendingTickets endpoint to return nested objects for user
and prize data instead of flat SQL columns. Frontend expects structure like
ticket.user.firstName and ticket.prize.name, which now displays correctly
in the employee verification interface instead of showing N/A.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
soufiane 2025-11-19 14:30:44 +01:00
parent e3794e1ba8
commit e72923ec86

View File

@ -18,12 +18,16 @@ export const getPendingTickets = asyncHandler(async (req, res) => {
t.code,
t.status,
t.played_at,
u.id as user_id,
u.email as user_email,
u.first_name || ' ' || u.last_name as user_name,
u.first_name as user_first_name,
u.last_name as user_last_name,
u.phone as user_phone,
p.id as prize_id,
p.name as prize_name,
p.type as prize_type,
p.value as prize_value
p.value as prize_value,
p.description as prize_description
FROM tickets t
JOIN users u ON t.user_id = u.id
JOIN prizes p ON t.prize_id = p.id
@ -41,9 +45,31 @@ export const getPendingTickets = asyncHandler(async (req, res) => {
const total = parseInt(countResult.rows[0].count);
// Transform data to match frontend expectations
const transformedData = result.rows.map(row => ({
id: row.id,
code: row.code,
status: row.status,
playedAt: row.played_at,
user: {
id: row.user_id,
email: row.user_email,
firstName: row.user_first_name,
lastName: row.user_last_name,
phone: row.user_phone,
},
prize: {
id: row.prize_id,
name: row.prize_name,
type: row.prize_type,
value: row.prize_value,
description: row.prize_description,
},
}));
res.json({
success: true,
data: result.rows,
data: transformedData,
pagination: {
total,
page: parseInt(page),