|
| 1 | +const GetPoolRequest = require("../../Request/Billing/Pool/GetPoolRequest.js"); |
| 2 | +const GetPoolMembersRequest = require("../../Request/Billing/Pool/GetPoolMembersRequest.js"); |
| 3 | +const GetPoolServersRequest = require("../../Request/Billing/Pool/GetPoolServersRequest.js"); |
| 4 | + |
| 5 | +class Pool { |
| 6 | + /** |
| 7 | + * @type {Client} |
| 8 | + * @private |
| 9 | + */ |
| 10 | + #client; |
| 11 | + |
| 12 | + /** |
| 13 | + * Pool ID |
| 14 | + * |
| 15 | + * @type {string} |
| 16 | + */ |
| 17 | + id; |
| 18 | + |
| 19 | + /** |
| 20 | + * Pool name |
| 21 | + * |
| 22 | + * @type {string} |
| 23 | + */ |
| 24 | + name; |
| 25 | + |
| 26 | + /** |
| 27 | + * Pool credit balance |
| 28 | + * |
| 29 | + * @type {number} |
| 30 | + */ |
| 31 | + credits; |
| 32 | + |
| 33 | + /** |
| 34 | + * Pool server count |
| 35 | + * |
| 36 | + * @type {number} |
| 37 | + */ |
| 38 | + servers; |
| 39 | + |
| 40 | + /** |
| 41 | + * Pool owner ID |
| 42 | + * |
| 43 | + * @type {string} |
| 44 | + */ |
| 45 | + owner; |
| 46 | + |
| 47 | + /** |
| 48 | + * Is pool owner |
| 49 | + * |
| 50 | + * @type {boolean} |
| 51 | + */ |
| 52 | + isOwner; |
| 53 | + |
| 54 | + /** |
| 55 | + * Pool member count |
| 56 | + * |
| 57 | + * @type {number} |
| 58 | + */ |
| 59 | + members; |
| 60 | + |
| 61 | + /** |
| 62 | + * Share of this pool owned by the current account |
| 63 | + * |
| 64 | + * @type {number} |
| 65 | + */ |
| 66 | + ownShare; |
| 67 | + |
| 68 | + /** |
| 69 | + * Credits in this pool owned by the current account |
| 70 | + * |
| 71 | + * @type {number} |
| 72 | + */ |
| 73 | + ownCredits; |
| 74 | + |
| 75 | + /** |
| 76 | + * Pool constructor |
| 77 | + * |
| 78 | + * @param {Client} client |
| 79 | + * @param {string} id |
| 80 | + */ |
| 81 | + constructor(client, id) { |
| 82 | + this.#client = client; |
| 83 | + this.id = id; |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * @param {{}} poolObject |
| 88 | + * @return {this} |
| 89 | + */ |
| 90 | + setFromObject(poolObject) { |
| 91 | + this.id = typeof poolObject.id !== "undefined" ? poolObject.id : null; |
| 92 | + this.name = typeof poolObject.name !== "undefined" ? poolObject.name : null; |
| 93 | + this.credits = typeof poolObject.credits !== "undefined" ? poolObject.credits : null; |
| 94 | + this.servers = typeof poolObject.servers !== "undefined" ? poolObject.servers : null; |
| 95 | + this.owner = typeof poolObject.owner !== "undefined" ? poolObject.owner : null; |
| 96 | + this.isOwner = typeof poolObject.isOwner !== "undefined" ? poolObject.isOwner : null; |
| 97 | + this.members = typeof poolObject.members !== "undefined" ? poolObject.members : null; |
| 98 | + this.ownShare = typeof poolObject.ownShare !== "undefined" ? poolObject.ownShare : null; |
| 99 | + this.ownCredits = typeof poolObject.ownCredits !== "undefined" ? poolObject.ownCredits : null; |
| 100 | + |
| 101 | + return this; |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Get credit pool info |
| 106 | + * |
| 107 | + * @return {this} |
| 108 | + * @throws {RequestError} |
| 109 | + */ |
| 110 | + async get() { |
| 111 | + let response = await this.#client.request(new GetPoolRequest(this.id)); |
| 112 | + this.setFromObject(response.getData()); |
| 113 | + return this; |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Get pool members |
| 118 | + * |
| 119 | + * @return {Promise<PoolMember[]>} |
| 120 | + */ |
| 121 | + async getMembers() { |
| 122 | + let response = await this.#client.request(new GetPoolMembersRequest(this.id)); |
| 123 | + return response.getData(); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Get pool servers |
| 128 | + * |
| 129 | + * @return {Promise<Server[]>} |
| 130 | + */ |
| 131 | + async getServers() { |
| 132 | + let response = await this.#client.request(new GetPoolServersRequest(this.id)); |
| 133 | + return response.getData(); |
| 134 | + } |
| 135 | +} |
| 136 | + |
| 137 | +module.exports = Pool; |
0 commit comments