송용우

Merge commit 'b885b7d5' into feature/rest_api

......@@ -8,3 +8,4 @@ access.log
# dependencies
/node_modules
......
......@@ -402,12 +402,12 @@
}
},
"bcrypt": {
"version": "3.0.8",
"resolved": "https://registry.npmjs.org/bcrypt/-/bcrypt-3.0.8.tgz",
"integrity": "sha512-jKV6RvLhI36TQnPDvUFqBEnGX9c8dRRygKxCZu7E+MgLfKZbmmXL8a7/SFFOyHoPNX9nV81cKRC5tbQfvEQtpw==",
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/bcrypt/-/bcrypt-5.0.0.tgz",
"integrity": "sha512-jB0yCBl4W/kVHM2whjfyqnxTmOHkCX4kHEa5nYKSoGeYe8YrjTYTc87/6bwt1g8cmV0QrbhKriETg9jWtcREhg==",
"requires": {
"nan": "2.14.0",
"node-pre-gyp": "0.14.0"
"node-addon-api": "^3.0.0",
"node-pre-gyp": "0.15.0"
}
},
"bcrypt-pbkdf": {
......@@ -2415,11 +2415,6 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"nan": {
"version": "2.14.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz",
"integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg=="
},
"natural-compare": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
......@@ -2451,14 +2446,19 @@
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
"integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw=="
},
"node-addon-api": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.0.0.tgz",
"integrity": "sha512-sSHCgWfJ+Lui/u+0msF3oyCgvdkhxDbkCS6Q8uiJquzOimkJBvX6hl5aSSA7DR1XbMpdM8r7phjcF63sF4rkKg=="
},
"node-pre-gyp": {
"version": "0.14.0",
"resolved": "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.14.0.tgz",
"integrity": "sha512-+CvDC7ZttU/sSt9rFjix/P05iS43qHCOOGzcr3Ry99bXG7VX953+vFyEuph/tfqoYu8dttBkE86JSKBO2OzcxA==",
"version": "0.15.0",
"resolved": "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.15.0.tgz",
"integrity": "sha512-7QcZa8/fpaU/BKenjcaeFF9hLz2+7S9AqyXFhlH/rilsQ/hPZKK32RtR5EQHJElgu+q5RfbJ34KriI79UWaorA==",
"requires": {
"detect-libc": "^1.0.2",
"mkdirp": "^0.5.1",
"needle": "^2.2.1",
"mkdirp": "^0.5.3",
"needle": "^2.5.0",
"nopt": "^4.0.1",
"npm-packlist": "^1.1.6",
"npmlog": "^4.0.2",
......
......@@ -5,7 +5,7 @@
"license": "MIT",
"dependencies": {
"axios": "^0.19.2",
"bcrypt": "^3.0.0",
"bcrypt": "^5.0.0",
"body-parser": "^1.19.0",
"cheerio": "^1.0.0-rc.3",
"cookie-parser": "^1.4.5",
......
......@@ -133,7 +133,7 @@ exports.recommend = async (ctx) => {
problem_set.problem_set
);
ctx.body = compareBJ.randomItem(unsolved_data);
//데이터가 비었을 떄 예외처리 필요
//TODO: 데이터가 비었을 떄 예외처리 필요
} catch (e) {
ctx.throw(500, e);
}
......
......@@ -8,6 +8,7 @@ const ProblemSchema=new Schema({
solvedacLevel: {type: Number},
sumbitNum: {type: Number, required: true},
correctNum: {type: Number, required: true},
count: { type: Number },
category: {type:[String]}
});
......@@ -46,6 +47,10 @@ ProblemSchema.methods.getCorrectNum=function(){
return this.correctNum;
}
ProblemSchema.methods.getCount=function(){
return this.count;
}
ProblemSchema.methods.getCategory=function(){
return this.category;
}
......
......@@ -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;
......
This diff is collapsed. Click to expand it.