JuWon Seo
Committed by GitHub

Merge pull request #17 from FacerAin/feature/database

Change column of model/challenge and model/session
...@@ -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
......
...@@ -6,7 +6,7 @@ const SessionSchema = new Schema({ ...@@ -6,7 +6,7 @@ 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 });
...@@ -23,8 +23,8 @@ SessionSchema.methods.getSessionEndDate=function(){ ...@@ -23,8 +23,8 @@ SessionSchema.methods.getSessionEndDate=function(){
23 return this.sessionEndDate; 23 return this.sessionEndDate;
24 } 24 }
25 25
26 -SessionSchema.methods.getIsOpen=function(){ 26 +SessionSchema.methods.getStatus=function(){
27 - return this.isOpen; 27 + return this.status;
28 } 28 }
29 29
30 SessionSchema.methods.serialize=function(){ 30 SessionSchema.methods.serialize=function(){
......