송용우
Committed by GitHub

Merge pull request #15 from FacerAin/feature/database

Feature/database
......@@ -8,5 +8,18 @@ const GroupSchema = new Schema({
collection: 'group'
});
GroupSchema.methods.addGroupMemeber=function(user){
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
......
......@@ -2,12 +2,32 @@ const mongoose = require("mongoose");
const { Schema } = mongoose;
const SelectedProblemSchema=new Schema({
problemNum: {type: Number, required: true},
isSolved: {type:Boolean, default: false},
},{
_id: false
});
const ParticipationSchema = new Schema({
sessionId: { type: Schema.Types.ObjectId, ref: 'Session' },
groupId: { type: Schema.Types.ObjectId, ref: 'Group' }
groupId: { type: Schema.Types.ObjectId, ref: 'Group' },
problems: [{type:SelectedProblemSchema}]
},{
collection: 'particiaption'
});
ParticipationSchema.statics.findBySessionId=function(session){
return this.find({sessionId:session._id});
}
ParticipationSchema.statics.findByGroupId=function(group){
return this.find({groupId:group._id});
}
ParticipationSchema.methods.addProblem=function(problem){
this.problems.push({problemNum:problem.problemNum,isSolved:problem.isSolved});
}
const Participation = mongoose.model('Participation', ParticipationSchema);
module.exports = Participation;
\ No newline at end of file
......
......@@ -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'
});
......
......@@ -11,5 +11,25 @@ const SessionSchema = new Schema({
collection: 'session'
});
SessionSchema.statics.findByChallengeId=function(challenge){
return this.find({challengeId:challenge._id});
}
SessionSchema.methods.getSessionStartDate=function(){
return this.sessionStartDate;
}
SessionSchema.methods.getSessionEndDate=function(){
return this.sessionEndDate;
}
SessionSchema.methods.getIsOpen=function(){
return this.isOpen;
}
SessionSchema.methods.serialize=function(){
return this.toJSON();
}
const Session = mongoose.model('Session', SessionSchema);
module.exports = Session;
\ No newline at end of file
......
......@@ -21,6 +21,11 @@ UserSchema.statics.findByUsername = function (username) {
return this.findOne({ username });
};
UserSchema.methods.addFriend=function(friend){
this.friendList.push(friend._id);
return this.save();
}
UserSchema.methods.setPassword = async function (password) {
const hash = await bcrypt.hash(password, 10);
this.hashedPassword = hash;
......