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

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

 constructor() {}

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