diff --git a/src/apis/v1/exam/service.ts b/src/apis/v1/exam/service.ts index 1446cb7..6004636 100644 --- a/src/apis/v1/exam/service.ts +++ b/src/apis/v1/exam/service.ts @@ -130,6 +130,7 @@ export const getExamById = async (id: string, userRank: string, userEmail: strin title: 1, description: 1, is_approved: 1, + school_year: 1, author: { _id: '$author._id', fullname: '$author.fullname', diff --git a/src/apis/v1/userExam/service.ts b/src/apis/v1/userExam/service.ts index fde1228..3e33260 100644 --- a/src/apis/v1/userExam/service.ts +++ b/src/apis/v1/userExam/service.ts @@ -209,6 +209,14 @@ export const getAllUserExamsByOwner = async (userId: string, filter: UserExamFil as: 'subject', }, }, + { + $lookup: { + from: 'user_answer', + localField: 'user_answer_id', + foreignField: '_id', + as: 'user_answers', + }, + }, { $unwind: '$subject', }, @@ -279,6 +287,22 @@ export const getUserExamByOwner = async (userEmail: string, userExamId: string) as: 'author', }, }, + { + $lookup: { + from: 'exam', + localField: 'original_exam', + foreignField: '_id', + as: 'exam', + }, + }, + { + $lookup: { + from: 'user', + localField: 'exam.author', + foreignField: '_id', + as: 'author_exam', + }, + }, { $lookup: { from: 'subject', @@ -311,6 +335,7 @@ export const getUserExamByOwner = async (userEmail: string, userExamId: string) 'questions.author': 0, 'user_answers.is_deleted': 0, 'user_answers.deleted_at': 0, + exam: 0, }, }, ]; @@ -346,9 +371,12 @@ export const getUserExamByOwner = async (userEmail: string, userExamId: string) return { answers: question?.answers, content: question?.content, + image: question?.image, + accuracy: question?.accuracy, _id: question._id, }; }), + author_exam: hideUserInfoIfRequired(userExam[0]?.author_exam[0]), author: hideUserInfoIfRequired(userExam[0]?.author), }; } catch (error) {