-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to trigger events directly from the API (#137)
* Add ability to trigger events directly from the API * Add documentation for directly triggering an event * Fix English
- Loading branch information
1 parent
bd08733
commit 5c8996d
Showing
5 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const app = (module.exports = require('express')()); | ||
const EventTrigger = require('../domain/event/EventTrigger.js'); | ||
const Config = require('../config/ConfigLoaderFactory') | ||
.getLoader() | ||
.getConfig(); | ||
|
||
app.post('/', (request, response) => { | ||
console.log('/event [POST]'); | ||
|
||
const eventName = request.body.event; | ||
|
||
if (!eventName) { | ||
return response.status(422).json({ | ||
message: `Missing required field "event".`, | ||
}); | ||
} | ||
|
||
if (Config.getEventByName(eventName)) { | ||
EventTrigger.fireModulesForEvent(eventName, null); | ||
|
||
return response.json({ | ||
message: 'Event has been triggered!', | ||
}); | ||
} | ||
|
||
return response.status(404).json({ | ||
message: `The given event name "${eventName}" is not found.`, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters