-
-
Save kleberksms/3ad340808e088a75ffecc3eceb89c216 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const general = this.scheduleService.getQueryCollection(ref => ref | |
.where('patientId', '==', uid) | |
.orderBy('date', 'asc')); | |
const appointments = this.scheduleService.getQueryCollection(ref => ref | |
.where('patients', 'array-contains', uid) | |
.orderBy('date', 'asc')); | |
combineLatest([general, appointments]).pipe( | |
map(arr => arr.reduce((acc, cur) => acc.concat(cur))), | |
).subscribe((schedules: Array<Schedule>) => { | |
this.schedules = schedules | |
.reduce((a: Array<Schedule>, b: Schedule) => { | |
if (b.patientId !== uid) { | |
b.groups = b.groups.filter((gs: ScheduleGroup) => { | |
return gs.sessions.map(e => e.patient && e.patient.id).indexOf(uid) > -1; | |
}); | |
} | |
const cm = moment(b.isoDate); | |
let add = false; | |
for (let index = 0; index < a.length; index++) { | |
const lm = moment(a[index].isoDate); | |
if (cm.isSame(lm, 'year') && cm.isSame(lm, 'month') && cm.isSame(lm, 'day')) { | |
a[index].groups = a[index].groups | |
.concat(b.groups) | |
.sort((aa: ScheduleGroup, bb: ScheduleGroup) => { | |
if (moment(aa.time).isSameOrBefore(bb.time)) { | |
return -1; | |
} | |
if (moment(aa.time).isSameOrAfter(aa.time)) { | |
return 1; | |
} | |
return 0; | |
}); | |
add = true; | |
} | |
} | |
if (!add) { | |
a.push(b); | |
} | |
return a; | |
}, []) | |
.sort((a: Schedule, b: Schedule) => { | |
if (moment(a.isoDate).isSameOrBefore(b.isoDate)) { | |
return -1; | |
} | |
if (moment(a.isoDate).isSameOrAfter(b.isoDate)) { | |
return 1; | |
} | |
return 0; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment