diff --git a/app.js b/app.js index 187fcae..0fc837f 100644 --- a/app.js +++ b/app.js @@ -1,16 +1,177 @@ -const books = [ - { author: "J.D. Salinger", title: "The Catcher in the Rye", id: 1 }, - { author: "Harper Lee", title: "To Kill a Mockingbird", id: 2 }, - { author: "George Orwell", title: "1984", id: 3 }, - { author: "F. Scott Fitzgerald", title: "The Great Gatsby", id: 4 }, - { author: "Jane Austen", title: "Pride and Prejudice", id: 5 }, +function Library(name, books) +{ +this.name=name; +this.books = [...books]; +this.addBook=function(title,author) +{ + console.log("__________ADD__________"); + let new_book; + let id; + let status; + id=this.books[this.books.length-1].id+1; + status=new BookStatus(); + new_book=new Book(title,author,id,status); + this.books.push(new_book); + console.log("the book ((("+new_book.title+"))) Aadded to the library "); + console.log("_______________________"); +} +this.checkOutBook = function(id, patron) +{ + console.log("__________CHECK OUT__________"); + let test_id=false; + let test_book; + test_book = this.books.find(function(v){ + return v.id == id; + }); + if(test_book != undefined) + { + if(test_book.status.checkOut == false) + { + test_book.status.checkOut=true; + test_book.status.patron = {...patron}; + // test_book.status.patron.id = patron.id; + console.log("the book ((("+test_book.title+"))) cheked out from the library , by ((("+patron.name+")))"); + }else + { + console.log("Sooory!!! this book ((("+test_book.title+" ))) can not checked out , becuase the books is checked out"); + } + }else + { + console.log("Sooory!!! the book with id : ((("+id+" ))) can not checked out , becuase the books is removed"); + } + console.log("__________________________"); +} +this.removeBook=function(id) +{ + console.log("__________REMOVE__________"); + let test_book; + test_book=this.books.find(function(v){ + return v.id==id; + }); + if(test_book) + { + this.books = this.books.filter(function(v){ + return v.id !== id; + }); + console.log("the book ((("+test_book.title+" ))) removed from library"); + }else { - author: "J.K. Rowling", - title: "Harry Potter and the Philosopher's Stone", - id: 6, - }, - { author: "J.R.R. Tolkien", title: "The Hobbit", id: 7 }, - { author: "George Orwell", title: "The Lord of the Rings", id: 8 }, - { author: "Aldous Huxley", title: "Animal Farm", id: 9 }, - { author: "Aldous Huxley", title: "Brave New World", id: 10 }, + console.log("the book with id : ((("+id+" ))) can not removed , becuase it is unavailable"); + } + console.log("__________________________"); +} +this.checkIn=function(id) +{ + let test_book; + test_book = this.books.find(function(v){ + return v.id==id; + }); + if(test_book) + { + test_book.status.checkOut=false; + test_book.status.patron=null; + console.log("the book ((( "+test_book.title+" ))) check in to library"); + + } +} +this.getBookById=function(id) +{ + let test_book; + test_book=this.books.find(function(v){ + return v.id == id; + }); + return test_book; +} +this.display=function() +{ + console.log("__________________________DISPLAY__________________________"); + for(let i=0;i