송용우

Integrate User and Profile Model to Model

......@@ -8,3 +8,4 @@ access.log
# dependencies
/node_modules
......
......@@ -134,7 +134,7 @@ exports.recommend = async (ctx) => {
problem_set.problem_set
);
ctx.body = compareBJ.randomItem(unsolved_data);
//데이터가 비었을 떄 예외처리 필요
//TODO: 데이터가 비었을 떄 예외처리 필요
} catch (e) {
ctx.throw(500, e);
}
......
......@@ -7,8 +7,18 @@ const Schema = mongoose.Schema;
const UserSchema = new Schema({
username: String,
hashedPassword: String,
userBJID: String,
sovledBJ: Object,
solvedBJ_date: Object,
friendList: [String],
slackWebHookURL: String,
goalNum: Number,
});
UserSchema.statics.findByUsername = function (username) {
return this.findOne({ username });
};
UserSchema.methods.setPassword = async function (password) {
const hash = await bcrypt.hash(password, 10);
this.hashedPassword = hash;
......@@ -17,14 +27,13 @@ UserSchema.methods.checkPassword = async function (password) {
const result = await bcrypt.compare(password, this.hashedPassword);
return result;
};
UserSchema.statics.findByUsername = function (username) {
return this.findOne({ username });
};
UserSchema.methods.serialize = function () {
const data = this.toJSON();
delete data.hashedPassword;
return data;
};
UserSchema.methods.generateToken = function () {
const token = jwt.sign(
{
......@@ -38,5 +47,32 @@ UserSchema.methods.generateToken = function () {
);
return token;
};
UserSchema.statics.findByUsername = function (username) {
return this.findOne({ username });
};
UserSchema.methods.getBJID = function () {
return this.userBJID;
};
UserSchema.methods.getBJdata = function () {
return this.solvedBJ;
};
UserSchema.methods.getslackURL = function () {
return this.slackWebHookURL;
};
UserSchema.methods.getgoalNum = function () {
return this.goalNum;
};
UserSchema.methods.getTodaySovled = function () {
if (this.solvedBJ_date) {
return this.solvedBJ_date.presentNum;
}
};
const User = mongoose.model("User", UserSchema);
module.exports = User;
......