JJuOn

Add participation, session and group schema and Edit challenge and user schema

const mongoose = require("mongoose");
const { Schema }=mongoose;
const GroupSchema=new Schema({
members:{type:[String]},
});
const { Schema } = mongoose;
const ChallengeSchema=new Schema({
challengeName: {type: String, required: true},
......@@ -12,24 +8,13 @@ const ChallengeSchema=new Schema({
endDate: {type: Object, required: true},
durationPerSession: {type: String, required: true}, // '1d' means one day per session, '2w' means 2 weeks per session, '3m' means 3 months per session.
goalPerSession: {type: Number, required:true}, // number of problems for one session
groups:{type: [GroupSchema], required:true}, // groups attending challenge, group of only one member supposed to be single
isOpen: { type: Boolean }
});
ChallengeSchema.statics.findByChallengeName=function(challengeName){
return this.findOne({challengeName:challengeName});
}
ChallengeSchema.methods.addNewGroup=function(group){
this.groups.push(group);
return this.save();
}
ChallengeSchema.methods.removeGroup=function(group_id){
const idx=this.groups.findIndex((item)=>item._id===group_id);
this.groups.splice(idx,1);
return this.save();
}
ChallengeSchema.methods.getChallengeName=function(){
return this.challengeName;
}
......@@ -50,13 +35,9 @@ ChallengeSchema.methods.getGoalPerSession=function(){
return this.goalPerSession;
}
ChallengeSchema.methods.getGroups=function(){
return this.groups;
}
ChallengeSchema.methods.serialize=function(){
return this.toJSON();
}
const Challenge=mongoose.model('Challenge',ChallengeSchema);
module.exports=Challenge;
\ No newline at end of file
const Challenge = mongoose.model('Challenge', ChallengeSchema);
module.exports = Challenge;
\ No newline at end of file
......
const mongoose = require("mongoose");
const { Schema } = mongoose;
const GroupSchema = new Schema({
members: [{ type: Schema.Types.ObjectId, ref: 'User' }]
});
const Group = mongoose.model('Group',GroupSchema);
module.exports = Group;
\ No newline at end of file
const mongoose = require("mongoose");
const { Schema } = mongoose;
const ParticipationSchema = new Schema({
sessionId: { type: Schema.Types.ObjectId, ref: 'Session' },
groupId: { type: Schema.Types.ObjectId, ref: 'Group' }
});
const Participation = mongoose.model('Participation', ParticipationSchema);
module.exports = Participation;
\ No newline at end of file
const mongoose = require("mongoose");
const { Schema } = mongoose;
const SessionSchema = new Schema({
challengeId: { type: Schema.Types.ObjectId, ref: 'Challenge' },
sessionStartDate: { type: Object },
sessionEndDate: { type: Object }
});
const Session = mongoose.model('Session', SessionSchema);
module.exports = Session;
\ No newline at end of file
......@@ -10,7 +10,7 @@ const UserSchema = new Schema({
userBJID: String,
sovledBJ: Object,
solvedBJ_date: Object,
friendList: [String],
friendList: [{ type: Schema.Types.ObjectId, ref: 'User' }],
slackWebHookURL: String,
goalNum: Number,
});
......