File size: 1,444 Bytes
d76f93d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { readMyData } from "../utils/fileStorage";
import { LinkManager } from "./LinkManager";

export enum Genre {
   Fiction = "Fiction",
   NonFiction = "Non-Fiction",
   Mystery = "Mystery",
   SciFi = "Sci-Fi",
   Fantasy = "Fantasy",
   Biography = "Biography",
   History = "History",
   Romance = "Romance",
   Thriller = "Thriller",
   Horror = "Horror",
   Poetry = "Poetry",
   Drama = "Drama",
   Comics = "Comics",
   Other = "Other",
}

export enum BookStatus {
   AVAILABLE = "available",
   BORROWED = "borrowed",
}

export interface Book {
   id: string;
   title: string;
   author: string;
   pages: number;
   year: number;
   genre: Genre;
   status: BookStatus;
}

export class BookLinkManager extends LinkManager<Book> {
   protected fileName = "books.sea";
   protected tableName = "books";


   async findAvailable(): Promise<Book[]> {
      const books = await readMyData<Book>(this.fileName);
      return books.filter((b) => b.status === BookStatus.AVAILABLE);
   }
}

export const bookLinkManager = new BookLinkManager(); 


export interface CreateBookRequest {
   title: string;
   author: string;
   pages: number;
   year: number;
   genre: Genre;
}

export interface BorrowBookRequest {
   bookIds: string[];
   visitorId: string;
   employeeId: string;
   borrowDate: string;
}

export interface ReturnBookRequest {
   bookIds: string[];
   visitorId: string;
   employeeId: string;
   returnDate: string;
}