UNPKG

event-app-api

Version:

Package for easy access to Event App API

83 lines (82 loc) 5.12 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._deleteComment = exports._deletePost = exports._updatePost = exports._addPost = exports._addComment = exports._unlikeComment = exports._likeComment = exports._unlikePost = exports._likePost = exports._fetchPostDetails = exports._fetchPosts = void 0; const api_1 = require("../../utils/api"); const base_1 = require("../../utils/base"); const _fetchPosts = (basePath, token, eventId) => __awaiter(void 0, void 0, void 0, function* () { var _a; const base = (0, base_1.getBasePath)(basePath); const posts = yield (0, api_1.getRequest)(`${base.EVENTS}/${eventId}/posts`, token); return ((_a = posts === null || posts === void 0 ? void 0 : posts.data) === null || _a === void 0 ? void 0 : _a.data) || (posts === null || posts === void 0 ? void 0 : posts.data) || posts; }); exports._fetchPosts = _fetchPosts; const _fetchPostDetails = (basePath, token, postId) => __awaiter(void 0, void 0, void 0, function* () { var _b; const base = (0, base_1.getBasePath)(basePath); const postDetails = yield (0, api_1.getRequest)(`${base.POSTS}/${postId}`, token); return ((_b = postDetails === null || postDetails === void 0 ? void 0 : postDetails.data) === null || _b === void 0 ? void 0 : _b.data) || (postDetails === null || postDetails === void 0 ? void 0 : postDetails.data) || postDetails; }); exports._fetchPostDetails = _fetchPostDetails; const _likePost = (basePath, token, postId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.getRequest)(`${base.POSTS}/${postId}/like`, token); return response; }); exports._likePost = _likePost; const _unlikePost = (basePath, token, postId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.deleteRequest)(`${base.POSTS}/${postId}/like`, null, token); return response; }); exports._unlikePost = _unlikePost; const _likeComment = (basePath, token, postId, commentId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.getRequest)(`${base.POSTS}/${postId}/comment/${commentId}/like`, token); return response; }); exports._likeComment = _likeComment; const _unlikeComment = (basePath, token, postId, commentId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.deleteRequest)(`${base.POSTS}/${postId}/comment/${commentId}/like`, {}, token); return response; }); exports._unlikeComment = _unlikeComment; const _addComment = (basePath, token, postId, body) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const comment = yield (0, api_1.postRequest)(`${base.POSTS}/${postId}/comment`, body, token); return (comment === null || comment === void 0 ? void 0 : comment.data) || comment; }); exports._addComment = _addComment; const _addPost = (basePath, token, body) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const post = yield (0, api_1.postRequest)(`${base.POSTS}`, body, token); return (post === null || post === void 0 ? void 0 : post.data) || post; }); exports._addPost = _addPost; const _updatePost = (basePath, token, postId, body) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const post = yield (0, api_1.postRequest)(`${base.POSTS}/${postId}`, body, token); return (post === null || post === void 0 ? void 0 : post.data) || post; }); exports._updatePost = _updatePost; const _deletePost = (basePath, token, postId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const response = yield (0, api_1.deleteRequest)(`${base.POSTS}/${postId}`, null, token); return response; }); exports._deletePost = _deletePost; const _deleteComment = (basePath, token, postId, commentId) => __awaiter(void 0, void 0, void 0, function* () { const base = (0, base_1.getBasePath)(basePath); const post = yield (0, api_1.deleteRequest)(`${base.POSTS}/${postId}/comment/${commentId}`, null, token); return post; }); exports._deleteComment = _deleteComment;