0
嘗試將承諾集成到我的塞內卡模塊。Senecajs |應用程序與結果,而不是一個對象或數組:Promise
首先,我們有一個公開的路徑文件server.js:
var express = require('express');
var app = express();
var Promise = require('bluebird');
var seneca = require('seneca')();
var act = Promise.promisify(seneca.act, {context: seneca});
var payroll = require ('./app/payroll');
seneca.use(payroll);
var router = express.Router();
router.route('/')
.get(function(req, res) {
act({role:'payroll', cmd:'generate-weekly-report-data', wc: 1489363200})
.then(function (data) {
res.json(data)
})
.catch(function (err) {
res.send(err)
});
})
app.use('/payroll', router);
app.listen(3000);
console.log("Magic happens at port 3000");
然後,我們已經拿到了工資模塊(payroll.js),其中包含的某些會計功能開始:
module.exports = function(options) {
var Promise = require('bluebird');
var seneca = this;
var act = Promise.promisify(seneca.act, {context: seneca});
var payStructure = require ('../plugins/pay-structure');
seneca.use(payStructure);
seneca.add({role:'payroll', cmd:'generate-weekly-report-data'}, function (args, done) {
act({role:'pay-structure', cmd:'get'})
.then(function (pay_structure) {
var referralPayRate = pay_structure.referralPayRate
var stylistPayRate = pay_structure.stylistPayRate
done(null, act({role:'transactions', cmd:'get_week', wc: args.wc, condense: true, totals: true }))
})
.catch(function (err) {
done(err)
});
});
}
任何幫助表示讚賞。