feat: add getUserById endpoint for admin user details
Added GET /api/admin/users/:id endpoint to retrieve detailed user information including contact info, personal data, and ticket statistics. This enables the admin interface to display comprehensive user details when clicking the "Détails" button. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
e72923ec86
commit
86ccc3ef4f
|
|
@ -450,6 +450,48 @@ export const createEmployee = asyncHandler(async (req, res, next) => {
|
|||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Récupérer un utilisateur par ID
|
||||
* GET /api/admin/users/:id
|
||||
*/
|
||||
export const getUserById = asyncHandler(async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
const result = await pool.query(
|
||||
`SELECT
|
||||
u.id,
|
||||
u.email,
|
||||
u.first_name,
|
||||
u.last_name,
|
||||
u.phone,
|
||||
u.address,
|
||||
u.city,
|
||||
u.postal_code,
|
||||
u.role,
|
||||
u.is_verified,
|
||||
u.created_at,
|
||||
u.date_of_birth,
|
||||
u.gender,
|
||||
COUNT(t.id) as tickets_count,
|
||||
COUNT(CASE WHEN t.status = 'PENDING' THEN 1 END) as pending_tickets,
|
||||
COUNT(CASE WHEN t.status = 'CLAIMED' THEN 1 END) as claimed_tickets
|
||||
FROM users u
|
||||
LEFT JOIN tickets t ON u.id = t.user_id
|
||||
WHERE u.id = $1
|
||||
GROUP BY u.id`,
|
||||
[id]
|
||||
);
|
||||
|
||||
if (result.rows.length === 0) {
|
||||
return next(new AppError('Utilisateur non trouvé', 404));
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: result.rows[0],
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Mettre à jour un utilisateur
|
||||
* PUT /api/admin/users/:id
|
||||
|
|
@ -812,6 +854,7 @@ export default {
|
|||
updatePrize,
|
||||
deletePrize,
|
||||
getAllUsers,
|
||||
getUserById,
|
||||
createEmployee,
|
||||
updateUser,
|
||||
deleteUser,
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ router.delete('/prizes/:id', validate(deletePrizeSchema), adminController.delete
|
|||
|
||||
// Gestion des utilisateurs
|
||||
router.get('/users', validate(paginationSchema), adminController.getAllUsers);
|
||||
router.get('/users/:id', adminController.getUserById);
|
||||
router.post('/employees', validate(createEmployeeSchema), adminController.createEmployee);
|
||||
router.put('/users/:id', validate(updateUserSchema), adminController.updateUser);
|
||||
router.delete('/users/:id', adminController.deleteUser);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user