I have a restaurant list where I want to use filters where the user can filter the restaurantlist on. So this is the data how a filter object would look like:
dishType:(3) ["Pasta", "Barbecue", "Casual Dining"]
dishnationality:(4) ["Korean", "Indian", "Arabian", "German"]
organizeby:"Low Price"
Here I allready have a query for orgranizing them on most rated like this:
export class RestaurantService {
restaurantsRef: AngularFireList<any>;
restaurantsList: Observable<any[]>;
constructor(
public afDb: AngularFireDatabase,
public storage: Storage
// public homePage: HomePage
) {
this.restaurantsRef = afDb.list('/restaurants');
this.restaurantsList = this.restaurantsRef.valueChanges();
}
getFilters(filters) {
if (filters.organizeby === "Most rating") {
this.restaurantsRef = this.afDb.list('/restaurants', ref => ref.orderByChild('rating'));
this.restaurantsList = this.restaurantsRef.valueChanges();
}
return this.restaurantsList;
}
But how can I do a multiple query based on the filter object I show above?
Or do I have to think an other way in firebase like storing the restaurants in an array to iterate over en push back the matching values?
What I have tried to do is creating a composite_key in my firebase db:
getFilters(filters) {
let dishtype = filters.dishtype;
let dishnationality = filters.dishnationality;
let composite_key = `${dishnationality}_${dishtype}`;
console.log(dishtype, dishnationality)
if(composite_key){
this.restaurantsRef = this.afDb.list('/restaurants', ref => ref.orderByChild('tag_dishnationality').equalTo(composite_key));
this.restaurantsList = this.restaurantsRef.valueChanges();
}
if (filters.organizeby === "Most rating") {
this.restaurantsRef = this.afDb.list('/restaurants', ref => ref.orderByChild('rating'));
this.restaurantsList = this.restaurantsRef.valueChanges();
}
return this.restaurantsList;
}
But How do I deal with that multiple array values and combining them?