-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/challenges add user to res (#148)
* feat: add getSeasonQuestion function * fix: return correct itemcount and pagecount when generating pagination metadata * test: add test file for pagination and getSeasonQuestion * fix: modify some function to use cont-serv-repo architecture * fix: add get season question endpoint
- Loading branch information
1 parent
5df66c8
commit f9bac61
Showing
21 changed files
with
543 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface GeneralResp { | ||
status: number; | ||
message: string; | ||
data?: any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Question, { QuestionModel } from "../model/question" | ||
import mongoose from 'mongoose'; | ||
|
||
const getQuestionByID = async ( | ||
questionID: mongoose.Types.ObjectId, | ||
): Promise<QuestionModel | null> => { | ||
const question = await Question.findOne({ | ||
_id: questionID | ||
}); | ||
return question; | ||
} | ||
|
||
const updateQuestionByID = async ( | ||
questionID: mongoose.Types.ObjectId, | ||
questionModel: QuestionModel | ||
): Promise<QuestionModel | null> => { | ||
const question = await Question.findOneAndUpdate({ | ||
_id: questionID | ||
}, questionModel, { new: true }); | ||
return question; | ||
} | ||
|
||
const updateQuestionSubmissions = async ( | ||
questionID: mongoose.Types.ObjectId, | ||
submissionID: mongoose.Types.ObjectId, | ||
isCorrect: boolean | ||
): Promise<QuestionModel | null> => { | ||
const question = await Question.findOneAndUpdate({ | ||
_id: questionID | ||
}, { | ||
$push: { submissions: submissionID }, | ||
$inc: { | ||
submissions_count: 1, | ||
correct_submissions_count: isCorrect ? 1 : 0 | ||
} | ||
}, { new: true }); | ||
return question; | ||
} | ||
|
||
const QuestionRepo = { | ||
getQuestionByID, | ||
updateQuestionByID, | ||
updateQuestionSubmissions | ||
} | ||
|
||
export { QuestionRepo as default } |
Oops, something went wrong.