UNPKG

baasic-sdk-javascript

Version:

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

193 lines (192 loc) 11 kB
"use strict"; /* globals module */ /** * @module articleSubRatingsClient * @description Article Sub Ratings Client provides an easy way to consume Article Ratings REST API end-points. `articleRatingsClient` functions enable performing standard CRUD operations directly on article rating resources, whereas the `articleService` functions allow management between article and article rating. In order to obtain needed routes `articleRatingsClient` uses `articleRatingsRoute`. */ 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 ArticleInstanceRatingsClient = /** @class */ (function () { function ArticleInstanceRatingsClient(articleInstanceRatingsRoute, apiClient) { this.articleInstanceRatingsRoute = articleInstanceRatingsRoute; this.apiClient = apiClient; } Object.defineProperty(ArticleInstanceRatingsClient.prototype, "routeDefinition", { /** * Provides direct access to `articleRatingsRoute`. * @method * @example articleInstanceRatingsClient.routeDefinition.get(id); **/ get: function () { return this.articleInstanceRatingsRoute; }, enumerable: true, configurable: true }); /** * Returns a promise that is resolved once the create article rating action has been performed; this action creates a new rating for an article. * @method * @param data An article rating object that needs to be inserted into the system. * @returns A promise that is resolved once the create article rating action has been performed. * @example articleInstanceRatingsClient.create({ articleId : '<article-id>', rating : 5, userId : '<user-id>' }) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ArticleInstanceRatingsClient.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 rating resources matching the given criteria. * @method * @param articleId Article slug or id which uniquely identifies article whose rating resources need to be retrieved. * @param options Query resource options object. * @returns A promise that is resolved once the find action has been performed. * @example articleInstanceRatingsClient.find({ pageNumber : 1, pageSize : 10, orderBy : '<field>', orderDirection : '<asc|desc>', search : '<search-phrase>' }) .then(function (collection) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ArticleInstanceRatingsClient.prototype.find = function (articleId, options) { return this.apiClient.get(this.articleInstanceRatingsRoute.find(articleId, options)); }; /** * Returns a promise that is resolved once the findByUser action has been performed. Success response returns a list of article rating resources filtered by username. * @method * @param articleId Article slug or id which uniquely identifies article whose rating resources need to be retrieved. * @param username Username which uniquely identifies a user which has created an article rating. * @param options Query resource options object. * @returns A promise that is resolved once the findByUser action has been performed. * @example articleInstanceRatingsClient.find('<username>', { pageNumber : 1, pageSize : 10, orderBy : '<field>', orderDirection : '<asc|desc>' }) .then(function (collection) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ArticleInstanceRatingsClient.prototype.findByUser = function (articleId, username, options) { return this.apiClient.get(this.articleInstanceRatingsRoute.findByUser(articleId, username, options)); }; /** * Returns a promise that is resolved once the get action has been performed. Success response returns the specified article rating resource. * @method * @param articleId Article slug or id which uniquely identifies article whose rating resources need to be retrieved. * @param id Article slug or id which uniquely identifies article 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 articleInstanceRatingsClient.get('<articleRating-id>') .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ArticleInstanceRatingsClient.prototype.get = function (articleId, id, options) { return this.apiClient.get(this.articleInstanceRatingsRoute.get(articleId, id, options)); }; /** * Returns a promise that is resolved once the update article rating action has been performed; this action updates an article rating. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `articleRatingsRoute` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.removeParams(articleRating); * let uri = params['model'].links('put').href; * ``` * @method * @param data An article object used to update specified article resource. * @returns A promise that is resolved once the update article rating action has been performed. * @example // articleRating is a resource previously fetched using get action. articleRating.rating = 4; articleInstanceRatingsClient.update(articleRating) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ArticleInstanceRatingsClient.prototype.update = function (data) { return this.apiClient.put(this.routeDefinition.update(data), this.routeDefinition.updateParams(data)); }; /** * Returns a promise that is resolved once the remove article rating action has been performed. If the action is successfully completed, the article rating resource will be permanently removed from the system. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `articleRatingsRoute` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.removeParams(articleRating); * let uri = params['model'].links('delete').href; * ``` * @method * @param data Rating resource resource that needs to be deleted. * @returns a promise that is resolved once the remove article rating action has been performed. * @example // articleRating is a resource previously fetched using get action. articleInstanceRatingsClient.remove(articleRating) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ArticleInstanceRatingsClient.prototype.remove = function (data) { return this.apiClient.delete(this.routeDefinition.delete(data)); }; /** * Returns a promise that is resolved once the removeAll article rating action has been performed. If the action is successfully completed, the article rating resources will be permanently removed from the system for a specified article resource. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `articleInstanceRouteClient` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.removeParams(article); * let uri = params['model'].links('delete-ratings-by-article').href; * ``` * @method * @param data Article object whose ratings needs to be deleted. * @returns A promise that is resolved once the removeAll article rating action has been performed. * @example // article is a resource previously fetched using get action. articleInstanceRatingsClient.removeAll(article) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ArticleInstanceRatingsClient.prototype.removeAll = function (data) { return this.apiClient.delete(this.routeDefinition.deleteAll(data)); }; ArticleInstanceRatingsClient = tslib_1.__decorate([ inversify_1.injectable(), tslib_1.__param(0, inversify_1.inject(__1.TYPES.ArticleInstanceRatingsRoute)), tslib_1.__param(1, inversify_1.inject(httpApi_1.httpTYPES.ApiClient)), tslib_1.__metadata("design:paramtypes", [__1.ArticleInstanceRatingsRoute, httpApi_1.ApiClient]) ], ArticleInstanceRatingsClient); return ArticleInstanceRatingsClient; }()); exports.ArticleInstanceRatingsClient = ArticleInstanceRatingsClient; /** * @copyright (c) 2017 Mono Ltd * @license MIT * @author Mono Ltd * @overview ***Notes:** - Refer to the [Baasic REST API](http://dev.baasic.com/api/reference/home) for detailed information about available Baasic REST API end-points. - All end-point objects are transformed by the associated route service. */