tn-api.js/src/CreditsManager.ts

23 lines
683 B
TypeScript
Raw Normal View History

2023-12-04 19:21:33 +01:00
import axios from "axios";
export default class CreditsManager {
token: string | undefined;
URL = "https://api.thundernetwork.org";
constructor(customURL: string, token: string | undefined) {
this.URL = customURL || this.URL;
this.token = token;
}
/**
* Retrieves the balance of a user with the given ID.
*
* @param {number} id - The ID of the user.
* @return {Promise<number>} The balance of the user.
*/
2023-12-07 13:10:33 +01:00
async balance(id: string|number) {
2023-12-04 19:21:33 +01:00
let req = await axios.get(`${this.URL}/credits/${id}`);
if (req.status == 404) throw new Error("User not found");
return req.data.credits;
}
}