tenebrous-sheets/static/scripts/api.js

31 lines
885 B
JavaScript
Raw Normal View History

function makeAPI(root) {
const Attribute = root.lookupType("models.proto.cofd.api.Attribute");
2020-12-27 21:49:08 +00:00
const attributesResource = (username, characterID) =>
'/api/cofd/' + username + '/' + characterID + '/attributes';
async function updateAttribute(params) {
const { username, characterID, attribute, newValue } = params;
let req = Attribute.create({
name: attribute,
value: parseInt(newValue)
});
2020-12-27 21:49:08 +00:00
const resource = attributesResource(username, characterID);
let resp = await fetch(resource, {
2020-12-27 21:49:08 +00:00
method: 'PATCH',
body: Attribute.encode(req).finish()
}).then(async resp => {
console.log("resp is", await resp.text());
}).catch(async err => {
console.log("err is", err.text());
});
}
return {
updateAttribute
};
}