Skip to content

Commit 1a1840b

Browse files
committed
const/let & just return messages.newMessageWithBody
1 parent 4705f7b commit 1a1840b

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

lib/actions/checkAvailability.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,11 @@ const ApiClient = require('../apiClient');
55
module.exports.process = processAction;
66

77
async function processAction(msg, cfg) {
8-
try {
9-
const client = ApiClient(cfg);
10-
let currentTime = msg.body.time || (new Date()).toISOString();
11-
let events = await client.get(`/me/events?$filter=start/dateTime le '${currentTime}'
12-
and end/dateTime ge '${currentTime}'`);
13-
this.emit('data', messages.newMessageWithBody({
14-
available: !events.value.length
15-
}));
16-
} catch (e) {
17-
console.log(e.error);
18-
this.emit('error', e);
19-
} finally {
20-
this.emit('end');
21-
}
8+
const client = ApiClient(cfg);
9+
const currentTime = msg.body.time || (new Date()).toISOString();
10+
const events = await client.get(`/me/events?$filter=start/dateTime le '${currentTime}'
11+
and end/dateTime ge '${currentTime}'`);
12+
return messages.newMessageWithBody({
13+
available: !events.value.length
14+
});
2215
}

lib/actions/findNextAvailableTime.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,15 @@ const ApiClient = require('../apiClient');
55
module.exports.process = processAction;
66

77
async function processAction(msg, cfg) {
8-
try {
98
const client = ApiClient(cfg);
109
let time = msg.body.time || (new Date()).toISOString();
11-
let events = await client.get(`/me/events?$filter=start/dateTime le '${time}'
12-
and end/dateTime ge '${time}'`);
10+
const events = await client.get(`/me/events?$filter=start/dateTime le '${time}'
11+
and end/dateTime ge '${time}'`);
1312
if (events.value.length) {
14-
time = events.value.pop().end.dateTime
13+
time = events.value.pop().end.dateTime;
1514
}
16-
this.emit('data', messages.newMessageWithBody({
17-
time: time,
18-
subject: msg.body.subject
19-
}));
20-
} catch (e) {
21-
console.log(e.error);
22-
this.emit('error', e);
23-
} finally {
24-
this.emit('end');
25-
}
26-
}
15+
return messages.newMessageWithBody({
16+
time,
17+
subject: msg.body.subject
18+
});
19+
}

0 commit comments

Comments
 (0)