@@ -30,10 +30,10 @@ class UserService extends Service {
30
30
const ctx = this . ctx ;
31
31
32
32
const wechat_info = { } ;
33
- [ 'openid' , 'nickname' , 'sex' , 'city' , 'province' , 'country' , 'headimgurl' ] . forEach ( key => {
33
+ [ 'openid' , 'nickname' , 'sex' , 'city' , 'province' , 'country' , 'headimgurl' ] . forEach ( key => {
34
34
wechat_info [ 'wechat_' + key ] = info [ key ] ;
35
35
} ) ;
36
- let exist_user = await ctx . model . User . find ( { where : { wechat_openid : wechat_info . wechat_openid } } ) ;
36
+ const exist_user = await ctx . model . User . find ( { where : { wechat_openid : wechat_info . wechat_openid } } ) ;
37
37
let user ;
38
38
39
39
if ( exist_user ) {
@@ -56,34 +56,34 @@ class UserService extends Service {
56
56
57
57
// TODO:从合约里读取用户信息
58
58
const userInChain = {
59
- send_likes_count : 0 , //累计发出打赏次数
60
- send_likes_value : 0 , //累计发出打赏的总金额
61
- send_likes_to_users_count : 0 , // 累计打赏了多少位用户
62
- receive_likes_count : 0 , //累计收到的打赏次数
63
- receive_likes_value : 0 , //累计收到打赏的总金额
64
- receive_likes_from_users_count : 0 , //累计收到了多少位用户的打赏
65
- balance : 0 , //账户余额
59
+ send_likes_count : 0 , // 累计发出打赏次数
60
+ send_likes_value : 0 , // 累计发出打赏的总金额
61
+ send_likes_to_users_count : 0 , // 累计打赏了多少位用户
62
+ receive_likes_count : 0 , // 累计收到的打赏次数
63
+ receive_likes_value : 0 , // 累计收到打赏的总金额
64
+ receive_likes_from_users_count : 0 , // 累计收到了多少位用户的打赏
65
+ balance : 0 , // 账户余额
66
66
} ;
67
67
68
- return { ... userInDB , ... userInChain } ;
68
+ return Object . assign ( { } , userInDB , userInChain ) ;
69
69
}
70
70
71
71
async updateByAddress ( address , updates ) {
72
72
const ctx = this . ctx ;
73
73
// TODO: address统一变小写,检查address是否合法
74
74
// ctx.throw(400, '无效地址', { code: 'INVALID_ADDRESS', error: { address } });
75
75
76
- let user = await this . ctx . model . User . find ( { where : { address } } ) ;
76
+ const user = await this . ctx . model . User . find ( { where : { address } } ) ;
77
77
if ( ! user ) {
78
- ctx . throw ( 404 , `地址(address: ${ address } )的用户不存在` , { code : 'USER_NOT_FOUND' , errors : { address } } )
78
+ ctx . throw ( 404 , `地址(address: ${ address } )的用户不存在` , { code : 'USER_NOT_FOUND' , errors : { address } } ) ;
79
79
}
80
80
81
81
// 检查更新参数是否合法
82
- const illegal = Object . keys ( updates ) . some ( ( key ) => {
83
- return ! [ 'nickname' , 'bio' , 'avatar_url' ] . includes ( key ) ;
82
+ const illegal = Object . keys ( updates ) . some ( key => {
83
+ return ! [ 'nickname' , 'bio' , 'avatar_url' ] . includes ( key ) ;
84
84
} ) ;
85
85
if ( illegal ) {
86
- ctx . throw ( 400 , ` 更新用户信息参数错误` , { code : 'ILLEGAL_UPDATE_USER_PRAM' , errors : { address, updates } } )
86
+ ctx . throw ( 400 , ' 更新用户信息参数错误' , { code : 'ILLEGAL_UPDATE_USER_PRAM' , errors : { address, updates } } ) ;
87
87
}
88
88
89
89
await user . update ( updates ) ;
@@ -111,19 +111,19 @@ class UserService extends Service {
111
111
112
112
await ctx . model . User . update ( {
113
113
address,
114
- private_key
114
+ private_key,
115
115
} , {
116
- where : {
117
- id : user_id ,
118
- address : null , // 如果同一个用户高并发打过来,可能会被更新多次, 所以不要用user.updates({address,private_key})
119
- private_key : null ,
120
- } ,
121
- returning : true ,
122
- } ) ;
116
+ where : {
117
+ id : user_id ,
118
+ address : null , // 如果同一个用户高并发打过来,可能会被更新多次, 所以不要用user.updates({address,private_key˜ })
119
+ private_key : null ,
120
+ } ,
121
+ returning : true ,
122
+ } ) ;
123
123
124
124
return {
125
125
address,
126
- private_key
126
+ private_key,
127
127
} ;
128
128
}
129
129
0 commit comments