|
| 1 | + |
| 2 | +const BookStatus = { |
| 3 | + AVAILABLE: 'AVAILABLE', |
| 4 | + LOANED: 'LOANED', |
| 5 | + LOST: 'LOST' |
| 6 | +}; |
| 7 | +const AccountStatus = { |
| 8 | + ACTIVE: 'ACTIVE', |
| 9 | + INACTIVE: 'INACTIVE', |
| 10 | + CLOSED: 'CLOSED', |
| 11 | + BLACKLISTED: 'BLACKLISTED' |
| 12 | +}; |
| 13 | + |
| 14 | +class LibraryCard { |
| 15 | + constructor() { |
| 16 | + this.cardNumber = this.generateRandomCardNumber(); |
| 17 | + this.barCode = this.generateBarcode(); |
| 18 | + this.issuedAt = new Date(); |
| 19 | + this.isActive = true; |
| 20 | + } |
| 21 | + |
| 22 | + setActive(status) { |
| 23 | + this.isActive = status; |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +class Account { |
| 28 | + constructor(name, email, password, status) { |
| 29 | + this.userId = this.geenrateRandomeID(); |
| 30 | + this.name = name; |
| 31 | + this.email = email; |
| 32 | + this.password = password; |
| 33 | + this.status = status; |
| 34 | + this.libraryCard = new LibraryCard(); |
| 35 | + } |
| 36 | + |
| 37 | + login(email, password) { |
| 38 | + if (email === this.email && this.password === password) { |
| 39 | + console.log('Logged IN'); |
| 40 | + this.status = AccountStatus.ACTIVE; |
| 41 | + } |
| 42 | + else { |
| 43 | + console.log('Wrong Credentials') |
| 44 | + } |
| 45 | + } |
| 46 | + logout() { |
| 47 | + this.status = AccountStatus.INACTIVE; |
| 48 | + }; |
| 49 | + resetPassword(oldPassword, newPassword) { |
| 50 | + if (oldPassword === this.password) { |
| 51 | + this.password = newPassword; |
| 52 | + } |
| 53 | + else { |
| 54 | + alert('Old Password does not match') |
| 55 | + } |
| 56 | + }; |
| 57 | + closeAccount() { |
| 58 | + this.status = AccountStatus.CLOSED; |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +class Member extends Account { |
| 63 | + constructor() { |
| 64 | + this.booksBorrowed = 0; |
| 65 | + this.searchBook = new Search(); |
| 66 | + this.dateOfMemeberShip = new Date(); |
| 67 | + } |
| 68 | + |
| 69 | + payFine(amount) { |
| 70 | + |
| 71 | + } |
| 72 | + checkForFine() { |
| 73 | + |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +class Librarian extends Account { |
| 78 | + constructor() { |
| 79 | + this.issueService = new BookIssueService(); |
| 80 | + this.searchBook = new Search(); |
| 81 | + } |
| 82 | + |
| 83 | + addBook(book); |
| 84 | + deleteBook(book_id); |
| 85 | + // return the updated book |
| 86 | + updateBook(book); |
| 87 | + blockMember(member); |
| 88 | + unBlockMember(member); |
| 89 | + cancelMembership(member); |
| 90 | +} |
| 91 | + |
| 92 | +class Search { |
| 93 | + getBookByTitle(title) { |
| 94 | + return this.callAPI(title) |
| 95 | + }; |
| 96 | + getBookByAuthor(author) { |
| 97 | + return this.callAPI(author) |
| 98 | + }; |
| 99 | + getBookByCateogry(bookType) { |
| 100 | + return this.callAPI(bookType) |
| 101 | + }; |
| 102 | +} |
| 103 | + |
| 104 | +class Book { |
| 105 | + constructor(title, author, category, shelf, floor, status) { |
| 106 | + this.bookId = this.geenrateRandomeID(); |
| 107 | + this.title = title; |
| 108 | + this.author = author; |
| 109 | + this.category = category; |
| 110 | + this.location = new Location(shelf, floor); |
| 111 | + this.status = status; |
| 112 | + } |
| 113 | + setBookStatus(status) { |
| 114 | + this.status = status; |
| 115 | + } |
| 116 | + setBorrowDate(date) { |
| 117 | + this.borrowDate = date; |
| 118 | + this.setDueDate(this.borrowDate + 15) |
| 119 | + } |
| 120 | + setDueDate(dueDate) { |
| 121 | + this.dueDate = dueDate; |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +class Location { |
| 126 | + constructor(shelf, floor) { |
| 127 | + this.shelfNo = shelf; |
| 128 | + this.floorNo = floor; |
| 129 | + } |
| 130 | + |
| 131 | + getLocation() { |
| 132 | + |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +class BookIssueService { |
| 137 | + calculateFine(days, user, book) { |
| 138 | + |
| 139 | + }; |
| 140 | + collectFine(user, days) { |
| 141 | + |
| 142 | + }; |
| 143 | + issueBook(book, user) { |
| 144 | + return dueDate |
| 145 | + }; |
| 146 | + renewBook(book, user) { |
| 147 | + return dueDate; |
| 148 | + }; |
| 149 | + returnBook(book, user) { |
| 150 | + |
| 151 | + }; |
| 152 | +} |
| 153 | + |
| 154 | + |
| 155 | +class BookIssueDetail { |
| 156 | + constructor(book, startDate, user) { |
| 157 | + this.book = book; |
| 158 | + this.startDate = startDate; |
| 159 | + this.user = user; |
| 160 | + this.dueDate = startDate + 15; |
| 161 | + } |
| 162 | +} |
0 commit comments