UNPKG

@hubs101/js-api-skd-client

Version:
117 lines (116 loc) 6.37 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._uploadPublicOfferPdf = exports._fetchPublicOffer = exports._fetchPublicFeeds = exports._fetchPublicEventStatistics = exports._getPublicGroupDetails = exports._getPublicRegistrationForm = exports._fetchPublicAgenda = exports._fetchPublicExhibitions = exports._fetchAllPublicEvents = void 0; const api_1 = require("../../utils/api"); const base_1 = require("../../utils/base"); const _fetchAllPublicEvents = (basePath, nbPage, params) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const configUrl = () => { if (nbPage && params) return `${base.PUBLIC_EVENTS}?limit=36&page=${nbPage}${params}`; else if (nbPage) return `${base.PUBLIC_EVENTS}?limit=36&page=${nbPage}`; return `${base.PUBLIC_EVENTS}?limit=36`; }; const allEvents = yield (0, api_1.getRequest)(configUrl()); return allEvents; }); exports._fetchAllPublicEvents = _fetchAllPublicEvents; const _fetchPublicExhibitions = (basePath, eventId, nbPage, params) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const configUrl = () => { if (nbPage && params) return `${base.PUBLIC_EVENTS}/${eventId}/exhibitions?limit=36&page=${nbPage}${params}`; else if (nbPage) return `${base.PUBLIC_EVENTS}/${eventId}/exhibitions?limit=36&page=${nbPage}`; return `${base.PUBLIC_EVENTS}/${eventId}/exhibitions?limit=36`; }; const exhibitions = yield (0, api_1.getRequest)(configUrl()); return exhibitions; }); exports._fetchPublicExhibitions = _fetchPublicExhibitions; const _fetchPublicAgenda = (basePath, eventId, nbPage, params) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const configUrl = () => { if (nbPage && params) return `${base.PUBLIC_EVENTS}/${eventId}/agenda?limit=36&page=${nbPage}${params}`; else if (nbPage) return `${base.PUBLIC_EVENTS}/${eventId}/agenda?limit=36&page=${nbPage}`; return `${base.PUBLIC_EVENTS}/${eventId}/agenda?limit=36`; }; const agenda = yield (0, api_1.getRequest)(configUrl()); return agenda; }); exports._fetchPublicAgenda = _fetchPublicAgenda; const _getPublicRegistrationForm = (basePath, eventId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const configUrl = () => { return `${base.PUBLIC_EVENTS}/${eventId}/registration-form`; }; const data = yield (0, api_1.getRequest)(configUrl()); return data; }); exports._getPublicRegistrationForm = _getPublicRegistrationForm; const _getPublicGroupDetails = (basePath, groupId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const groups = yield (0, api_1.getRequest)(`${base.PUBLIC_GROUPS}/${groupId}`); return (groups === null || groups === void 0 ? void 0 : groups.data) || groups; }); exports._getPublicGroupDetails = _getPublicGroupDetails; const _fetchPublicEventStatistics = (basePath, eventId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const data = yield (0, api_1.getRequest)(`${base.PUBLIC_EVENTS}/${eventId}/statistics`); return (data === null || data === void 0 ? void 0 : data.data) || data; }); exports._fetchPublicEventStatistics = _fetchPublicEventStatistics; const _fetchPublicFeeds = (basePath, accountId, params) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const url = params ? `${base.PUBLIC_ACCOUNTS}/${accountId}/feeds?${params}` : `${base.PUBLIC_ACCOUNTS}/${accountId}/feeds`; const feeds = yield (0, api_1.getRequest)(url); return feeds; }); exports._fetchPublicFeeds = _fetchPublicFeeds; const _fetchPublicOffer = (basePath, offerId, userId, access) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const url = `${base.PUBLIC_OFFERS}/${offerId}?user=${userId}&access=${access}`; const offer = yield (0, api_1.getRequest)(url); return (offer === null || offer === void 0 ? void 0 : offer.data) || offer; }); exports._fetchPublicOffer = _fetchPublicOffer; const _uploadPublicOfferPdf = (basePath, offerId, userId, access, file) => __awaiter(void 0, void 0, void 0, function* () { var _a; const base = (0, base_1.getBasePath)(basePath); const url = `${base.PUBLIC_OFFERS_UPLOAD}/${offerId}/upload-offer?user=${userId}&access=${access}`; const formData = new FormData(); formData.append("file", file); const response = yield fetch(url, { method: "POST", body: formData, }); if (!response.ok) { const errorText = yield response.text(); throw new Error(`HTTP ${response.status}: ${errorText}`); } const data = yield response.json(); if (String(data === null || data === void 0 ? void 0 : data.status).startsWith("4")) { if (data === null || data === void 0 ? void 0 : data.invalid_fields) { throw new Error((_a = Object.values(data === null || data === void 0 ? void 0 : data.invalid_fields)) === null || _a === void 0 ? void 0 : _a.toString()); } if (data === null || data === void 0 ? void 0 : data.message) { throw new Error(data.message); } } return (data === null || data === void 0 ? void 0 : data.result) || data; }); exports._uploadPublicOfferPdf = _uploadPublicOfferPdf;