Writing js, I tried the atom-beautify plug-in. I didn’t like it very much. I recommend other plug-ins that can format, mainly for automatic alignment. I hope the code style is like this:
cg_query: (req, res) => {
console.log('------查询------');
console.log('phone: ', req.body.phone);
console.log('token: ', req.header('token'));
// token 验证通过
// 输入号码合法则进行后续操作
let reg = /^1\d{10}$/;// 11 位数字,以 1 开头
if (req.body.phone && reg.test(req.body.phone)) {
model.UserModel.findOne({ phone: req.body.phone }, 'asset', (err, result) => {
console.log('result: ', result);
try {
console.log(result.asset);
let a = {
currentGoldSum: result.asset.currentGoldSum,
cgEarningsSum: result.asset.cgEarningsSum,
cgEarningsYtd: result.asset.cgEarningsYtd
};
res.json({code: 0, msg: '查询成功', asset: a});
return;
} catch (e) {
console.log(e);
}
if (err) {
console.log('db error: ', err);
}
res.json({code:-1, msg: '查询失败'});
return;
});
} else {
res.json({code:-2, msg: '非法输入'});
return;
}
}