JuWon Seo
Committed by GitHub

Merge pull request #21 from FacerAin/feature/database

Feature/database
......@@ -42,7 +42,9 @@ ChallengeSchema.methods.getStatus=function(){
}
ChallengeSchema.methods.serialize=function(){
return this.toJSON();
let challengeJSON = this.toJSON();
delete challengeJSON._id;
return challengeJSON;
}
const Challenge = mongoose.model('Challenge', ChallengeSchema);
......
......@@ -3,12 +3,17 @@ const mongoose = require("mongoose");
const { Schema } = mongoose;
const GroupSchema = new Schema({
groupName: { type: String },
members: [{ type: Schema.Types.ObjectId, ref: 'User' }]
},{
collection: 'group'
});
GroupSchema.methods.addGroupMemeber=function(user){
GroupSchema.statics.findByGroupName=function(groupName){
return this.find({groupName:groupName});
}
GroupSchema.methods.addGroupMember=function(user){
this.members.push(user._id);
return this.save();
}
......@@ -18,7 +23,9 @@ GroupSchema.methods.getMembers=function(){
}
GroupSchema.methods.serialize=function(){
return this.toJSON();
let groupJSON=this.toJSON();
delete groupJSON._id;
return groupJSON;
}
const Group = mongoose.model('Group',GroupSchema);
......
......@@ -29,5 +29,11 @@ ParticipationSchema.methods.addProblem=function(problem){
this.problems.push({problemNum:problem.problemNum,isSolved:problem.isSolved});
}
ParticipationSchema.methods.serialize=function(){
let participationJSON=this.toJSON();
delete participationJSON._id;
return participationJSON;
}
const Participation = mongoose.model('Participation', ParticipationSchema);
module.exports = Participation;
\ No newline at end of file
......
......@@ -58,7 +58,9 @@ ProblemSchema.methods.getCategory=function(){
}
ProblemSchema.methods.serialize=function(){
return this.toJSON();
let problemJSON=this.toJSON();
delete problemJSON._id;
return problemJSON;
}
const Problem = mongoose.model('Problem',ProblemSchema);
......
......@@ -28,7 +28,9 @@ SessionSchema.methods.getStatus=function(){
}
SessionSchema.methods.serialize=function(){
return this.toJSON();
let sessionJSON=this.toJSON();
delete sessionJSON._id;
return sessionJSON;
}
const Session = mongoose.model('Session', SessionSchema);
......
......@@ -38,13 +38,14 @@ UserSchema.methods.checkPassword = async function (password) {
UserSchema.methods.serialize = function () {
const data = this.toJSON();
delete data.hashedPassword;
delete data._id;
return data;
};
UserSchema.methods.generateToken = function () {
const token = jwt.sign(
{
_id: this.id,
_id: this._id,
username: this.username,
},
process.env.JWT_SECRET,
......