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