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");
const { Schema } = mongoose;
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.getChallengeName = function () {
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
status: { type: String }
},{
collection: 'challenge'
});
ChallengeSchema.statics.findByChallengeName=function(challengeName){
return this.findOne({challengeName:challengeName});
}
ChallengeSchema.methods.getChallengeName=function(){
return this.challengeName;
};
}
ChallengeSchema.methods.getStartDate = function () {
ChallengeSchema.methods.getStartDate=function(){
return this.startDate;
};
}
ChallengeSchema.methods.getEndDate = function () {
ChallengeSchema.methods.getEndDate=function(){
return this.endDate;
};
}
ChallengeSchema.methods.getDurationPerSession = function () {
ChallengeSchema.method.getDurationPerSession=function(){
return this.durationPerSession;
};
}
ChallengeSchema.methods.getGoalPerSession = function () {
ChallengeSchema.methods.getGoalPerSession=function(){
return this.goalPerSession;
};
}
ChallengeSchema.methods.serialize = function () {
ChallengeSchema.methods.getStatus=function(){
return this.status;
}
ChallengeSchema.methods.serialize=function(){
return this.toJSON();
};
}
const Challenge = mongoose.model("Challenge", ChallengeSchema);
const Challenge = mongoose.model('Challenge', ChallengeSchema);
module.exports = Challenge;
\ No newline at end of file
......
......@@ -6,7 +6,7 @@ const SessionSchema = new Schema({
challengeId: { type: Schema.Types.ObjectId, ref: 'Challenge' },
sessionStartDate: { type: Object },
sessionEndDate: { type: Object },
isOpen: { type: Boolean }
status: { type: String }
},{
collection: 'session'
});
......@@ -23,8 +23,8 @@ SessionSchema.methods.getSessionEndDate=function(){
return this.sessionEndDate;
}
SessionSchema.methods.getIsOpen=function(){
return this.isOpen;
SessionSchema.methods.getStatus=function(){
return this.status;
}
SessionSchema.methods.serialize=function(){
......