zygos / moleculer-adapter-feathers

Moleculer service mixin wrapping Feathers.js services
MIT License
17 stars 2 forks source link

Problem in hooks #2

Open ParraAlejandro opened 5 years ago

ParraAlejandro commented 5 years ago

hi ! I want to use the all hooks "before, after and error". But I read the documentation and only mentions "before and after". When I declare the hook for "error", it's breaks and shows a message of "registeredService [hooksType]".

I'm using "feathers-knex": "^5.0.5",

This is the mensaje of error:

 registeredService[hooksType] is not a function TypeError: registeredService[hooksType] is not a function
    at Object.register (/app/node_modules/moleculer-adapter-feathers/src/services.js:32:35)
    at Service.created (/app/node_modules/moleculer-adapter-feathers/src/index.js:94:30)
    at schema.created.forEach.fn (/app/node_modules/moleculer/src/service.js:174:41)
    at Array.forEach (<anonymous>)
    at Service._init (/app/node_modules/moleculer/src/service.js:174:24)
    at Service.parseServiceSchema (/app/node_modules/moleculer/src/service.js:148:8)
    at new Service (/app/node_modules/moleculer/src/service.js:57:9)
    at ServiceBroker.createService (/app/node_modules/moleculer/src/service-broker.js:636:14)
    at ServiceBroker.loadService (/app/node_modules/moleculer/src/service-broker.js:563:15)
    at _.uniq.forEach.f (/app/node_modules/moleculer/bin/moleculer-runner.js:352:44)
    at Array.forEach (<anonymous>)
    at loadServices (/app/node_modules/moleculer/bin/moleculer-runner.js:352:24)
    at startBroker (/app/node_modules/moleculer/bin/moleculer-runner.js:422:2)
    at tryCatcher (/app/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/app/node_modules/bluebird/js/release/promise.

I would appreciate help.

hooks.js

module.exports = {
    before: {
        all: [],
        create: [],
        find: [],
        get: [],
        update: [],
        patch: [],
        remove: [],
    },
    after: {
        all: [],
        create: [],
        find: [],
        get: [],
        update: [],
        patch: [],
        remove: [],
    },
    error: {
        all: [],
        find: [],
        get: [],
        create: [],
        update: [],
        patch: [],
        remove: []
    }
}

service.js

const Feathers = require("moleculer-adapter-feathers");
const feathersKnex = require("feathers-knex");
const knex = require("knex");
const databaseConf = require("../../config/database.config.json");

module.exports = {
    name: "myservicedb",
    mixins: [Feathers],
    settings: {
        feathers: {
            adapter: feathersKnex,
            hooks: require('./hooks'),
            options: {
                name: "myTable",
                id: 'myId',
                paginate: databaseConf.paginate,
                Model: new knex({
                    client: 'oracledb',
                    connection: {
                        user: databaseConf.usermame,
                        password: databaseConf.password,
                        host: databaseConf.host,
                        database: databaseConf.database
                    },
                    useNullAsDefault: true,
                    pool: {
                        min: databaseConf.poolMin,
                        max: databaseConf.poolMax
                    },
                    acquireConnectionTimeout: databaseConf.timeout
                }),
            },
        },
    },
    dependencies: [],
    actions: {},
    events: {},
    methods: {},
    created() {},
    started() {},
    stopped() {
    }
};
ghost commented 5 years ago

It looks 'error' hook is not supported.

https://www.npmjs.com/package/feathers-hooks This package has been deprecated