-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadapter.js
58 lines (53 loc) · 1.62 KB
/
adapter.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const userURL = "http://localhost:3000/users"
const gameURL = "http://localhost:3000/games"
const gamePanel = () => {
fetch(`http://localhost:3000/games`)
.then(response => response.json())
.then(gameData)
}
const createUser = (event) => {
let username = event.target[0].value
fetch('http://localhost:3000/users', {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: JSON.stringify({
username: username
})
}).then(response => response.json())
.then((event) => {loggedIn(event)})
}
const renderStats = () => {
let currentUserId = parseInt(document.querySelector('#rt-panel-data').dataset.id)
fetch(`http://localhost:3000/users/${currentUserId}`)
.then(response => response.json())
.then(event => renderUserData(event))
}
const deleteUser = (event) => {
let id = parseInt(event.target.dataset.id)
fetch(`http://localhost:3000/users/${id}`, {
method: "DELETE"
}).then(res => res.json())
.then(logOut)
}
const gameOver = (event) => {
let userId = parseInt(event.target.parentElement.parentElement.parentElement.nextElementSibling.firstElementChild.dataset.id)
let userClickCount = parseInt(document.querySelector('#click-count').innerText)
fetch(`http://localhost:3000/games`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: JSON.stringify({
user_id: userId,
click_total: userClickCount
})
}).then(response => response.json())
.then(function(){
renderStats()
gamePanel()
})
}