starts improving REST Api

This commit is contained in:
2019-08-04 21:23:01 +02:00
parent e56c8df121
commit a0e4a02e0f
4 changed files with 72 additions and 51 deletions

View File

@@ -18,13 +18,29 @@ export const Api = {
return fetch(API_ENDPOINT(playerId + "/loot"))
.then(r => r.json())
},
putClaim (playerId, itemId) {
return fetch(API_ENDPOINT(playerId + "/claim/" + itemId))
.then(r => r.json())
putClaim (player_id, item_id) {
const payload = { player_id, item_id };
return fetch(API_ENDPOINT("claims"),
{
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload)
})
.then(r => r.json())
},
unClaim (playerId, itemId) {
return fetch(API_ENDPOINT(playerId + "/unclaim/" + itemId))
.then(r => r.json())
unClaim (player_id, item_id) {
const payload = { player_id, item_id };
return fetch(API_ENDPOINT("claims"),
{
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload)
})
.then(r => r.json())
},
updateWealth (playerId, goldValue) {
return fetch(API_ENDPOINT(playerId + "/update-wealth/" + goldValue))
@@ -83,7 +99,7 @@ export const AppStorage = {
// Sets a new active player by id
setActivePlayer (newPlayerId) {
if (this.debug) console.log('setActivePlayer to ', newPlayerId)
this.state.player_id = newPlayerId
this.state.player_id = Number(newPlayerId)
document.cookie = `player_id=${newPlayerId};`;
},
// Show/Hide player's chest