Showing
3 changed files
with
41 additions
and
4 deletions
... | @@ -134,7 +134,7 @@ exports.recommend = async (ctx) => { | ... | @@ -134,7 +134,7 @@ exports.recommend = async (ctx) => { |
134 | problem_set.problem_set | 134 | problem_set.problem_set |
135 | ); | 135 | ); |
136 | ctx.body = compareBJ.randomItem(unsolved_data); | 136 | ctx.body = compareBJ.randomItem(unsolved_data); |
137 | - //데이터가 비었을 떄 예외처리 필요 | 137 | + //TODO: 데이터가 비었을 떄 예외처리 필요 |
138 | } catch (e) { | 138 | } catch (e) { |
139 | ctx.throw(500, e); | 139 | ctx.throw(500, e); |
140 | } | 140 | } | ... | ... |
... | @@ -7,8 +7,18 @@ const Schema = mongoose.Schema; | ... | @@ -7,8 +7,18 @@ const Schema = mongoose.Schema; |
7 | const UserSchema = new Schema({ | 7 | const UserSchema = new Schema({ |
8 | username: String, | 8 | username: String, |
9 | hashedPassword: String, | 9 | hashedPassword: String, |
10 | + userBJID: String, | ||
11 | + sovledBJ: Object, | ||
12 | + solvedBJ_date: Object, | ||
13 | + friendList: [String], | ||
14 | + slackWebHookURL: String, | ||
15 | + goalNum: Number, | ||
10 | }); | 16 | }); |
11 | 17 | ||
18 | +UserSchema.statics.findByUsername = function (username) { | ||
19 | + return this.findOne({ username }); | ||
20 | +}; | ||
21 | + | ||
12 | UserSchema.methods.setPassword = async function (password) { | 22 | UserSchema.methods.setPassword = async function (password) { |
13 | const hash = await bcrypt.hash(password, 10); | 23 | const hash = await bcrypt.hash(password, 10); |
14 | this.hashedPassword = hash; | 24 | this.hashedPassword = hash; |
... | @@ -17,14 +27,13 @@ UserSchema.methods.checkPassword = async function (password) { | ... | @@ -17,14 +27,13 @@ UserSchema.methods.checkPassword = async function (password) { |
17 | const result = await bcrypt.compare(password, this.hashedPassword); | 27 | const result = await bcrypt.compare(password, this.hashedPassword); |
18 | return result; | 28 | return result; |
19 | }; | 29 | }; |
20 | -UserSchema.statics.findByUsername = function (username) { | 30 | + |
21 | - return this.findOne({ username }); | ||
22 | -}; | ||
23 | UserSchema.methods.serialize = function () { | 31 | UserSchema.methods.serialize = function () { |
24 | const data = this.toJSON(); | 32 | const data = this.toJSON(); |
25 | delete data.hashedPassword; | 33 | delete data.hashedPassword; |
26 | return data; | 34 | return data; |
27 | }; | 35 | }; |
36 | + | ||
28 | UserSchema.methods.generateToken = function () { | 37 | UserSchema.methods.generateToken = function () { |
29 | const token = jwt.sign( | 38 | const token = jwt.sign( |
30 | { | 39 | { |
... | @@ -38,5 +47,32 @@ UserSchema.methods.generateToken = function () { | ... | @@ -38,5 +47,32 @@ UserSchema.methods.generateToken = function () { |
38 | ); | 47 | ); |
39 | return token; | 48 | return token; |
40 | }; | 49 | }; |
50 | + | ||
51 | +UserSchema.statics.findByUsername = function (username) { | ||
52 | + return this.findOne({ username }); | ||
53 | +}; | ||
54 | + | ||
55 | +UserSchema.methods.getBJID = function () { | ||
56 | + return this.userBJID; | ||
57 | +}; | ||
58 | + | ||
59 | +UserSchema.methods.getBJdata = function () { | ||
60 | + return this.solvedBJ; | ||
61 | +}; | ||
62 | + | ||
63 | +UserSchema.methods.getslackURL = function () { | ||
64 | + return this.slackWebHookURL; | ||
65 | +}; | ||
66 | + | ||
67 | +UserSchema.methods.getgoalNum = function () { | ||
68 | + return this.goalNum; | ||
69 | +}; | ||
70 | + | ||
71 | +UserSchema.methods.getTodaySovled = function () { | ||
72 | + if (this.solvedBJ_date) { | ||
73 | + return this.solvedBJ_date.presentNum; | ||
74 | + } | ||
75 | +}; | ||
76 | + | ||
41 | const User = mongoose.model("User", UserSchema); | 77 | const User = mongoose.model("User", UserSchema); |
42 | module.exports = User; | 78 | module.exports = User; | ... | ... |
-
Mentioned in commit b885b7d5
-
Please register or login to post a comment