Problem is that Realtime database can be queried by only one field at a time. So the way to go might be:
- Run query on dates and return who's valid;
- On each reservation add one more field -
uID_dateValid
that takes the uid string and simply adds valid to it - KGHFHJKJ_VALID
- Now just run query on newly added field and return result to your component.
So in your case it would be something like:
const dateValid$ = this.firebase.database.list('/reservations', {
var currentTime = new Date().getTime();
query: {
orderByChild: 'date',
startAt: currentTime
}
});
// just to note - you might not need three rows like you have now -
// "date", "dateTime", "time". You can save one row where value is a
// timestamp, like in my variable "currentTime" above.
dateValid$.map(items => items.map(item => {
var key = item.$key;
var uID_dateValid = item.uID + '_VALID';
dataToSave[`reservations/${key}/uID_dateValid`] = uID_dateValid;
return this.firebaseUpdate(dataToSave);
})).subscribe();
And now you can query that and return:
return this.firebase.database.list('/reservations', {
var valid = uID + '_VALID';
query: {
orderByChild: 'uID_dateValid',
equalTo: valid
}
});
There might be some syntax or minor logic mistakes, but the idea is clear.
Other way would be, just to query database twice, get both lists and filter them on client side.
And one more way might be to query twice, get those two Observables, find the matching records and return Observable of those keys, but in context of streams I am a bit unsure how this could be done..