송용우

Merge branch 'develop' of https://github.com/FacerAin/Jaksimsamil into develop

...@@ -2,47 +2,48 @@ const mongoose = require("mongoose"); ...@@ -2,47 +2,48 @@ const mongoose = require("mongoose");
2 2
3 const { Schema } = mongoose; 3 const { Schema } = mongoose;
4 4
5 -const ChallengeSchema = new Schema( 5 +const ChallengeSchema=new Schema({
6 - { 6 + challengeName: {type: String, required: true},
7 - challengeName: { type: String, required: true }, 7 + startDate: {type: Object, required: true},
8 - startDate: { type: Object, required: true }, 8 + endDate: {type: Object, required: true},
9 - endDate: { type: Object, required: true }, 9 + durationPerSession: {type: String, required: true}, // '1d' means one day per session, '2w' means 2 weeks per session, '3m' means 3 months per session.
10 - durationPerSession: { type: String, required: true }, // '1d' means one day per session, '2w' means 2 weeks per session, '3m' means 3 months per session. 10 + goalPerSession: {type: Number, required:true}, // number of problems for one session
11 - goalPerSession: { type: Number, required: true }, // number of problems for one session 11 + status: { type: String }
12 - isOpen: { type: Boolean }, 12 +},{
13 - }, 13 + collection: 'challenge'
14 - { 14 +});
15 - collection: "challenge", 15 +
16 - } 16 +ChallengeSchema.statics.findByChallengeName=function(challengeName){
17 -); 17 + return this.findOne({challengeName:challengeName});
18 - 18 +}
19 -ChallengeSchema.statics.findByChallengeName = function (challengeName) { 19 +
20 - return this.findOne({ challengeName: challengeName }); 20 +ChallengeSchema.methods.getChallengeName=function(){
21 -};
22 -
23 -ChallengeSchema.methods.getChallengeName = function () {
24 return this.challengeName; 21 return this.challengeName;
25 -}; 22 +}
26 23
27 -ChallengeSchema.methods.getStartDate = function () { 24 +ChallengeSchema.methods.getStartDate=function(){
28 return this.startDate; 25 return this.startDate;
29 -}; 26 +}
30 27
31 -ChallengeSchema.methods.getEndDate = function () { 28 +ChallengeSchema.methods.getEndDate=function(){
32 return this.endDate; 29 return this.endDate;
33 -}; 30 +}
34 31
35 -ChallengeSchema.methods.getDurationPerSession = function () { 32 +ChallengeSchema.method.getDurationPerSession=function(){
36 return this.durationPerSession; 33 return this.durationPerSession;
37 -}; 34 +}
38 35
39 -ChallengeSchema.methods.getGoalPerSession = function () { 36 +ChallengeSchema.methods.getGoalPerSession=function(){
40 return this.goalPerSession; 37 return this.goalPerSession;
41 -}; 38 +}
42 39
43 -ChallengeSchema.methods.serialize = function () { 40 +ChallengeSchema.methods.getStatus=function(){
41 + return this.status;
42 +}
43 +
44 +ChallengeSchema.methods.serialize=function(){
44 return this.toJSON(); 45 return this.toJSON();
45 -}; 46 +}
46 47
47 -const Challenge = mongoose.model("Challenge", ChallengeSchema); 48 +const Challenge = mongoose.model('Challenge', ChallengeSchema);
48 module.exports = Challenge; 49 module.exports = Challenge;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -8,5 +8,18 @@ const GroupSchema = new Schema({ ...@@ -8,5 +8,18 @@ const GroupSchema = new Schema({
8 collection: 'group' 8 collection: 'group'
9 }); 9 });
10 10
11 +GroupSchema.methods.addGroupMemeber=function(user){
12 + this.members.push(user._id);
13 + return this.save();
14 +}
15 +
16 +GroupSchema.methods.getMembers=function(){
17 + return this.members;
18 +}
19 +
20 +GroupSchema.methods.serialize=function(){
21 + return this.toJSON();
22 +}
23 +
11 const Group = mongoose.model('Group',GroupSchema); 24 const Group = mongoose.model('Group',GroupSchema);
12 module.exports = Group; 25 module.exports = Group;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -2,12 +2,32 @@ const mongoose = require("mongoose"); ...@@ -2,12 +2,32 @@ const mongoose = require("mongoose");
2 2
3 const { Schema } = mongoose; 3 const { Schema } = mongoose;
4 4
5 +const SelectedProblemSchema=new Schema({
6 + problemNum: {type: Number, required: true},
7 + isSolved: {type:Boolean, default: false},
8 +},{
9 + _id: false
10 +});
11 +
5 const ParticipationSchema = new Schema({ 12 const ParticipationSchema = new Schema({
6 sessionId: { type: Schema.Types.ObjectId, ref: 'Session' }, 13 sessionId: { type: Schema.Types.ObjectId, ref: 'Session' },
7 - groupId: { type: Schema.Types.ObjectId, ref: 'Group' } 14 + groupId: { type: Schema.Types.ObjectId, ref: 'Group' },
15 + problems: [{type:SelectedProblemSchema}]
8 },{ 16 },{
9 collection: 'particiaption' 17 collection: 'particiaption'
10 }); 18 });
11 19
20 +ParticipationSchema.statics.findBySessionId=function(session){
21 + return this.find({sessionId:session._id});
22 +}
23 +
24 +ParticipationSchema.statics.findByGroupId=function(group){
25 + return this.find({groupId:group._id});
26 +}
27 +
28 +ParticipationSchema.methods.addProblem=function(problem){
29 + this.problems.push({problemNum:problem.problemNum,isSolved:problem.isSolved});
30 +}
31 +
12 const Participation = mongoose.model('Participation', ParticipationSchema); 32 const Participation = mongoose.model('Participation', ParticipationSchema);
13 module.exports = Participation; 33 module.exports = Participation;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -9,7 +9,7 @@ const ProblemSchema=new Schema({ ...@@ -9,7 +9,7 @@ const ProblemSchema=new Schema({
9 sumbitNum: {type: Number, required: true}, 9 sumbitNum: {type: Number, required: true},
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 },{ 13 },{
14 collection: 'problem' 14 collection: 'problem'
15 }); 15 });
......
...@@ -6,10 +6,30 @@ const SessionSchema = new Schema({ ...@@ -6,10 +6,30 @@ const SessionSchema = new Schema({
6 challengeId: { type: Schema.Types.ObjectId, ref: 'Challenge' }, 6 challengeId: { type: Schema.Types.ObjectId, ref: 'Challenge' },
7 sessionStartDate: { type: Object }, 7 sessionStartDate: { type: Object },
8 sessionEndDate: { type: Object }, 8 sessionEndDate: { type: Object },
9 - isOpen: { type: Boolean } 9 + status: { type: String }
10 },{ 10 },{
11 collection: 'session' 11 collection: 'session'
12 }); 12 });
13 13
14 +SessionSchema.statics.findByChallengeId=function(challenge){
15 + return this.find({challengeId:challenge._id});
16 +}
17 +
18 +SessionSchema.methods.getSessionStartDate=function(){
19 + return this.sessionStartDate;
20 +}
21 +
22 +SessionSchema.methods.getSessionEndDate=function(){
23 + return this.sessionEndDate;
24 +}
25 +
26 +SessionSchema.methods.getStatus=function(){
27 + return this.status;
28 +}
29 +
30 +SessionSchema.methods.serialize=function(){
31 + return this.toJSON();
32 +}
33 +
14 const Session = mongoose.model('Session', SessionSchema); 34 const Session = mongoose.model('Session', SessionSchema);
15 module.exports = Session; 35 module.exports = Session;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -21,6 +21,11 @@ UserSchema.statics.findByUsername = function (username) { ...@@ -21,6 +21,11 @@ UserSchema.statics.findByUsername = function (username) {
21 return this.findOne({ username }); 21 return this.findOne({ username });
22 }; 22 };
23 23
24 +UserSchema.methods.addFriend=function(friend){
25 + this.friendList.push(friend._id);
26 + return this.save();
27 +}
28 +
24 UserSchema.methods.setPassword = async function (password) { 29 UserSchema.methods.setPassword = async function (password) {
25 const hash = await bcrypt.hash(password, 10); 30 const hash = await bcrypt.hash(password, 10);
26 this.hashedPassword = hash; 31 this.hashedPassword = hash;
......