Skip to content

fix: Allow to set false for actions without mixins#1355

Open
Embraser01 wants to merge 1 commit into
moleculerjs:masterfrom
Embraser01:allow-false-actions-without-mixins
Open

fix: Allow to set false for actions without mixins#1355
Embraser01 wants to merge 1 commit into
moleculerjs:masterfrom
Embraser01:allow-false-actions-without-mixins

Conversation

@Embraser01
Copy link
Copy Markdown

📝 Description

This allows to easily have "conditional" actions defined in your service (cf. exemple).
The alternative is to wrap it with an object spread or have a "false" mixin handler.

🎯 Relevant issues

I didn't find any issue about that, but I can create one if you prefer.

💎 Type of change

  • Bug fix (non-breaking change which fixes an issue)

📜 Example code

export default {
	name: 'test',
	actions: {
		sum: !env.ENABLE_SUM && {
			handler(ctx) {
				return ctx.params.a + ctx.params.b
			}
		}
	}
}

🚦 How Has This Been Tested?

We got the issue on our side and found the mergeSchemaActions method that handles it. I then found a test case to
add this use case to see if I could repro it.
Once reproduced in unit tests, I fixed it in the code.

🏁 Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have commented my code, particularly in hard-to-understand areas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant