UNPKG

@questlabs/core

Version:
62 lines (61 loc) 3.24 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomReward = void 0; const constants_1 = require("../../utils/constants"); const helperFunctions_1 = require("../../utils/helperFunctions"); class CustomReward { constructor(questSdk) { this.questSdk = questSdk; } addCustomRewardToUser(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ entityId, rewardId, forUserId }, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ userId: forUserId || userId, token, entityId: defaultEntityId, rewardId }); const url = `/entities/${defaultEntityId}/users/${forUserId || userId}/${rewardId}`; return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, queryParams: options === null || options === void 0 ? void 0 : options._queryParams, body: options === null || options === void 0 ? void 0 : options._body, headers: options === null || options === void 0 ? void 0 : options._headers, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } getCustomRewardByUser() { return __awaiter(this, arguments, void 0, function* ({ entityId, forUserId } = {}, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ userId: forUserId || userId, token, entityId: defaultEntityId }); const url = `/entities/${defaultEntityId}/users/${forUserId || userId}/custom-reward`; return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.GET, queryParams: options === null || options === void 0 ? void 0 : options._queryParams, headers: options === null || options === void 0 ? void 0 : options._headers, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } } exports.CustomReward = CustomReward;