forked from RossGreene987/Bookish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
47 lines (40 loc) · 1.36 KB
/
index.ts
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
const request = require('request');
const express = require('express');
const pgp = require('pg-promise')(/* options */);
const link = 'postgres://Bookish:ZSE$4rfv@localhost:5432/Bookish'
const db = pgp(link);
class Book {
author: string;
copiesAvailable: number;
ISBN: number;
title: string;
numberInLibrary: number;
constructor(author: string, copiesAvailable: number, ISBN: number, title: string, numberInLibrary: number) {
this.author = author;
this.copiesAvailable = copiesAvailable;
this.ISBN = ISBN;
this.title = title;
this.numberInLibrary = numberInLibrary;
}
}
function listBooksFromCatalogue(catalogue){
let bookList = catalogue.map((book) => {
return new Book(book.Author, book.Copies_Available, book.ISBN, book.Title, book.Number_in_Library)
});
return bookList;
}
function main() {
const app = express();
const port = 3000;
//app.use(express.static('frontend'));
app.get("/bookish", (req, res) => {
//let inqueery = req.query.inqueery;
db.any('SELECT * FROM public."Books"')
.then((catalogue) => {
let bookList = listBooksFromCatalogue(catalogue);
res.send(bookList)
}, (error) => {console.log(error)});
} );
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
}
main();