Skip to content
This repository was archived by the owner on Aug 3, 2018. It is now read-only.

Commit 30caacc

Browse files
SebastianMartin
authored andcommitted
fix(appointment-helper): fix query for finding next appointment (#180)
(cherry picked from commit b3c88fc)
1 parent 4b9bf08 commit 30caacc

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/app/helper/appointment.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,29 @@ appointmentHelper.notify = () => new Promise(async (resolve) => {
7171
const now = moment.tz(settings.appointmentsTimezone);
7272

7373
let nextAppointment = await Appointment
74-
.findOne({
74+
.find({
7575
user: { $exists: true, $ne: null },
7676
weekDay: now.weekday(),
7777
hour: {
7878
$gte: now.hours() * 100 + now.minutes(),
7979
}
8080
})
81+
.sort({
82+
hour: 'asc'
83+
})
84+
.limit(1)
8185
.populate('user', 'name gravatarHash')
86+
.lean()
8287
.then();
8388

8489

85-
if (!nextAppointment) {
90+
if (!nextAppointment || nextAppointment.length < 1) {
8691
resolve('No appointment found. Aborting.');
8792
return;
8893
}
8994

95+
nextAppointment = nextAppointment[0];
96+
9097
if (settings.appointmentsIncrement) {
9198
// add global increment
9299
nextAppointment = appointmentHelper.addIncrement(nextAppointment, settings.appointmentsIncrement);

0 commit comments

Comments
 (0)