-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
56 lines (44 loc) · 1.76 KB
/
test.js
File metadata and controls
56 lines (44 loc) · 1.76 KB
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
require('dotenv').config(); // DOTENV
var MongoClient = require('mongodb').MongoClient;
var client = new MongoClient(process.env.mongodburi, { useNewUrlParser: true, useUnifiedTopology: true });
var dbo;
var fetch = require("node-fetch");
MongoClient.connect(process.env.mongodburi, (err, db) => {
if (err)
throw err;
dbo = db.db("ddlibrary");
console.log("connected to database");
const isbn = 9780765375650
fetch("https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn)
.then(function (res) { return res.json(); })
.then(function (json) {
if (json.items[0].id != "t5rgAAAAMAAJ") {
var isbn_13 = json.items[0].volumeInfo.industryIdentifiers.find(element => element.type == "ISBN_13").identifier;
var isbn_10 = json.items[0].volumeInfo.industryIdentifiers.find(element => element.type == "ISBN_10").identifier;
var name = json.items[0].volumeInfo.title;
var authors = json.items[0].volumeInfo.authors;
var id = json.items[0].id
var bookBody = {};
bookBody.name = name
bookBody.authors = authors
bookBody.isbn_10 = isbn_10
bookBody.isbn_13 = isbn_13
bookBody._id = id
console.log(bookBody)
let query = dbo.collection("users").find({
books: {
"$in":[
bookBody
]
}
})
.toArray(function(err, result) {
if (err) throw err;
console.log(result);
db.close();
})
} else {
return res.status(400).send(`-_- only numbers`);
}
}
)})