송용우

Merge commit '42919eb6' into feature/rest_api

......@@ -2,34 +2,24 @@ const mongoose = require("mongoose");
const { Schema } = mongoose;
const GroupSchema = new Schema({
members: { type: [String] },
});
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
});
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
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 ProfileSchema = new Schema({
username: { type: String, required: true, unique: true },
userBJID: String,
solvedBJ: Object,
solvedBJ_date: Object,
friendList: [String],
slackWebHookURL: String,
goalNum: Number,
});
ProfileSchema.statics.findByUsername = function (username) {
return this.findOne({ username });
};
ProfileSchema.methods.getBJID = function () {
return this.userBJID;
};
ProfileSchema.methods.getBJdata = function () {
return this.solvedBJ;
};
ProfileSchema.methods.getslackURL = function () {
return this.slackWebHookURL;
};
ProfileSchema.methods.getgoalNum = function () {
return this.goalNum;
};
ProfileSchema.methods.getTodaySovled = function () {
if (this.solvedBJ_date) {
return this.solvedBJ_date.presentNum;
}
};
ProfileSchema.methods.serialize = function () {
const data = this.toJSON();
return data;
};
const Profile = mongoose.model("Profile", ProfileSchema);
module.exports = Profile;
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) {
......