terra-notification
v1.0.4
Published
build notifications and retrieve
Downloads
10
Readme
notification-builder
library basically provides two classes Notification and NotificationBuilder to create, update and fetch notification workers on terra.
Install
npm i terra-notification
NotificationBuilder
this class process the data in json format and also provides function to get Notification objects.
Import
const builder = require("terra-notification").NotificationBuilder;
Usage
var obj = new builder();
//first parameter is type of notification and second parameter is no of notifications
let list = await obj.getNotifications("mail", 5); // get first 5 pending notifications as list of Notification Object
var json = await obj.create("mail", { email: "[email protected]", templateId: "T1" }); //creates a new notication and returns the same.
other methods are :
- setDone(id)
- setProcessing(id)
- setFailed(id)
- get(type,noOfNotifications) // will return list of json objects
TaskNotification
this class processes the data within the class.
Import
const notification = require("terra-notification").TaskNotification;
Usage
//first parameter is type of notification and second parameter is input json
var task = new Notification("mail", { email: "[email protected]", templateId: "T1" });
let result = await task.create(); //returns true if notification is created
methods are :
- create()
- markAsInitiated()
- markAsDone()
- markAsFailed()
- setAll(json) // set all values from json
sample json :
{ id: 1836,notificationType: 'mail', status: 'created',inputJson: '{"email":"[email protected]","templateId":"T1"}' }
* Note : input json can be any json as per task need. To test worker use --experimental-worker flag with server.js like as follow :
node --experimental-worker server.js