Product purchase functions

This commit is contained in:
Eden Kirin
2023-04-10 20:02:23 +02:00
parent edca936325
commit fd71fa276c

View File

@ -121,6 +121,34 @@ class FairHopper {
} }
return await r.json(); return await r.json();
} }
async getProducts() {
const r = await fetch(this.formatUrl("/products"), {
headers: this.defaultHeaders,
});
return await r.json();
}
async purchaseProduct(playerId, productId) {
const url = this.formatUrl(`/player/${playerId}/product/purchase`);
const postData = {
product_id: productId,
};
const r = await fetch(url, {
method: "post",
headers: this.defaultHeaders,
body: JSON.stringify(postData),
});
switch (r.status) {
case 403:
throw new PlayerInactiveError();
case 404:
throw new PlayerNotFoundError();
case 409:
throw new PositionError();
}
return await r.json();
}
} }
module.exports = { module.exports = {