diff --git a/package.json b/package.json index e46598b..a878dd6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tn-api.js", - "version": "0.3.0", + "version": "0.4.0", "description": "A Public Template for npm", "main": "build/index.js", "repository": "https://source.thundernetwork.org/ThunderNetworkRaD/tn-api.js", diff --git a/src/CreditsManager.ts b/src/CreditsManager.ts index baea11a..94edfdf 100644 --- a/src/CreditsManager.ts +++ b/src/CreditsManager.ts @@ -22,17 +22,38 @@ export default class CreditsManager { } /** - * Sets the number of credits for a given user. + * Sets the credit number for a given ID. * - * @param {number} id - The ID to set. - * @return {Promise} - The credits of the user. + * @param {string|number} id - The ID of the user. + * @param {number} number - The new credit number. */ - async set(id: number, number: number) { + async set(id: string|number, number: number) { let req = await axios.post(`${this.URL}/credits/${id}`, { number }, { headers: { Authorization: `Bearer ${this.token}` } }); + if (req.status == 403) throw new Error("No Permission"); if (req.status == 404) throw new Error("User not Found"); } - async verify(code: number) { - await axios.get(`${this.URL}/credits/verify/${code}`, { headers: { Authorization: `Bearer ${this.token}` } }); + /** + * Verifies the given transaction. + * + * @param {number} code - The code of the transaction to be verified. + * @return {void} - This function does not return anything. + */ + async verifyTransaction(code: number) { + let req = await axios.post(`${this.URL}/credits/verify/${code}`, {}, { headers: { Authorization: `Bearer ${this.token}` } }); + if (req.status == 403) throw new Error("No Permission"); + if (req.status == 404) throw new Error("Transaction not Found"); + } + + /** + * Retrieves a transaction by its code. + * + * @param {number} code - The code of the transaction. + * @return {Promise} The transaction object. + */ + async getTransaction(code: number) { + let req = await axios.get(`${this.URL}/credits/verify/${code}`); + if (req.status == 404) throw new Error("Transaction not Found"); + return req.data.transaction; } } \ No newline at end of file