Repository navigation
fix(interview): improve adaptive session schema validation #2409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,152 @@ | ||
|
|
||
| const mongoose = require("mongoose"); | ||
|
|
||
| const adaptiveQuestionSchema = new mongoose.Schema({ | ||
| questionText: { type: String, required: true }, | ||
| topic: { type: String, required: true }, | ||
| difficulty: { type: String, enum: ["Easy", "Medium", "Hard"], required: true }, | ||
| userAnswer: { type: String, default: "" }, | ||
| feedback: { | ||
| correctnessScore: { type: Number, min: 0, max: 100, default: null }, | ||
| explanationScore: { type: Number, min: 0, max: 100, default: null }, | ||
| approachFeedback: { type: String, default: "" }, | ||
| generalFeedback: { type: String, default: "" } | ||
| const adaptiveQuestionSchema = new mongoose.Schema( | ||
| { | ||
| questionText: { | ||
| type: String, | ||
| required: true, | ||
| trim: true | ||
| }, | ||
| topic: { | ||
| type: String, | ||
| required: true, | ||
| trim: true | ||
| }, | ||
| difficulty: { | ||
| type: String, | ||
| enum: ["Easy", "Medium", "Hard"], | ||
| required: true | ||
| }, | ||
| userAnswer: { | ||
| type: String, | ||
| default: "", | ||
| trim: true | ||
| }, | ||
| feedback: { | ||
| correctnessScore: { | ||
| type: Number, | ||
| min: 0, | ||
| max: 100, | ||
| default: null | ||
| }, | ||
| explanationScore: { | ||
| type: Number, | ||
| min: 0, | ||
| max: 100, | ||
| default: null | ||
| }, | ||
| approachFeedback: { | ||
| type: String, | ||
| default: "", | ||
| trim: true | ||
| }, | ||
| generalFeedback: { | ||
| type: String, | ||
| default: "", | ||
| trim: true | ||
| } | ||
| }, | ||
| overallScore: { | ||
| type: Number, | ||
| min: 0, | ||
| max: 100, | ||
| default: null | ||
| }, | ||
| isAnswered: { | ||
| type: Boolean, | ||
| default: false | ||
| } | ||
| }, | ||
| { timestamps: true } | ||
| ); | ||
|
|
||
| const adaptiveInterviewSessionSchema = new mongoose.Schema( | ||
| { | ||
| user: { | ||
| type: mongoose.Schema.Types.ObjectId, | ||
| ref: "User", | ||
| required: true, | ||
| index: true | ||
| }, | ||
| role: { | ||
| type: String, | ||
| required: true, | ||
| trim: true | ||
| }, | ||
| experienceLevel: { | ||
| type: String, | ||
| required: true, | ||
| trim: true | ||
| }, | ||
| topics: { | ||
| type: [{ | ||
| type: String, | ||
| trim: true | ||
| }], | ||
| required: true, | ||
| validate: { | ||
| validator: value => value.length > 0, | ||
| message: "At least one topic is required." | ||
| } | ||
| }, | ||
| status: { | ||
| type: String, | ||
| enum: ["in-progress", "completed"], | ||
| default: "in-progress" | ||
| }, | ||
| currentDifficulty: { | ||
| type: String, | ||
| enum: ["Easy", "Medium", "Hard"], | ||
| default: "Medium" | ||
| }, | ||
| maxQuestions: { | ||
| type: Number, | ||
| min: 1, | ||
| max: 50, | ||
|
Comment on lines
+105
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate
Check the value before the first Suggested fix
|
||
| default: 5, | ||
| validate: { | ||
| validator: Number.isInteger, | ||
| message: "maxQuestions must be an integer." | ||
| } | ||
| }, | ||
| questions: { | ||
| type: [adaptiveQuestionSchema], | ||
| default: [], | ||
| validate: { | ||
| validator: function (value) { | ||
| return value.length <= this.maxQuestions; | ||
| }, | ||
| message: "Questions cannot exceed maxQuestions." | ||
| } | ||
| }, | ||
| finalReport: { | ||
| totalScore: { | ||
| type: Number, | ||
| min: 0, | ||
| max: 100, | ||
| default: null | ||
| }, | ||
| improvementAreas: { | ||
| type: [String], | ||
| default: [] | ||
| }, | ||
| topicPerformance: { | ||
| type: mongoose.Schema.Types.Mixed, | ||
| default: {} | ||
| } | ||
| } | ||
| }, | ||
| overallScore: { type: Number, min: 0, max: 100, default: null }, | ||
| isAnswered: { type: Boolean, default: false } | ||
| { timestamps: true } | ||
| ); | ||
|
|
||
| adaptiveInterviewSessionSchema.index({ | ||
| user: 1, | ||
| status: 1 | ||
| }); | ||
|
|
||
| const adaptiveInterviewSessionSchema = new mongoose.Schema({ | ||
| user: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: true, index: true }, | ||
| role: { type: String, required: true }, | ||
| experienceLevel: { type: String, required: true }, | ||
| topics: { type: [String], required: true }, | ||
| status: { type: String, enum: ["in-progress", "completed"], default: "in-progress" }, | ||
| currentDifficulty: { type: String, enum: ["Easy", "Medium", "Hard"], default: "Medium" }, | ||
| maxQuestions: { type: Number, default: 5 }, | ||
| questions: [adaptiveQuestionSchema], | ||
| finalReport: { | ||
| totalScore: { type: Number, default: null }, | ||
| improvementAreas: { type: [String], default: [] }, | ||
| topicPerformance: { type: mongoose.Schema.Types.Mixed, default: {} } | ||
| } | ||
| }, { timestamps: true }); | ||
| module.exports = mongoose.model( | ||
| "AdaptiveInterviewSession", | ||
| adaptiveInterviewSessionSchema | ||
| ); | ||
|
|
||
| module.exports = mongoose.model("AdaptiveInterviewSession", adaptiveInterviewSessionSchema); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reject blank topic strings in the
topicsvalidator.topicstrims each entry, but the validator checks only the array length. An all-blank request such as[" "]is saved as[""]. LatersubmitAnswercalls pass that value into the question prompt as the allowed topics, so the model receives no usable topic.Suggested fix
Committable suggestion