From 569ffe8714fa228c5330954df68bf4146972acfe Mon Sep 17 00:00:00 2001 From: dungnguyenn1103 Date: Fri, 21 Apr 2023 09:59:57 +0700 Subject: [PATCH] feat/#166 [fix result response of api userExam] --- src/apis/v1/exam/service.ts | 1 + src/apis/v1/userExam/service.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) 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 8abc31f..4014649 100644 --- a/src/apis/v1/userExam/service.ts +++ b/src/apis/v1/userExam/service.ts @@ -287,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', @@ -319,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, }, }, ]; @@ -357,6 +374,7 @@ export const getUserExamByOwner = async (userEmail: string, userExamId: string) _id: question._id, }; }), + author_exam: hideUserInfoIfRequired(userExam[0]?.author_exam[0]), author: hideUserInfoIfRequired(userExam[0]?.author), }; } catch (error) {