@pryv/monitor
Version:
Extends `pryv` with event-driven notifications for changes on a Pryv.io account
30 lines (28 loc) • 952 B
JavaScript
/**
* @license
* [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
*/
const Changes = require('./Changes');
module.exports = async function _updateEvents (monitor) {
function forEachEvent (event) {
// update eventsGetScope with "latest modified" information found
if (event.modified > monitor.eventsGetScope.modifiedSince) {
monitor.eventsGetScope.modifiedSince = event.modified;
}
if (event.deleted) {
// event.delete is actually the date it was deleted.
// use it as "modified" information
if (event.deleted > monitor.eventsGetScope.modifiedSince) {
monitor.eventsGetScope.modifiedSince = event.deleted;
}
monitor.emit(Changes.EVENT_DELETE, event);
} else {
monitor.emit(Changes.EVENT, event);
}
}
try {
await monitor.connection.getEventsStreamed(monitor.eventsGetScope, forEachEvent);
} catch (e) {
monitor.emit(Changes.ERROR, e);
}
};