Skip to content

Commit a967322

Browse files
committed
style: resolve eslint errors && format
1 parent b3456f4 commit a967322

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

app/service/user.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ class UserService extends Service {
3030
const ctx = this.ctx;
3131

3232
const wechat_info = {};
33-
['openid', 'nickname', 'sex', 'city', 'province', 'country', 'headimgurl'].forEach(key => {
33+
[ 'openid', 'nickname', 'sex', 'city', 'province', 'country', 'headimgurl' ].forEach(key => {
3434
wechat_info['wechat_' + key] = info[key];
3535
});
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 } });
3737
let user;
3838

3939
if (exist_user) {
@@ -56,34 +56,34 @@ class UserService extends Service {
5656

5757
// TODO:从合约里读取用户信息
5858
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, // 账户余额
6666
};
6767

68-
return { ...userInDB, ...userInChain };
68+
return Object.assign({}, userInDB, userInChain);
6969
}
7070

7171
async updateByAddress(address, updates) {
7272
const ctx = this.ctx;
7373
// TODO: address统一变小写,检查address是否合法
7474
// ctx.throw(400, '无效地址', { code: 'INVALID_ADDRESS', error: { address } });
7575

76-
let user = await this.ctx.model.User.find({ where: { address } });
76+
const user = await this.ctx.model.User.find({ where: { address } });
7777
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 } });
7979
}
8080

8181
// 检查更新参数是否合法
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);
8484
});
8585
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 } });
8787
}
8888

8989
await user.update(updates);
@@ -111,19 +111,19 @@ class UserService extends Service {
111111

112112
await ctx.model.User.update({
113113
address,
114-
private_key
114+
private_key,
115115
}, {
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+
});
123123

124124
return {
125125
address,
126-
private_key
126+
private_key,
127127
};
128128
}
129129

0 commit comments

Comments
 (0)