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:
parent
e3794e1ba8
commit
e72923ec86
|
|
@ -18,12 +18,16 @@ export const getPendingTickets = asyncHandler(async (req, res) => {
|
||||||
t.code,
|
t.code,
|
||||||
t.status,
|
t.status,
|
||||||
t.played_at,
|
t.played_at,
|
||||||
|
u.id as user_id,
|
||||||
u.email as user_email,
|
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,
|
u.phone as user_phone,
|
||||||
|
p.id as prize_id,
|
||||||
p.name as prize_name,
|
p.name as prize_name,
|
||||||
p.type as prize_type,
|
p.type as prize_type,
|
||||||
p.value as prize_value
|
p.value as prize_value,
|
||||||
|
p.description as prize_description
|
||||||
FROM tickets t
|
FROM tickets t
|
||||||
JOIN users u ON t.user_id = u.id
|
JOIN users u ON t.user_id = u.id
|
||||||
JOIN prizes p ON t.prize_id = p.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);
|
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({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
data: result.rows,
|
data: transformedData,
|
||||||
pagination: {
|
pagination: {
|
||||||
total,
|
total,
|
||||||
page: parseInt(page),
|
page: parseInt(page),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user