1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | function getMortgageApplication(params) { return new Promise(function(resolve, reject){ try{ logHelper.logEntryAndInput(logger, 'getMortgageApplication', params); if(!validate.isValidJson(params)){ logHelper.logError(logger, 'getMortgageApplication', 'Invalid params'); return reject({statusCode: constants.INVALID_INPUT, body: 'Could not fetch mortgage application. Invalid params' }) } var user = params.user; if(!validate.isValidString(user)){ logHelper.logError(logger, 'getMortgageApplication', 'Invalid user'); return reject({statusCode: constants.INVALID_INPUT, body: 'Could not fetch mortgage application. Invalid user' }) } var id = params.id; if(!validate.isValidString(id)){ logHelper.logError(logger, 'getMortgageApplication', 'Invalid id'); return reject({statusCode: constants.INVALID_INPUT, body: 'Could not fetch mortgage application. Invalid id' }) } var reqSpec = getRequestSpec({functionName: 'GetLoanApplication', args: [id]}); recursiveQuery({requestSpec: reqSpec, user: user}) .then(function(resp){ logHelper.logMessage(logger, 'GetMortgageApplication', 'Successfully fetched mortgage application', resp.body); return resolve({statusCode: constants.SUCCESS, body: resp.body}); }) .catch(function(err){ logHelper.logError(logger, 'GetMortgageApplication', 'Could not fetch mortgage application', err); return reject({statusCode: constants.INTERNAL_SERVER_ERROR, body: 'Could not fetch mortgage applications' }); }); } catch(err){ logHelper.logError(logger, 'getMortgageApplication', 'Could not fetch property ad ', err); return reject({statusCode: constants.INTERNAL_SERVER_ERROR, body: 'Could not fetch mortgage application ' }); } }); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | var chain = bcNetwork.getChain(); var chainAsync = Promise.promisifyAll(chain); chainAsync.getMemberAsync(user) .then(function(member){ var tx = member.query(requestSpec); tx.on('submitted', function() { logHelper.logMessage(logger, 'doQuery','Transaction for query submitted'); }); tx.on('complete', function(data) { try{ logHelper.logMessage(logger, 'doQuery', 'Transaction for query complete ',requestSpec); var buffer = new Buffer(data.result); var jsonResp = JSON.parse(buffer.toString()); return resolve({statusCode: constants.SUCCESS, body: jsonResp}); } catch(err){ logHelper.logError(logger,'doQuery','Could not parse query response',err); return reject({statusCode: constants.INTERNAL_SERVER_ERROR, body: 'Could not parse query response ' }); } }); tx.on('error', function (err) { logHelper.logError(logger, 'doQuery', 'Could not perform query ',err); return reject({statusCode: constants.INTERNAL_SERVER_ERROR, body: 'Could not perform query ' }); }); }) |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |