송용우

Merge commit 'ce195302' into develop

......@@ -2,34 +2,24 @@ const mongoose = require("mongoose");
const { Schema } = mongoose;
const GroupSchema = new Schema({
members: { type: [String] },
});
const ChallengeSchema = new Schema({
const ChallengeSchema = new Schema(
{
challengeName: { type: String, required: true },
startDate: { type: Object, required: true },
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 },
},
{
collection: "challenge",
}
);
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,10 +40,6 @@ ChallengeSchema.methods.getGoalPerSession = function () {
return this.goalPerSession;
};
ChallengeSchema.methods.getGroups = function () {
return this.groups;
};
ChallengeSchema.methods.serialize = function () {
return this.toJSON();
};
......
const mongoose = require("mongoose");
const { Schema } = mongoose;
const GroupSchema = new Schema({
members: [{ type: Schema.Types.ObjectId, ref: 'User' }]
},{
collection: 'group'
});
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' }
},{
collection: 'particiaption'
});
const Participation = mongoose.model('Participation', ParticipationSchema);
module.exports = Participation;
\ No newline at end of file
......@@ -10,6 +10,8 @@ const ProblemSchema=new Schema({
correctNum: {type: Number, required: true},
count: { type: Number },
category: {type:[String]}
},{
collection: 'problem'
});
ProblemSchema.statics.findByProblemNum=function(problemNum){
......@@ -59,5 +61,5 @@ ProblemSchema.methods.serialize=function(){
return this.toJSON();
}
const Problem=mongoose.model('Problem',ProblemSchema);
module.exports=Problem;
\ No newline at end of file
const Problem = mongoose.model('Problem',ProblemSchema);
module.exports = Problem;
\ 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 },
isOpen: { type: Boolean }
},{
collection: 'session'
});
const Session = mongoose.model('Session', SessionSchema);
module.exports = Session;
\ No newline at end of file
......@@ -10,9 +10,11 @@ const UserSchema = new Schema({
userBJID: String,
sovledBJ: Object,
solvedBJ_date: Object,
friendList: [String],
friendList: [{ type: Schema.Types.ObjectId, ref: 'User' }],
slackWebHookURL: String,
goalNum: Number,
},{
collection: 'user'
});
UserSchema.statics.findByUsername = function (username) {
......