UNPKG

@oxyhq/services

Version:

Reusable OxyHQ module to handle authentication, user management, karma system, device-based session management and more 🚀

117 lines (110 loc) • 2.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OxyServicesKarmaMixin = OxyServicesKarmaMixin; var _mixinHelpers = require("./mixinHelpers"); /** * Karma Methods Mixin * * Provides methods for karma system management */ function OxyServicesKarmaMixin(Base) { return class extends Base { constructor(...args) { super(...args); } /** * Get user karma */ async getUserKarma(userId) { try { return await this.makeRequest('GET', `/api/karma/${userId}`, undefined, { cache: true, cacheTTL: 2 * 60 * 1000 // 2 minutes cache }); } catch (error) { throw this.handleError(error); } } /** * Give karma to user */ async giveKarma(userId, amount, reason) { try { return await this.makeRequest('POST', `/api/karma/${userId}/give`, { amount, reason }, { cache: false }); } catch (error) { throw this.handleError(error); } } /** * Get user karma total * @param userId - The user ID * @returns User karma total */ async getUserKarmaTotal(userId) { try { return await this.makeRequest('GET', `/api/karma/${userId}/total`, undefined, { cache: true, cacheTTL: _mixinHelpers.CACHE_TIMES.MEDIUM }); } catch (error) { throw this.handleError(error); } } /** * Get user karma history * @param userId - The user ID * @param limit - Optional limit for results * @param offset - Optional offset for pagination * @returns User karma history */ async getUserKarmaHistory(userId, limit, offset) { try { const params = {}; if (limit) params.limit = limit; if (offset) params.offset = offset; return await this.makeRequest('GET', `/api/karma/${userId}/history`, params, { cache: true, cacheTTL: _mixinHelpers.CACHE_TIMES.MEDIUM }); } catch (error) { throw this.handleError(error); } } /** * Get karma leaderboard * @returns Karma leaderboard */ async getKarmaLeaderboard() { try { return await this.makeRequest('GET', '/api/karma/leaderboard', undefined, { cache: true, cacheTTL: _mixinHelpers.CACHE_TIMES.LONG }); } catch (error) { throw this.handleError(error); } } /** * Get karma rules * @returns Karma rules */ async getKarmaRules() { try { return await this.makeRequest('GET', '/api/karma/rules', undefined, { cache: true, cacheTTL: _mixinHelpers.CACHE_TIMES.EXTRA_LONG // Rules don't change often }); } catch (error) { throw this.handleError(error); } } }; } //# sourceMappingURL=OxyServices.karma.js.map