Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add triggers & actions to your feathers app.

License

NotificationsYou must be signed in to change notification settings

fratzinger/feathers-trigger

Repository files navigation

NOTE: This is the version for Feathers v5. For Feathers v4 usefeathers-trigger v0

npmGitHub Workflow StatusCode Climate maintainabilityCode Climate coveragelibraries.ionpmGitHub license

Documentation

For more information, please have a look at the docs:https://feathers-trigger.netlify.app/

Installation

npm i feathers-trigger

Usage

Imagine you want to notify users when apost gets published.

How can this be done? In this example apost has apublishedAt property which shows when apost was published. Apost withpublishedAt === null means that thepost is not published yet. Apost can be created as a draft which is not published.

But how do you know when apost gets published? Sounds silly, but there are three possibilities:

  • Apost gets created withpublishedAt: { $ne: null }.
  • Apost gets updated bydatapublishedAt: { $ne: null }, it hadpublishedAt: null before and theresult really haspublishedAt: { $ne: null }.
  • Apost gets patched bydatapublishedAt: { $ne: null }, it hadpublishedAt: null before and theresult really haspublishedAt: { $ne: null }.

How can this be accomplished?

  1. Checkcontext.data forpublishedAt: { $ne: null } and if that's not true, the subscription is not true.
  2. Check if the post in the database haspublishedAt === null and therefore is not published yet. You need to check that in abefore hook. If that's not true, the subscription is not true.
  3. Check if thecontext.result really haspublishedAt: { $ne: null } (maybe it's handled by another permission hook, or something). If that's not true, the subscription is not true.
  4. If all three checks are true, run thenotify function.

It's up to you how you define thenotify action. For the example above the solution withfeathers-trigger looks like the following:

// posts.hooks.jsimport{trigger}from"feathers-trigger";constnotifyPublished=trigger({data:{publishedAt:{$ne:null}},before:{publishedAt:null},result:{publishedAt:{$ne:null}},action:({ item},context)=>{returncontext.app.service("/notify").create(item);},});exportdefault{before:{create:[notifyPublished],update:[notifyPublished],patch:[notifyPublished],},after:{create:[notifyPublished],update:[notifyPublished],patch:[notifyPublished],},};

For more advanced examples, please have a look at thedocs

Testing

Simply runnpm test and all your tests in thetest/ directory will be run. It has full support forVisual Studio Code. You can use the debugger to set breakpoints.

Help

For more information on all the things you can do, visitFeathersJS.

License

Licensed under theMIT license.

About

Add triggers & actions to your feathers app.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp