FIX - email au lieu du userId

This commit is contained in:
Eddi3_As 2025-03-17 19:06:25 -04:00
parent 3124d23df3
commit c4b90a8ee5
3 changed files with 27 additions and 6 deletions

View file

@ -12,7 +12,7 @@ export interface QuizType {
export interface QuizTypeShort {
_id: string;
userId: string;
email: string;
title: string;
created_at: Date;
updated_at: Date;

View file

@ -94,7 +94,7 @@ const Users: React.FC = () => {
<TableBody>
{quizzes.map((quiz) => (
<TableRow key={quiz._id}>
<TableCell>{quiz.userId}</TableCell>
<TableCell>{quiz.email}</TableCell>
<TableCell>{quiz.title}</TableCell>
<TableCell>{new Date(quiz.created_at).toLocaleDateString()}</TableCell>
<TableCell>{new Date(quiz.updated_at).toLocaleDateString()}</TableCell>

View file

@ -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,