UNPKG

baasic-sdk-javascript

Version:

JavaScript SDK provides core functionality for building web and mobile applications on [Baasic](http://www.baasic.com/).

294 lines (293 loc) 16.9 kB
"use strict"; /* globals module */ /** * @module articleCommentsClient * @description Article Comments Client provides an easy way to consume Article Comments REST API end-points. `articleCommentsClient` functions enable performing standard CRUD operations directly on article comment resources, whereas the `articleClient` functions allow management between article and article comments. In order to obtain needed routes `articleCommentsClient` uses `articleCommentsRoute`. */ Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var inversify_1 = require("inversify"); ; var httpApi_1 = require("../../httpApi"); var _1 = require("./"); var ArticleCommentsClient = /** @class */ (function () { function ArticleCommentsClient(articleCommentRepliesClient, articleCommentsRoute, apiClient) { this.articleCommentRepliesClient = articleCommentRepliesClient; this.articleCommentsRoute = articleCommentsRoute; this.apiClient = apiClient; /** * Contains a reference to valid list of article comment states. It returns an object containing all article comment states. * @method * @example articleCommentsClient.statuses.approved; **/ this.statuses = _1.CommentStatus; } Object.defineProperty(ArticleCommentsClient.prototype, "replies", { /** * Provides direct access to `articleCommentRepliesClient`. * @method **/ get: function () { return this.articleCommentRepliesClient; }, enumerable: true, configurable: true }); Object.defineProperty(ArticleCommentsClient.prototype, "routeDefinition", { /** * Provides direct access to `articleCommentsRoute`. * @method * @example articleCommentsRoute.routeDefinition.get(); **/ get: function () { return this.articleCommentsRoute; }, enumerable: true, configurable: true }); /** * Returns a promise that is resolved once the approve article comment action has been performed. This action sets the state of an article comment to "approved". This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `articleCommentsRoute` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.updateParams(articleComment); * let uri = params['model'].links('comment-approve').href; * ``` * @method * @param data Article Comment object. * @param options Notification configuration used to control the article comment recourse access when managing notification distribution. * @returns A promise that is resolved once the approve article comment action has been performed. * @example // articleComment is a resource previously fetched using get action. articleCommentsClient.approve(articleComment, commentOptions) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ArticleCommentsClient.prototype.approve = function (data, options) { return this.apiClient.put(this.routeDefinition.approve(data), this.routeDefinition.updateParams(options)); }; /** * Returns a promise that is resolved once the unapprove article comment action has been performed. This action sets the state of an article comment to "unapproved". This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `articleCommentsRoute` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.updateParams(articleComment); * let uri = params['model'].links('comment-unapprove').href; * ``` * @method * @param data Article Comment object. * @returns A promise that is resolved once the unapprove article comment action has been performed. * @example // articleComment is a resource previously fetched using get action. articleCommentsClient.unapprove(articleComment) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ArticleCommentsClient.prototype.unapprove = function (data) { return this.apiClient.put(this.routeDefinition.unapprove(data), this.routeDefinition.updateParams(data)); }; /** * Returns a promise that is resolved once the create article comment action has been performed; this action creates a new comment for an article. * @method * @param data Article Comment object. * @returns A promise that is resolved once the create article comment action has been performed. * @example articleCommentsClient.create({ articleId : '<article-id>', comment : <comment>, userId : '<user-id>' }) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ArticleCommentsClient.prototype.create = function (data) { return this.apiClient.post(this.routeDefinition.create(data), this.routeDefinition.createParams(data)); }; /** * Returns a promise that is resolved once the find action has been performed. Success response returns a list of article comment resources matching the given criteria. * @method * @param options Query resource options object. * @returns A promise that is resolved once the find action has been performed. * @example articleCommentsClient.find({ pageNumber : 1, pageSize : 10, orderBy : '<field>', orderDirection : '<asc|desc>', search : '<search-phrase>' }) .success(function (collection) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); **/ ArticleCommentsClient.prototype.find = function (options) { return this.apiClient.get(this.routeDefinition.find(options)); }; /** * Returns a promise that is resolved once the flag article comment action has been performed. This action sets the state of an article comment to "flagged". This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `articleCommentsRoute` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.updateParams(articleComment); * let uri = params['model'].links('comment-flag').href; * ``` * @method * @param data Article Comment object. * @returns A promise that is resolved once the flag article comment action has been performed. * @example // articleComment is a resource previously fetched using get action. articleCommentsClient.flag(articleComment) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ArticleCommentsClient.prototype.flag = function (data) { return this.apiClient.put(this.routeDefinition.flag(data), this.routeDefinition.updateParams(data)); }; /** * Returns a promise that is resolved once the unflag article comment action has been performed. This action removes the "flagged" comment mark. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `articleCommentsRoute` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.updateParams(articleComment); * let uri = params['model'].links('comment-unflag').href; * ``` * @method * @param data Article Comment object. * @returns A promise that is resolved once the unflag article comment action has been performed. * @example // articleComment is a resource previously fetched using get action. articleCommentsClient.unflag(articleComment) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ArticleCommentsClient.prototype.unflag = function (data) { return this.apiClient.put(this.routeDefinition.unflag(data), this.routeDefinition.updateParams(data)); }; /** * Returns a promise that is resolved once the get action has been performed. Success response returns the specified article comment resource. * @method * @param id Id which uniquely identifies article comment resource that needs to be retrieved. * @param options Options object that contains embed data. * @returns A promise that is resolved once the get action has been performed. * @example articleCommentsClient.get('<article-id>', '<comment-id>') .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ArticleCommentsClient.prototype.get = function (id, options) { return this.apiClient.get(this.articleCommentsRoute.get(id, options)); }; /** * Returns a promise that is resolved once the remove article comment action has been performed. If the action is successfully completed, the article comment resource and its replies will be permanently removed from the system. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `articleCommentsRoute` route template. Here is an example of how a route can be obtained from HAL enabled objects: ``` let params = modelMapper.removeParams(articleComment); let uri = params['model'].links('delete').href; ``` * @method * @param data Article Comment object. * @returns A promise that is resolved once the remove article comment action has been performed. * @example // articleComment is a resource previously fetched using get action. articleCommentsClient.remove(articleComment) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ArticleCommentsClient.prototype.remove = function (data) { return this.apiClient.delete(this.routeDefinition.delete(data)); }; /** * Returns a promise that is resolved once the report article comment action has been performed. This action sets the state of an article comment to "reported". This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `articleCommentsRoute` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.updateParams(articleComment); * let uri = params['model'].links('comment-report').href; * ``` * @method * @param data Article Comment object. * @param options Notification configuration used to control the article comment recourse access when managing notification distribution. * @returns A promise that is resolved once the report article comment action has been performed. * @example // articleComment is a resource previously fetched using get action. articleCommentsClient.report(articleComment, commentOptions) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); **/ ArticleCommentsClient.prototype.report = function (data, options) { return this.apiClient.put(this.routeDefinition.report(data), this.routeDefinition.updateParams(options)); }; /** * Returns a promise that is resolved once the unreport article comment action has been performed. This action removes the "reported" comment mark. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `articleCommentsRoute` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.updateParams(articleComment); * let uri = params['model'].links('comment-unreport').href; * ``` * @method * @param data Article Comment object. * @returns A promise that is resolved once the unreport article comment action has been performed. * @example // articleComment is a resource previously fetched using get action. articleCommentsClient.unreport(articleComment) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ArticleCommentsClient.prototype.unreport = function (data) { return this.apiClient.put(this.routeDefinition.unreport(data), this.routeDefinition.updateParams(data)); }; /** * Returns a promise that is resolved once the update article comment action has been performed; this action updates an article comment resource. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `articleCommentsRoute` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.updateParams(articleComment); * let uri = params['model'].links('put').href; * ``` * @method * @param data Article Comment object. * @returns A promise that is resolved once the update article comment action has been performed. * @example // articleComment is a resource previously fetched using get action. articleCommentsClient.update(articleComment) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ArticleCommentsClient.prototype.update = function (data) { return this.apiClient.put(this.routeDefinition.update(data), this.routeDefinition.updateParams(data)); }; ArticleCommentsClient = tslib_1.__decorate([ inversify_1.injectable(), tslib_1.__param(0, inversify_1.inject(_1.TYPES.ArticleCommentRepliesClient)), tslib_1.__param(1, inversify_1.inject(_1.TYPES.ArticleCommentsRoute)), tslib_1.__param(2, inversify_1.inject(httpApi_1.httpTYPES.ApiClient)), tslib_1.__metadata("design:paramtypes", [_1.ArticleCommentRepliesClient, _1.ArticleCommentsRoute, httpApi_1.ApiClient]) ], ArticleCommentsClient); return ArticleCommentsClient; }()); exports.ArticleCommentsClient = ArticleCommentsClient; /** * @overview ***Notes:** - Refer to the [REST API documentation](https://github.com/Baasic/baasic-rest-api/wiki) for detailed information about available Baasic REST API end-points. - All end-point objects are transformed by the associated route service. */