JJuOn

Fix query using _ids

......@@ -9,9 +9,17 @@ const GroupSchema = new Schema({
});
GroupSchema.methods.addGroupMemeber=function(user){
this.members.push({$oid:user._id.$oid});
this.members.push(user._id);
return this.save();
}
GroupSchema.methods.getMembers=function(){
return this.members;
}
GroupSchema.methods.serialize=function(){
return this.toJSON();
}
const Group = mongoose.model('Group',GroupSchema);
module.exports = Group;
\ No newline at end of file
......
......@@ -18,11 +18,11 @@ const ParticipationSchema = new Schema({
});
ParticipationSchema.statics.findBySessionId=function(session){
return this.find({sessionId:session._id.$oid});
return this.find({sessionId:session._id});
}
ParticipationSchema.statics.findByGroupId=function(group){
return this.find({groupId:group._id.$oid});
return this.find({groupId:group._id});
}
ParticipationSchema.methods.addProblem=function(problem){
......
......@@ -9,7 +9,7 @@ const ProblemSchema=new Schema({
sumbitNum: {type: Number, required: true},
correctNum: {type: Number, required: true},
count: { type: Number },
category: {type:[String]}
category: [{ type:String }],
},{
collection: 'problem'
});
......
......@@ -12,7 +12,7 @@ const SessionSchema = new Schema({
});
SessionSchema.statics.findByChallengeId=function(challenge){
return this.find({challengeId:challenge._id.$oid});
return this.find({challengeId:challenge._id});
}
SessionSchema.methods.getSessionStartDate=function(){
......
......@@ -22,7 +22,7 @@ UserSchema.statics.findByUsername = function (username) {
};
UserSchema.methods.addFriend=function(friend){
this.friendList.push({$oid:friend._id.$oid});
this.friendList.push(friend._id);
return this.save();
}
......