-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpopulateDatabase.js
More file actions
50 lines (45 loc) · 1.41 KB
/
populateDatabase.js
File metadata and controls
50 lines (45 loc) · 1.41 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
import axios from 'axios';
import { books } from './data/books.js';
const BASE_URL = 'http://localhost:80/gilhari/v1/'
var n_authors=1
var authors = new Map()
for (let index = 0; index <= 200; index++) {
const book = books[index]
//console.log(index)
let a_id = n_authors
if (!authors.has(book.Author)){
n_authors+=1
authors.set(book.Author, a_id)
axios.post(BASE_URL+'Authors/', {
"entity":{"ID":a_id, "Name": book.Author}
}).then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error);
});
} else {
a_id = authors.get(book.Author)
}
const jsonBook = {"ID":index, "Title":book.Title, "Auth_ID":a_id, "Genre":book.Genre, "Height":book.Height,
"SubGenre":book.SubGenre, "Publisher":book.Publisher
}
axios.post(BASE_URL+'Books/', {
"entity":jsonBook
}).then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error);
});
}
axios.get(BASE_URL+'Books/')
.then(response => {
// Access the response data
const responseData = response.data;
// Process the response data here
console.log(responseData)
return responseData
})
.catch(error => {
// Handle any errors
console.log(error)
});