Skip to content

Commit f7d14cb

Browse files
committed
Reduce duplicate logic when buidling response
1 parent 64178f7 commit f7d14cb

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lib/commands/implementations/schedule.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ function getNextStreamDate(input, services) {
1212

1313
const { allDay, name, start, childEvent } = nextStreamDay;
1414
const isHappening = start.isBefore(moment());
15-
const startTime = start.fromNow();
16-
const link = services.schedule.link();
1715
let scheduleOutput = '';
1816

19-
if (isHappening) {
20-
scheduleOutput = allDay
21-
? `${name}, an all-day event, is scheduled today. ${link}`
22-
: `${name} is currently happening! It started ${startTime}. ${link}`;
23-
24-
if (allDay && childEvent) {
17+
if (isHappening && allDay) {
18+
scheduleOutput = `${name}, an all-day event, is scheduled today.`;
19+
if (childEvent) {
2520
const childEventIsHappening = moment(childEvent.start).isBefore(moment());
21+
2622
// prettier-ignore
27-
scheduleOutput = childEventIsHappening
28-
? `${name}, an all-day event, is scheduled today. ${childEvent.name} is currently happening! It started ${childEvent.start.fromNow()}. ${link}`
29-
: `${name}, an all-day event, is scheduled today. Coming up ${childEvent.start.fromNow()} is ${childEvent.name}. ${link}`;
23+
scheduleOutput += childEventIsHappening
24+
? ` ${childEvent.name} is currently happening! It started ${childEvent.start.fromNow()}.`
25+
: ` Coming up ${childEvent.start.fromNow()} is ${childEvent.name}.`;
3026
}
27+
} else if (isHappening) {
28+
scheduleOutput = `${name} is currently happening! It started ${start.fromNow()}.`;
3129
} else {
32-
scheduleOutput = `${name} is the next scheduled event. It starts ${startTime}. ${link}`;
30+
scheduleOutput = `${name} is the next scheduled event. It starts ${start.fromNow()}.`;
3331
}
3432

33+
scheduleOutput += ` ${services.schedule.link()}`;
34+
3535
return new CommandOutput(null, scheduleOutput);
3636
})
3737
.catch((err) => new CommandOutput(err, "Oops. Something didn't work. Check the logs."));

0 commit comments

Comments
 (0)