Created
July 6, 2018 11:45
-
-
Save luojiyin1987/34572797f7be4cadd4310f54335ee75a to your computer and use it in GitHub Desktop.
要抽象的异步调用 #callback #moogoose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 代码 | |
| const keystone = require('keystone'); | |
| const SMSLog = keystone.list('SMS_log'); | |
| const user = keystone.list('User'); | |
| const Wallet = keystone.list('Wallet'); | |
| exports = module.exports = function (req, res) { | |
| console.log(req.query.id); | |
| const id = req.query.id; | |
| Wallet.model.find() | |
| .where('mobile', id) | |
| .exec(function(err ,Wallets){ | |
| if (err) console.log(err); | |
| if ( Wallets.length === 0) { | |
| res.json({ message: 'no walletaddr' }); | |
| } else { | |
| res.json({ message: 'has walletaddr', | |
| walletAddr: Wallets[0].address }); | |
| } | |
| }) | |
| } | |
| //----------------------------------------------------------------- | |
| // 我想把下面的代码抽象出一个可以调用的函数 | |
| Wallet.model.find() | |
| .where('mobile', id) | |
| .exec(function(err ,Wallets){ | |
| if (err) console.log(err); | |
| if ( Wallets.length === 0) { | |
| res.json({ message: 'no walletaddr' }); | |
| } else { | |
| res.json({ message: 'has walletaddr', | |
| walletAddr: Wallets[0].address }); | |
| } | |
| }) | |
| //----------------------------------------------------------------- | |
| 否则以后逻辑复杂后, 将死得很难看 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment