UNPKG

@questlabs/core

Version:
114 lines (113 loc) 5.75 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.Skill = void 0; const constants_1 = require("../../utils/constants"); const helperFunctions_1 = require("../../utils/helperFunctions"); class Skill { constructor(questSdk) { this.questSdk = questSdk; } getAllSkills() { 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 = `/skills`; const queryParams = Object.assign({ userId, entityId: defaultEntityId }, 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; } }); } getSkillDetails(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ skillId }, options) { try { const { userId, token } = this.questSdk.getUser(); (0, helperFunctions_1.validateParams)({ userId, token, skillId }); const url = `/skills/${skillId}`; 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; } }); } addNewSkill(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ name, description, entityId }, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, name, description }); if (this.questSdk.getEntityAuthenticationToken() === undefined) { (0, helperFunctions_1.validateParams)({ token, userId }); } const url = `/skills`; const queryParams = Object.assign(Object.assign({}, (userId && { userId })), options === null || options === void 0 ? void 0 : options._queryParams); const body = Object.assign({ entityId: defaultEntityId, name, description }, 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; } }); } addMultipleNewSkills(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ skills, entityId }, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, skills }); if (this.questSdk.getEntityAuthenticationToken() === undefined) { (0, helperFunctions_1.validateParams)({ userId, token }); } const url = `/skills/multiple`; const queryParams = Object.assign(Object.assign({}, (userId && { userId })), options === null || options === void 0 ? void 0 : options._queryParams); const body = Object.assign({ entityId: defaultEntityId, skills }, 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; } }); } } exports.Skill = Skill;