송용우

Merge commit '42919eb6' into feature/rest_api

...@@ -2,34 +2,24 @@ const mongoose = require("mongoose"); ...@@ -2,34 +2,24 @@ const mongoose = require("mongoose");
2 2
3 const { Schema } = mongoose; 3 const { Schema } = mongoose;
4 4
5 -const GroupSchema = new Schema({ 5 +const ChallengeSchema = new Schema(
6 - members: { type: [String] }, 6 + {
7 -}); 7 + challengeName: { type: String, required: true },
8 - 8 + startDate: { type: Object, required: true },
9 -const ChallengeSchema = new Schema({ 9 + endDate: { type: Object, required: true },
10 - challengeName: { type: String, required: true }, 10 + durationPerSession: { type: String, required: true }, // '1d' means one day per session, '2w' means 2 weeks per session, '3m' means 3 months per session.
11 - startDate: { type: Object, required: true }, 11 + goalPerSession: { type: Number, required: true }, // number of problems for one session
12 - endDate: { type: Object, required: true }, 12 + isOpen: { type: Boolean },
13 - durationPerSession: { type: String, required: true }, // '1d' means one day per session, '2w' means 2 weeks per session, '3m' means 3 months per session. 13 + },
14 - goalPerSession: { type: Number, required: true }, // number of problems for one session 14 + {
15 - groups: { type: [GroupSchema], required: true }, // groups attending challenge, group of only one member supposed to be single 15 + collection: "challenge",
16 -}); 16 + }
17 +);
17 18
18 ChallengeSchema.statics.findByChallengeName = function (challengeName) { 19 ChallengeSchema.statics.findByChallengeName = function (challengeName) {
19 return this.findOne({ challengeName: challengeName }); 20 return this.findOne({ challengeName: challengeName });
20 }; 21 };
21 22
22 -ChallengeSchema.methods.addNewGroup = function (group) {
23 - this.groups.push(group);
24 - return this.save();
25 -};
26 -
27 -ChallengeSchema.methods.removeGroup = function (group_id) {
28 - const idx = this.groups.findIndex((item) => item._id === group_id);
29 - this.groups.splice(idx, 1);
30 - return this.save();
31 -};
32 -
33 ChallengeSchema.methods.getChallengeName = function () { 23 ChallengeSchema.methods.getChallengeName = function () {
34 return this.challengeName; 24 return this.challengeName;
35 }; 25 };
...@@ -50,10 +40,6 @@ ChallengeSchema.methods.getGoalPerSession = function () { ...@@ -50,10 +40,6 @@ ChallengeSchema.methods.getGoalPerSession = function () {
50 return this.goalPerSession; 40 return this.goalPerSession;
51 }; 41 };
52 42
53 -ChallengeSchema.methods.getGroups = function () {
54 - return this.groups;
55 -};
56 -
57 ChallengeSchema.methods.serialize = function () { 43 ChallengeSchema.methods.serialize = function () {
58 return this.toJSON(); 44 return this.toJSON();
59 }; 45 };
......
1 +const mongoose = require("mongoose");
2 +
3 +const { Schema } = mongoose;
4 +
5 +const GroupSchema = new Schema({
6 + members: [{ type: Schema.Types.ObjectId, ref: 'User' }]
7 +},{
8 + collection: 'group'
9 +});
10 +
11 +const Group = mongoose.model('Group',GroupSchema);
12 +module.exports = Group;
...\ No newline at end of file ...\ No newline at end of file
1 +const mongoose = require("mongoose");
2 +
3 +const { Schema } = mongoose;
4 +
5 +const ParticipationSchema = new Schema({
6 + sessionId: { type: Schema.Types.ObjectId, ref: 'Session' },
7 + groupId: { type: Schema.Types.ObjectId, ref: 'Group' }
8 +},{
9 + collection: 'particiaption'
10 +});
11 +
12 +const Participation = mongoose.model('Participation', ParticipationSchema);
13 +module.exports = Participation;
...\ No newline at end of file ...\ No newline at end of file
...@@ -10,6 +10,8 @@ const ProblemSchema=new Schema({ ...@@ -10,6 +10,8 @@ const ProblemSchema=new Schema({
10 correctNum: {type: Number, required: true}, 10 correctNum: {type: Number, required: true},
11 count: { type: Number }, 11 count: { type: Number },
12 category: {type:[String]} 12 category: {type:[String]}
13 +},{
14 + collection: 'problem'
13 }); 15 });
14 16
15 ProblemSchema.statics.findByProblemNum=function(problemNum){ 17 ProblemSchema.statics.findByProblemNum=function(problemNum){
...@@ -59,5 +61,5 @@ ProblemSchema.methods.serialize=function(){ ...@@ -59,5 +61,5 @@ ProblemSchema.methods.serialize=function(){
59 return this.toJSON(); 61 return this.toJSON();
60 } 62 }
61 63
62 -const Problem=mongoose.model('Problem',ProblemSchema);
63 -module.exports=Problem;
...\ No newline at end of file ...\ No newline at end of file
64 +const Problem = mongoose.model('Problem',ProblemSchema);
65 +module.exports = Problem;
...\ No newline at end of file ...\ No newline at end of file
......
1 -const mongoose = require("mongoose");
2 -
3 -const { Schema } = mongoose;
4 -
5 -const ProfileSchema = new Schema({
6 - username: { type: String, required: true, unique: true },
7 - userBJID: String,
8 - solvedBJ: Object,
9 - solvedBJ_date: Object,
10 - friendList: [String],
11 - slackWebHookURL: String,
12 - goalNum: Number,
13 -});
14 -ProfileSchema.statics.findByUsername = function (username) {
15 - return this.findOne({ username });
16 -};
17 -ProfileSchema.methods.getBJID = function () {
18 - return this.userBJID;
19 -};
20 -ProfileSchema.methods.getBJdata = function () {
21 - return this.solvedBJ;
22 -};
23 -ProfileSchema.methods.getslackURL = function () {
24 - return this.slackWebHookURL;
25 -};
26 -ProfileSchema.methods.getgoalNum = function () {
27 - return this.goalNum;
28 -};
29 -ProfileSchema.methods.getTodaySovled = function () {
30 - if (this.solvedBJ_date) {
31 - return this.solvedBJ_date.presentNum;
32 - }
33 -};
34 -
35 -ProfileSchema.methods.serialize = function () {
36 - const data = this.toJSON();
37 - return data;
38 -};
39 -const Profile = mongoose.model("Profile", ProfileSchema);
40 -module.exports = Profile;
1 +const mongoose = require("mongoose");
2 +
3 +const { Schema } = mongoose;
4 +
5 +const SessionSchema = new Schema({
6 + challengeId: { type: Schema.Types.ObjectId, ref: 'Challenge' },
7 + sessionStartDate: { type: Object },
8 + sessionEndDate: { type: Object },
9 + isOpen: { type: Boolean }
10 +},{
11 + collection: 'session'
12 +});
13 +
14 +const Session = mongoose.model('Session', SessionSchema);
15 +module.exports = Session;
...\ No newline at end of file ...\ No newline at end of file
...@@ -10,9 +10,11 @@ const UserSchema = new Schema({ ...@@ -10,9 +10,11 @@ const UserSchema = new Schema({
10 userBJID: String, 10 userBJID: String,
11 sovledBJ: Object, 11 sovledBJ: Object,
12 solvedBJ_date: Object, 12 solvedBJ_date: Object,
13 - friendList: [String], 13 + friendList: [{ type: Schema.Types.ObjectId, ref: 'User' }],
14 slackWebHookURL: String, 14 slackWebHookURL: String,
15 goalNum: Number, 15 goalNum: Number,
16 +},{
17 + collection: 'user'
16 }); 18 });
17 19
18 UserSchema.statics.findByUsername = function (username) { 20 UserSchema.statics.findByUsername = function (username) {
......