moleculerjs / database

Advanced Database Access Service for Moleculer microservices framework
MIT License
32 stars 16 forks source link

Wrong check createActions #12

Closed maxinminax closed 2 years ago

maxinminax commented 2 years ago

https://github.com/moleculerjs/database/blob/ed33d2dcbacb6d3ac8793e0698e1a9c5e71d008d/src/actions.js#L55-L60

it must be:

const actionEnabled = name => { 
    return ( 
        mixinOpts.createActions === true || 
        (typeof mixinOpts.createActions == "object" && mixinOpts.createActions[name] === true) 
    ); 
 }; 
icebob commented 2 years ago

What is the use-case when the original code is wrong?

maxinminax commented 2 years ago

What is the use-case when the original code is wrong?

When I disable some service actions via createActions option As in the document:

module.exports = {
    mixins: [DbService({
        createActions: {
            find: false,
            replace: false
        }
    })]
}

If createActions is a Object, actionEnabled will always return true and all actions will be created Because default value of createActions is true, so I have updated my resolve:

const actionEnabled = name => {
    if (typeof mixinOpts.createActions === "object") {
        return mixinOpts.createActions[name] !== false;
    }
    return mixinOpts.createActions !== false;
};
icebob commented 2 years ago

You are right, thanks. I'm fixing...

maxinminax commented 2 years ago

What is the use-case when the original code is wrong?

When I disable some service actions via createActions option As in the document:

module.exports = {
    mixins: [DbService({
        createActions: {
            find: false,
            replace: false
        }
    })]
}

If createActions is a Object, actionEnabled will always return true and all actions will be created Because default value of createActions is true, so I have updated my resolve:

const actionEnabled = name => {
  if (typeof mixinOpts.createActions === "object") {
      return mixinOpts.createActions[name] !== false;
  }
  return mixinOpts.createActions !== false;
};

sorry but I have updated my resolve, because default actions is will be created, so must be check it's not false (set false to disable): mixinOpts.createActions[name] !== false

As the case in document:

module.exports = {
    mixins: [DbService({
        createActions: {
            find: false,
            replace: false
        }
    })]
}

No action is true in the createActions object, so don't have any actions will be create

icebob commented 2 years ago

Could you please open a PR with your solution? Thanks in advance