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,