From c4b90a8ee5953c2814668f404c2c132dd9728513 Mon Sep 17 00:00:00 2001 From: Eddi3_As Date: Mon, 17 Mar 2025 19:06:25 -0400 Subject: [PATCH] FIX - email au lieu du userId --- client/src/Types/QuizType.tsx | 2 +- client/src/pages/Admin/Stats.tsx | 2 +- server/models/admin.js | 29 +++++++++++++++++++++++++---- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/client/src/Types/QuizType.tsx b/client/src/Types/QuizType.tsx index f97809f..5078eda 100644 --- a/client/src/Types/QuizType.tsx +++ b/client/src/Types/QuizType.tsx @@ -12,7 +12,7 @@ export interface QuizType { export interface QuizTypeShort { _id: string; - userId: string; + email: string; title: string; created_at: Date; updated_at: Date; diff --git a/client/src/pages/Admin/Stats.tsx b/client/src/pages/Admin/Stats.tsx index 50563e5..334ecea 100644 --- a/client/src/pages/Admin/Stats.tsx +++ b/client/src/pages/Admin/Stats.tsx @@ -94,7 +94,7 @@ const Users: React.FC = () => { {quizzes.map((quiz) => ( - {quiz.userId} + {quiz.email} {quiz.title} {new Date(quiz.created_at).toLocaleDateString()} {new Date(quiz.updated_at).toLocaleDateString()} diff --git a/server/models/admin.js b/server/models/admin.js index d85b217..95e317d 100644 --- a/server/models/admin.js +++ b/server/models/admin.js @@ -41,10 +41,31 @@ class Admin { const quizColl = conn.collection('files'); - const projection = { content: 0, folderName: 0, folderId: 0 }; - const result = await quizColl.find({}, projection).toArray(); - - if (!result) return null; + const result = await quizColl.aggregate([ + { + $addFields: { userId: { $toObjectId: "$userId" } } + }, + { + $lookup: { + from: "users", + localField: "userId", + foreignField: "_id", + as: "user" + } + }, + { + $unwind: "$user" + }, + { + $project: { + _id: 1, + email: "$user.email", + title: 1, + created_at: 1, + updated_at: 1 + } + } + ]).toArray(); let respObj = { quizzes: result,