Committed by
GitHub
Merge pull request #17 from FacerAin/feature/database
Change column of model/challenge and model/session
Showing
2 changed files
with
48 additions
and
47 deletions
... | @@ -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 | -}; | 21 | + return this.challengeName; |
22 | - | 22 | +} |
23 | -ChallengeSchema.methods.getChallengeName = function () { | 23 | + |
24 | - return this.challengeName; | 24 | +ChallengeSchema.methods.getStartDate=function(){ |
25 | -}; | 25 | + return this.startDate; |
26 | - | 26 | +} |
27 | -ChallengeSchema.methods.getStartDate = function () { | 27 | + |
28 | - return this.startDate; | 28 | +ChallengeSchema.methods.getEndDate=function(){ |
29 | -}; | 29 | + return this.endDate; |
30 | - | 30 | +} |
31 | -ChallengeSchema.methods.getEndDate = function () { | 31 | + |
32 | - return this.endDate; | 32 | +ChallengeSchema.method.getDurationPerSession=function(){ |
33 | -}; | 33 | + return this.durationPerSession; |
34 | - | 34 | +} |
35 | -ChallengeSchema.methods.getDurationPerSession = function () { | 35 | + |
36 | - return this.durationPerSession; | 36 | +ChallengeSchema.methods.getGoalPerSession=function(){ |
37 | -}; | 37 | + return this.goalPerSession; |
38 | - | 38 | +} |
39 | -ChallengeSchema.methods.getGoalPerSession = function () { | 39 | + |
40 | - return this.goalPerSession; | 40 | +ChallengeSchema.methods.getStatus=function(){ |
41 | -}; | 41 | + return this.status; |
42 | - | 42 | +} |
43 | -ChallengeSchema.methods.serialize = function () { | 43 | + |
44 | - return this.toJSON(); | 44 | +ChallengeSchema.methods.serialize=function(){ |
45 | -}; | 45 | + return this.toJSON(); |
46 | - | 46 | +} |
47 | -const Challenge = mongoose.model("Challenge", ChallengeSchema); | 47 | + |
48 | -module.exports = Challenge; | 48 | +const Challenge = mongoose.model('Challenge', ChallengeSchema); |
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(){ | ... | ... |
-
Please register or login to post a comment