Skip to content

Commit 225b2dd

Browse files
committed
chore: simplify the app
1 parent 243d281 commit 225b2dd

File tree

16 files changed

+76
-196
lines changed

16 files changed

+76
-196
lines changed

app.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/*
2-
* Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
3-
* See LICENSE in the project root for license information.
4-
*/
5-
61
import express from 'express';
72
import path from 'path';
83
import favicon from 'serve-favicon';
@@ -22,7 +17,6 @@ app.locals.ENV_DEVELOPMENT = (env === 'development');
2217
app.set('views', path.join(__dirname, 'views'));
2318
app.set('view engine', 'jade');
2419

25-
app.use(favicon(__dirname + '/public/img/favicon.ico'));
2620
app.use(logger('dev'));
2721
app.use(bodyParser.json());
2822
app.use(bodyParser.urlencoded({ extended: true }));
@@ -52,15 +46,15 @@ if (app.get('env') === 'development') {
5246
title: 'error'
5347
});
5448
});
55-
}
56-
57-
// production error handler
58-
// no stacktraces leaked to user
59-
app.use((err, req, res) => {
60-
res.status(err.status || 500);
61-
res.render('error', {
62-
message: err.message,
63-
error: { },
64-
title: 'error'
49+
} else {
50+
// production error handler
51+
// no stacktraces leaked to user
52+
app.use((err, req, res) => {
53+
res.status(err.status || 500);
54+
res.render('error', {
55+
message: err.message,
56+
error: { },
57+
title: 'error'
58+
});
6559
});
66-
});
60+
}

gulpfile.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/*
2-
* Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
3-
* See LICENSE in the project root for license information.
4-
*/
5-
61
var gulp = require('gulp');
72
var nodemon = require('gulp-nodemon');
83
var plumber = require('gulp-plumber'); // eslint-disable-line no-unused-vars

helpers/authHelper.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
/*
2-
* Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
3-
* See LICENSE in the project root for license information.
4-
*/
5-
61
import { AuthenticationContext } from 'adal-node';
2+
73
import { adalConfiguration } from '../constants';
84

95
const resource = 'https://graph.microsoft.com/';
@@ -22,7 +18,6 @@ export function getAuthUrl() {
2218
/**
2319
* Gets a token for a given resource.
2420
* @param {string} code An authorization code returned from a client.
25-
* @param {string} res A URI that identifies the resource for which the token is valid.
2621
* @param {AcquireTokenCallback} callback The callback function.
2722
*/
2823
export function getTokenFromCode(code, callback) {
@@ -34,11 +29,8 @@ export function getTokenFromCode(code, callback) {
3429
adalConfiguration.clientID,
3530
adalConfiguration.clientSecret,
3631
(error, token) => {
37-
if (error) {
38-
callback(error, null);
39-
} else {
40-
callback(null, token);
41-
}
32+
if (error) callback(error, null);
33+
else callback(null, token);
4234
}
4335
);
4436
}

helpers/dbHelper.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/*
2-
* Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
3-
* See LICENSE in the project root for license information.
4-
*/
5-
61
import fs from 'fs';
72
import sql from 'sqlite3';
83

@@ -27,15 +22,13 @@ export function createDatabase() {
2722
'SubscriptionExpirationDateTime TEXT NOT NULL' +
2823
')';
2924

30-
db.serialize(function createTable() {
25+
db.serialize(() => {
3126
if (!dbExists) {
3227
db.run(
3328
createSubscriptionStatement,
3429
[],
35-
function callback(error) {
36-
if (error !== null) {
37-
throw error;
38-
}
30+
error => {
31+
if (error !== null) throw error;
3932
}
4033
);
4134
}
@@ -59,7 +52,7 @@ export function getSubscription(subscriptionId, callback) {
5952
'WHERE SubscriptionId = $subscriptionId ' +
6053
'AND SubscriptionExpirationDateTime > datetime(\'now\')';
6154

62-
db.serialize(function executeSelect() {
55+
db.serialize(() => {
6356
db.get(
6457
getUserDataStatement,
6558
{
@@ -79,7 +72,7 @@ export function saveSubscription(subscriptionData, callback) {
7972
'VALUES ($userId, $subscriptionId, $accessToken, $resource, $changeType, ' +
8073
'$clientState, $notificationUrl, $subscriptionExpirationDateTime)';
8174

82-
db.serialize(function executeInsert() {
75+
db.serialize(() => {
8376
db.run(
8477
insertStatement,
8578
{
@@ -103,12 +96,10 @@ export function deleteSubscription(subscriptionId, callback) {
10396
'DELETE FROM Subscription WHERE ' +
10497
'SubscriptionId = $subscriptionId';
10598

106-
db.serialize(function executeDelete() {
99+
db.serialize(() => {
107100
db.run(
108101
deleteStatement,
109-
{
110-
$subscriptionId: subscriptionId
111-
},
102+
{ $subscriptionId: subscriptionId },
112103
callback
113104
);
114105
});

helpers/requestHelper.js

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/*
2-
* Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
3-
* See LICENSE in the project root for license information.
4-
*/
5-
61
import https from 'https';
72

83
const host = 'graph.microsoft.com';
@@ -28,24 +23,18 @@ export function postData(path, token, data, callback) {
2823

2924
const req = https.request(options, res => {
3025
let subscriptionData = '';
31-
res.on('data', chunk => {
32-
subscriptionData += chunk;
33-
});
26+
27+
res.on('data', chunk => (subscriptionData += chunk));
3428
res.on('end', () => {
35-
if (res.statusCode === 201) {
36-
callback(null, JSON.parse(subscriptionData));
37-
} else {
38-
callback(JSON.parse(subscriptionData), null);
39-
}
29+
if (res.statusCode === 201) callback(null, JSON.parse(subscriptionData));
30+
else callback(JSON.parse(subscriptionData), null);
4031
});
4132
});
4233

4334
req.write(data);
4435
req.end();
4536

46-
req.on('error', error => {
47-
callback(error, null);
48-
});
37+
req.on('error', error => callback(error, null));
4938
}
5039

5140
/**
@@ -69,24 +58,18 @@ export function getData(path, token, callback) {
6958

7059
const req = https.request(options, res => {
7160
let endpointData = '';
72-
res.on('data', chunk => {
73-
endpointData += chunk;
74-
});
61+
62+
res.on('data', chunk => (endpointData += chunk));
7563
res.on('end', () => {
76-
if (res.statusCode === 200) {
77-
callback(null, JSON.parse(endpointData));
78-
} else {
79-
callback(JSON.parse(endpointData), null);
80-
}
64+
if (res.statusCode === 200) callback(null, JSON.parse(endpointData));
65+
else callback(JSON.parse(endpointData), null);
8166
});
8267
});
8368

8469
req.write('');
8570
req.end();
8671

87-
req.on('error', error => {
88-
callback(error, null);
89-
});
72+
req.on('error', error => callback(error, null));
9073
}
9174

9275
/**
@@ -109,17 +92,11 @@ export function deleteData(path, token, callback) {
10992

11093
const req = https.request(options, res => {
11194
let endpointData = '';
112-
res.on('data', chunk => {
113-
endpointData += chunk;
114-
});
115-
res.on('end', () => {
116-
callback(null);
117-
});
95+
res.on('data', chunk => (endpointData += chunk));
96+
res.on('end', () => callback(null));
11897
});
11998

12099
req.end();
121100

122-
req.on('error', error => {
123-
callback(error);
124-
});
101+
req.on('error', error => callback(error));
125102
}

helpers/socketHelper.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/*
2-
* Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
3-
* See LICENSE in the project root for license information.
4-
*/
5-
61
import express from 'express';
72
import http from 'http';
83
import io from 'socket.io';

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "o365-nodejs-webhook",
3-
"version": "0.0.1",
2+
"name": "microsoft-graph-webhook-nodejs",
3+
"version": "1.0.0",
44
"private": true,
55
"scripts": {
66
"start": "mocha ./tests/confTest.js && nodemon --exec babel-node --presets es2015 ./bin/www",
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/*
2-
* Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
3-
* See LICENSE in the project root for license information.
4-
*/
5-
61
const socket = io.connect('http://localhost:3001'); // eslint-disable-line no-undef
72

83
// Socket `notification_received` event handler.
@@ -42,11 +37,10 @@ document.getElementById('signOutButton').onclick = () => {
4237
function getQueryStringParameter(paramToRetrieve) {
4338
const params = document.URL.split('?')[1].split('&');
4439

45-
for (let i = 0; i < params.length; i = i + 1) {
40+
for (let i = 0; i < params.length; i++) {
4641
const singleParam = params[i].split('=');
47-
if (singleParam[0] === paramToRetrieve) {
48-
return singleParam[1];
49-
}
42+
43+
if (singleParam[0] === paramToRetrieve) return singleParam[1];
5044
}
5145
return null;
5246
}

public/css/fabric.components.min.css

Lines changed: 0 additions & 6 deletions
This file was deleted.

public/css/fabric.min.css

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)