1
- /* eslint new-cap: [2, {"capIsNewExceptions": ["Q"]}] */
1
+ /* eslint no-console: 0 no-invalid-this: 0 */
2
2
'use strict' ;
3
3
const messages = require ( 'elasticio-node' ) . messages ;
4
4
const co = require ( 'co' ) ;
5
5
const MicrosoftGraph = require ( 'msgraph-sdk-javascript' ) ;
6
6
const rp = require ( 'request-promise' ) ;
7
7
8
- module . exports . process = processAction ;
9
-
10
8
/**
11
9
* This method will be called from elastic.io platform providing following data
12
10
*
13
11
* @param msg incoming message object that contains ``body`` with payload
14
12
* @param cfg configuration that is account information and configuration field values
13
+ * @param snapshot - snapshot that stores the data between the runs
15
14
*/
16
15
function processAction ( msg , cfg , snapshot ) {
17
16
console . log ( 'Snapshot is %j' , snapshot ) ;
18
17
19
- // Should be in ISO-Date format
18
+ // Should be in ISO-Date format
20
19
snapshot . lastModifiedDateTime = snapshot . lastModifiedDateTime || new Date ( 0 ) . toISOString ( ) ;
21
20
22
- // Main loop
23
- co ( function * mainLoop ( ) {
21
+ // Main loop
22
+ return co ( function * mainLoop ( ) {
24
23
console . log ( 'Refreshing an OAuth Token' ) ;
25
24
const newToken = yield rp ( {
26
25
method : 'POST' ,
@@ -49,11 +48,11 @@ function processAction(msg, cfg, snapshot) {
49
48
50
49
console . log ( 'Selecting contacts that was modified since %s' , snapshot . lastModifiedDateTime ) ;
51
50
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 ( ) ;
57
56
const values = contacts . value ;
58
57
console . log ( 'Found %s contacts' , values . length ) ;
59
58
if ( values . length > 0 ) {
@@ -62,20 +61,17 @@ function processAction(msg, cfg, snapshot) {
62
61
} ) ;
63
62
this . emit ( 'data' , message ) ;
64
63
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
68
67
lmdate . setMilliseconds ( 999 ) ;
69
68
snapshot . lastModifiedDateTime = lmdate . toISOString ( ) ;
70
69
} else {
71
70
console . log ( 'No contacts modified since %s were found' , snapshot . lastModifiedDateTime ) ;
72
71
}
73
72
console . log ( 'Processing completed, new lastModifiedDateTime is ' + snapshot . lastModifiedDateTime ) ;
74
73
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 ) ) ;
81
75
}
76
+
77
+ module . exports . process = processAction ;
0 commit comments