我正在尝试将 Bluebird 与 Seneca 一起使用,以保证我创建的所有 seneca 模块。我希望能够链接 seneca 命令。
这是一个事务模块,它使事情尽可能简单,只有一个任务,创建一个事务
// ./app/transaction.js
module.exports = function(options) {
var Promise = require('bluebird');
var seneca = this;
var act = Promise.promisify(seneca.act, {context: seneca});
var Transaction = require('./models/transaction');
this.add({role:'transaction', cmd: 'create'}, function( msg, done ) {
var t = new Transaction({
datetime: new Date(),
stylist_ids: ["STY_001", "STY_002"],
promoter_ids: ["HOT_001", "HOT_002"],
amount: 100
});
t.save((err,transaction) => {
if (err)
done(err);
else
done(null, { transaction: transaction });
});
})
}
这是我的 server.js 代码,目前应该只使用 seneca 命令创建一个事务:
// server.js
var mongoose = require('mongoose');
mongoose.connect("mongodb://localhost:27017/promisfy");
var seneca = require('seneca')();
var Promise = require('bluebird');
var act = Promise.promisify(seneca.act, seneca);
var transaction = require ('./app/transaction');
seneca.use(transaction);
act({role:'transaction', cmd: 'create'})
.then(function (result) {
console.log(result)
})
.catch(function (err) {
console.log(err)
});
但我得到这个错误:
TypeError: Cannot read property 'ge' of undefined
at do_act (/Users/jackrobson/development/active/glam-army-admin-app/node_modules/seneca/seneca.js:1046:30)
at Object.api_act (/Users/jackrobson/development/active/glam-army-admin-app/node_modules/seneca/seneca.js:867:5)
at Object.tryCatcher (/Users/jackrobson/development/active/glam-army-admin-app/node_modules/bluebird/js/release/util.js:16:23)
at ret (eval at makeNodePromisifiedEval (/Users/jackrobson/development/active/glam-army-admin-app/node_modules/bluebird/js/release/promisify.js:184:12), <anonymous>:14:23)
at Object.<anonymous> (/Users/jackrobson/development/active/glam-army-admin-app/server.js:11:1)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:418:7)
at startup (bootstrap_node.js:139:9)
at bootstrap_node.js:533:3
任何帮助表示赞赏。谢谢 :)