Skip to content

Commit 6665a5f

Browse files
committed
Fixed ESLINT warnings, migrated to salior 2.0 and now using promises in trigger
1 parent b4e0690 commit 6665a5f

File tree

6 files changed

+25
-32
lines changed

6 files changed

+25
-32
lines changed

lib/actions/createEvent.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/*eslint no-console: 0 consistent-this: 0*/
12
'use strict';
23
const elasticio = require('elasticio-node');
34
const messages = elasticio.messages;
@@ -21,14 +22,13 @@ function getCalendars(cfg, cb) {
2122
console.log('Getting calendar data ...');
2223
const instance = new ApiClient(cfg);
2324
return instance
24-
.get('/me/calendars')
25-
.then(processData)
26-
.nodeify(cb);
25+
.get('/me/calendars')
26+
.then(processData)
27+
.nodeify(cb);
2728
}
2829

2930

3031
function processAction(msg, cfg) {
31-
3232
const self = this;
3333
const calendarId = cfg.calendarId;
3434
console.log(`About to create event in calendar with id=${calendarId}`);
@@ -65,9 +65,9 @@ function processAction(msg, cfg) {
6565

6666

6767
let promise = processEventData(cfg, msg.body)
68-
.then(createEvent)
69-
.then(emitData)
70-
.fail(emitError);
68+
.then(createEvent)
69+
.then(emitData)
70+
.fail(emitError);
7171

7272
return promise.finally(emitEnd);
7373

lib/processEventDataHelper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/*eslint no-console: 0 */
12
'use strict';
23
const moment = require('moment-timezone');
34
const _ = require('lodash');

lib/triggers/contacts.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
/* eslint new-cap: [2, {"capIsNewExceptions": ["Q"]}] */
1+
/* eslint no-console: 0 no-invalid-this: 0*/
22
'use strict';
33
const messages = require('elasticio-node').messages;
44
const co = require('co');
55
const MicrosoftGraph = require('msgraph-sdk-javascript');
66
const rp = require('request-promise');
77

8-
module.exports.process = processAction;
9-
108
/**
119
* This method will be called from elastic.io platform providing following data
1210
*
1311
* @param msg incoming message object that contains ``body`` with payload
1412
* @param cfg configuration that is account information and configuration field values
13+
* @param snapshot - snapshot that stores the data between the runs
1514
*/
1615
function processAction(msg, cfg, snapshot) {
1716
console.log('Snapshot is %j', snapshot);
1817

19-
// Should be in ISO-Date format
18+
// Should be in ISO-Date format
2019
snapshot.lastModifiedDateTime = snapshot.lastModifiedDateTime || new Date(0).toISOString();
2120

22-
// Main loop
23-
co(function* mainLoop() {
21+
// Main loop
22+
return co(function* mainLoop() {
2423
console.log('Refreshing an OAuth Token');
2524
const newToken = yield rp({
2625
method: 'POST',
@@ -49,11 +48,11 @@ function processAction(msg, cfg, snapshot) {
4948

5049
console.log('Selecting contacts that was modified since %s', snapshot.lastModifiedDateTime);
5150
const contacts = yield client
52-
.api('/me/contacts')
53-
.orderby('lastModifiedDateTime asc')
54-
.top(900)
55-
.filter('lastModifiedDateTime gt ' + snapshot.lastModifiedDateTime)
56-
.get();
51+
.api('/me/contacts')
52+
.orderby('lastModifiedDateTime asc')
53+
.top(900)
54+
.filter('lastModifiedDateTime gt ' + snapshot.lastModifiedDateTime)
55+
.get();
5756
const values = contacts.value;
5857
console.log('Found %s contacts', values.length);
5958
if (values.length > 0) {
@@ -62,20 +61,17 @@ function processAction(msg, cfg, snapshot) {
6261
});
6362
this.emit('data', message);
6463
let lmdate = new Date(values[values.length - 1].lastModifiedDateTime);
65-
// The output value has always 0 milliseconds
66-
// we need to set the milliseconds value to 999 in order not to see
67-
// the duplicate results
64+
// The output value has always 0 milliseconds
65+
// we need to set the milliseconds value to 999 in order not to see
66+
// the duplicate results
6867
lmdate.setMilliseconds(999);
6968
snapshot.lastModifiedDateTime = lmdate.toISOString();
7069
} else {
7170
console.log('No contacts modified since %s were found', snapshot.lastModifiedDateTime);
7271
}
7372
console.log('Processing completed, new lastModifiedDateTime is ' + snapshot.lastModifiedDateTime);
7473
this.emit('snapshot', snapshot);
75-
this.emit('end');
76-
}.bind(this)).catch(err => {
77-
console.log('Error occured', err.stack || err);
78-
this.emit('error', err);
79-
this.emit('end');
80-
});
74+
}.bind(this));
8175
}
76+
77+
module.exports.process = processAction;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"bluebird": "^3.4.6",
2828
"co": "^4.6.0",
2929
"elasticio-node": "0.0.7",
30-
"elasticio-sailor-nodejs": "1.3.0",
30+
"elasticio-sailor-nodejs": "2.0.0",
3131
"lodash": "^4.17.2",
3232
"moment": "^2.1.16",
3333
"moment-timezone": "^0.5.9",

spec/helpers/checkRequiredFields.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
'use strict';
2-
const moment = require('moment');
32

43
describe('Outlook Check Required Fields', function test() {
54

65
const action = require('../../lib/processEventDataHelper');
7-
const data = require('../data/processEventData_test.json');
86

97
it('throws an error when required cfg field calendarId is missing', function test() {
108
let configInput = {

spec/helpers/formatDate.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
'use strict';
2-
const moment = require('moment');
32

43
describe('Outlook Format Date', function test() {
54

65
const action = require('../../lib/processEventDataHelper');
7-
const data = require('../data/processEventData_test.json');
86

97
//Check if the date FORMAT itself is as expected.
108
describe('formats input date string based on given parameter ', function test() {

0 commit comments

Comments
 (0)