@questlabs/core
Version:
This is the quest SDK
192 lines (191 loc) • 10.4 kB
JavaScript
"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.EntityGem = void 0;
const constants_1 = require("../../utils/constants");
const helperFunctions_1 = require("../../utils/helperFunctions");
class EntityGem {
constructor(questSdk) {
this.questSdk = questSdk;
}
getAllEntityGemsContracts(_a, options_1) {
return __awaiter(this, arguments, void 0, function* ({ entityId }, options) {
try {
const { userId, token } = this.questSdk.getUser();
const defaultEntityId = entityId || this.questSdk.getEntityId();
(0, helperFunctions_1.validateParams)({ userId, token, entityId: defaultEntityId });
const url = `/entities/${defaultEntityId}/gem-contracts`;
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;
}
});
}
getEntityGemContractById(_a, options_1) {
return __awaiter(this, arguments, void 0, function* ({ entityGemsContractId, entityId }, options) {
try {
const { userId, token } = this.questSdk.getUser();
const defaultEntityId = entityId || this.questSdk.getEntityId();
(0, helperFunctions_1.validateParams)({ userId, token, entityGemsContractId, entityId: defaultEntityId });
const url = `/entities/${defaultEntityId}/gem-contracts/${entityGemsContractId}`;
return this.questSdk.makeRequest({
url,
method: constants_1.HTTP_METHOD.GET,
headers: options._headers,
queryParams: options._queryParams,
});
}
catch (error) {
this.questSdk.captureSentryException(error);
throw error;
}
});
}
addNewEntityGemsContractForEntity(_a, options_1) {
return __awaiter(this, arguments, void 0, function* ({ initialDefaultValue, name, source, desc, entityId, logo }, options) {
try {
const { userId, token } = this.questSdk.getUser();
const defaultEntityId = entityId || this.questSdk.getEntityId();
(0, helperFunctions_1.validateParams)({ userId, token, entityId: defaultEntityId, name, source, initialDefaultValue });
const url = `/entities/${defaultEntityId}/gem-contracts`;
const body = Object.assign(Object.assign(Object.assign({ name,
source,
initialDefaultValue }, (desc && { desc })), (logo && { logo })), options._body);
return this.questSdk.makeRequest({
url,
method: constants_1.HTTP_METHOD.POST,
queryParams: options._queryParams,
body,
headers: options._headers,
});
}
catch (error) {
this.questSdk.captureSentryException(error);
throw error;
}
});
}
updateEntityGemsContractForEntity(_a, options_1) {
return __awaiter(this, arguments, void 0, function* ({ entityId, entityGemsContractId, desc, initialDefaultValue, logo, name, source, }, options) {
try {
const { userId, token } = this.questSdk.getUser();
const defaultEntityId = entityId || this.questSdk.getEntityId();
(0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, entityGemsContractId, userId, token });
const url = `/entities/${defaultEntityId}/gem-contracts/${entityGemsContractId}/update`;
const body = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (name && { name })), (source && { source })), (desc && { desc })), (logo && { logo })), (initialDefaultValue && { initialDefaultValue })), options === null || options === void 0 ? void 0 : options._body);
return this.questSdk.makeRequest({
url,
method: constants_1.HTTP_METHOD.POST,
body,
headers: options === null || options === void 0 ? void 0 : options._headers,
queryParams: options === null || options === void 0 ? void 0 : options._queryParams,
});
}
catch (error) {
this.questSdk.captureSentryException(error);
throw error;
}
});
}
softDeleteEntityGemsContractForEntity(_a, options_1) {
return __awaiter(this, arguments, void 0, function* ({ entityGemsContractId, entityId }, options) {
try {
const { userId, token } = this.questSdk.getUser();
const defaultEntityId = entityId || this.questSdk.getEntityId();
(0, helperFunctions_1.validateParams)({ userId, token, entityId: defaultEntityId, entityGemsContractId });
const url = `/entities/${defaultEntityId}/gem-contracts/${entityGemsContractId}/delete`;
return this.questSdk.makeRequest({
url,
method: constants_1.HTTP_METHOD.POST,
body: options === null || options === void 0 ? void 0 : options._body,
headers: options === null || options === void 0 ? void 0 : options._headers,
queryParams: options === null || options === void 0 ? void 0 : options._queryParams,
});
}
catch (error) {
this.questSdk.captureSentryException(error);
throw error;
}
});
}
getAllEntityGemsForAUser() {
return __awaiter(this, arguments, void 0, function* ({ entityId, userId } = {}, options) {
try {
const user = this.questSdk.getUser();
const defaultEntityId = entityId || this.questSdk.getEntityId();
(0, helperFunctions_1.validateParams)({ userId: userId || user.userId, token: user.token, entityId: defaultEntityId });
const url = `/entities/${defaultEntityId}/users/${userId || user.userId}/gems`;
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;
}
});
}
increaseEntityGemForAUser(_a, options_1) {
return __awaiter(this, arguments, void 0, function* ({ entityGemsContractId, value, entityId, userId }, options) {
try {
const user = this.questSdk.getUser();
const defaultEntityId = entityId || this.questSdk.getEntityId();
(0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, entityGemsContractId, value, userId: userId || user.userId });
const url = `/entities/${defaultEntityId}/users/${userId || user.userId}/gemsContracts/${entityGemsContractId}/increase`;
const body = Object.assign({ value }, options === null || options === void 0 ? void 0 : options._body);
return this.questSdk.makeRequest({
url,
method: constants_1.HTTP_METHOD.POST,
body,
headers: options === null || options === void 0 ? void 0 : options._headers,
queryParams: options === null || options === void 0 ? void 0 : options._queryParams,
});
}
catch (error) {
this.questSdk.captureSentryException(error);
throw error;
}
});
}
decreaseEntityGemForAUser(_a, options_1) {
return __awaiter(this, arguments, void 0, function* ({ entityGemsContractId, entityId, userId, value }, options) {
try {
const user = this.questSdk.getUser();
const defaultEntityId = entityId || this.questSdk.getEntityId();
(0, helperFunctions_1.validateParams)({ entityGemsContractId, entityId: defaultEntityId, userId: userId || user.userId, value });
const url = `/entities/${defaultEntityId}/users/${userId || user.userId}/gemsContracts/${entityGemsContractId}/decrease`;
const body = Object.assign({ value }, options === null || options === void 0 ? void 0 : options._body);
return this.questSdk.makeRequest({
url,
method: constants_1.HTTP_METHOD.POST,
body,
headers: options === null || options === void 0 ? void 0 : options._headers,
queryParams: options === null || options === void 0 ? void 0 : options._queryParams,
});
}
catch (error) {
this.questSdk.captureSentryException(error);
throw error;
}
});
}
}
exports.EntityGem = EntityGem;