@questlabs/core
Version:
This is the quest SDK
152 lines (151 loc) • 8.35 kB
JavaScript
;
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.MembershipTier = void 0;
const constants_1 = require("../../utils/constants");
const helperFunctions_1 = require("../../utils/helperFunctions");
class MembershipTier {
constructor(questSdk) {
this.questSdk = questSdk;
}
addNewMembershipTierForEntity(_a, options_1) {
return __awaiter(this, arguments, void 0, function* ({ membershipTier, xpThreshold, description, entityId, imageIPFS }, options) {
try {
const { userId, token } = this.questSdk.getUser();
const defaultEntityId = entityId || this.questSdk.getEntityId();
(0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, membershipTier, xpThreshold });
if (this.questSdk.getEntityAuthenticationToken() === undefined) {
(0, helperFunctions_1.validateParams)({ userId, token });
}
const url = `/entities/${defaultEntityId}/membershipTiers`;
const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams);
const body = Object.assign({ membershipTier,
xpThreshold,
description,
imageIPFS }, options === null || options === void 0 ? void 0 : options._body);
return this.questSdk.makeRequest({
url,
method: constants_1.HTTP_METHOD.POST,
queryParams,
body,
headers: options === null || options === void 0 ? void 0 : options._headers,
});
}
catch (error) {
this.questSdk.captureSentryException(error);
throw error;
}
});
}
getAllMembershipTiersForEntity() {
return __awaiter(this, arguments, void 0, function* ({ entityId, limit, page } = {}, options) {
try {
const { userId, token } = this.questSdk.getUser();
const defaultEntityId = entityId || this.questSdk.getEntityId();
(0, helperFunctions_1.validateParams)({ entityId: defaultEntityId });
if (this.questSdk.getEntityAuthenticationToken() === undefined) {
(0, helperFunctions_1.validateParams)({ userId, token });
}
const url = `/entities/${defaultEntityId}/membershipTiers`;
const queryParams = Object.assign(Object.assign(Object.assign({}, (limit && { limit })), (page && { page })), options === null || options === void 0 ? void 0 : options._queryParams);
return this.questSdk.makeRequest({
url,
method: constants_1.HTTP_METHOD.GET,
queryParams,
headers: options === null || options === void 0 ? void 0 : options._headers,
});
}
catch (error) {
this.questSdk.captureSentryException(error);
throw error;
}
});
}
updateMembershipTierForEntity(_a, options_1) {
return __awaiter(this, arguments, void 0, function* ({ membershipTier, description, imageIPFS, xpThreshold, entityId }, options) {
try {
const { userId, token } = this.questSdk.getUser();
const defaultEntityId = entityId || this.questSdk.getEntityId();
(0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, membershipTier });
if (this.questSdk.getEntityAuthenticationToken() === undefined) {
(0, helperFunctions_1.validateParams)({ userId, token });
}
const url = `/entities/${defaultEntityId}/membershipTiers/${membershipTier}/update`;
const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams);
const body = Object.assign(Object.assign(Object.assign(Object.assign({}, (description && { description })), (imageIPFS && { imageIPFS })), (xpThreshold && { xpThreshold })), options === null || options === void 0 ? void 0 : options._body);
if (Object.keys(body).length === 0) {
throw new Error("Invalid reques. Atleast one field is necessary to update");
}
return this.questSdk.makeRequest({
url,
method: constants_1.HTTP_METHOD.POST,
queryParams,
body,
headers: options === null || options === void 0 ? void 0 : options._headers,
});
}
catch (error) {
this.questSdk.captureSentryException(error);
throw error;
}
});
}
deleteMembershipTierForEntity(_a, options_1) {
return __awaiter(this, arguments, void 0, function* ({ membershipTier, entityId }, options) {
try {
const { userId, token } = this.questSdk.getUser();
const defaultEntityId = entityId || this.questSdk.getEntityId();
(0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, membershipTier });
if (this.questSdk.getEntityAuthenticationToken() === undefined) {
(0, helperFunctions_1.validateParams)({ userId, token });
}
const url = `/entities/${defaultEntityId}/membershipTiers/${membershipTier}/delete`;
const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams);
return this.questSdk.makeRequest({
url,
method: constants_1.HTTP_METHOD.POST,
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;
}
});
}
getMembershipTierDetailsForEntity(_a, options_1) {
return __awaiter(this, arguments, void 0, function* ({ membershipTier, entityId }, options) {
try {
const { userId, token } = this.questSdk.getUser();
const defaultEntityId = entityId || this.questSdk.getEntityId();
(0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, membershipTier });
if (this.questSdk.getEntityAuthenticationToken() === undefined) {
(0, helperFunctions_1.validateParams)({ userId, token });
}
const url = `/entities/${entityId}/membershipTiers/${membershipTier}`;
const queryParams = Object.assign(Object.assign({}, (userId && { userId })), options === null || options === void 0 ? void 0 : options._queryParams);
return this.questSdk.makeRequest({
url,
method: constants_1.HTTP_METHOD.GET,
queryParams,
headers: options === null || options === void 0 ? void 0 : options._headers,
});
}
catch (error) {
this.questSdk.captureSentryException(error);
throw error;
}
});
}
}
exports.MembershipTier = MembershipTier;