// film.service.ts

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

@Injectable({
  providedIn: 'root'
})
export class BookService {
  private Book = Parse.Object.extend('LQLBook');

 constructor() {}

 async getBooks(queryParams: any): Promise<Parse.Object[]> {
   const query = new Parse.Query(this.Book);
   if (queryParams.name) {
     query.contains('name', queryParams.name);
   }
   if (queryParams.author) {
     query.equalTo('aouhor', queryParams.aouhor);
   }
   if (queryParams.sortByrating) {
     query.ascending('rating');
   } else {
     query.descending('rating');
   }
   return await query.find();
 }

//   async getBooks(): Promise<any[]> {
//     const Book = Parse.Object.extend('Book');
//     const query = new Parse.Query(Book);
//     return await query.find();
//   }

//   async getSortedBooksByRating(): Promise<any[]> {
//     const Book = Parse.Object.extend('Book');
//     const query = new Parse.Query(Book);
//     query.descending('rating');
//     return await query.find();
//   }

}