import { Injectable } from '@angular/core';
import Parse from 'parse';

@Injectable({
  providedIn: 'root'
})
export class PetService {
  private Foodcourt = Parse.Object.extend('Foodcourt');

  constructor() {}

  async getFoodcourts(queryParams: any): Promise<Parse.Object[]> {
    const query = new Parse.Query(this.Foodcourt);
    if (queryParams.name) {
      query.contains('name', queryParams.name);
    }
    if (queryParams.type) {
      query.equalTo('type', queryParams.type);
    }
    if (queryParams.sortByName) {
      query.ascending('name');
    } else {
      query.descending('name');
    }
    return await query.find();
  }
}