UNPKG

baasic-sdk-javascript

Version:

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

155 lines (154 loc) 8.87 kB
"use strict"; /* globals module */ /** * @module shoppingCartClient * @description Shopping Cart Item Client provides Baasic route templates which can be expanded to Baasic REST URIs. Various services can use BaasicShopping Cart Item Route Service to obtain needed routes while other routes will be obtained through HAL. By convention, all route services use the same function names as their corresponding services. */ 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 ShoppingCartItemClient = /** @class */ (function () { function ShoppingCartItemClient(shoppingCartItemRoute, apiClient, shoppingCartItemBatchClient) { this.shoppingCartItemRoute = shoppingCartItemRoute; this.apiClient = apiClient; this.shoppingCartItemBatchClient = shoppingCartItemBatchClient; } Object.defineProperty(ShoppingCartItemClient.prototype, "routeDefinition", { get: function () { return this.shoppingCartItemRoute; }, enumerable: true, configurable: true }); Object.defineProperty(ShoppingCartItemClient.prototype, "batch", { get: function () { return this.shoppingCartItemBatchClient; }, enumerable: true, configurable: true }); /** * Returns a promise that is resolved once the remove action has been performed. This action will remove one shopping cart item resources from the system if successfully completed. Specified shopping cart item and all accompanying derived resources will be removed from the system. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply baasicShoppingCartItemRouteService route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.removeParams(shoppingCartItem); * let uri = params['id'].links('delete').href; * ``` * @method * @param id Shopping Cart Item id used to delete specific Shopping Cart Item resource from the system. * @example // id is a shopping cart item resource id previously fetched using get action. The following action will remove the original shopping cart item resource and all accompanying derived shopping cart item resources. shoppingCartClient.remove(id) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ShoppingCartItemClient.prototype.remove = function (id) { return this.apiClient.delete(this.routeDefinition.delete(id)); }; /** * Returns a promise that is resolved once the remove action has been performed. This action will remove one shopping cart item resources from the system if successfully completed. Specified shopping cart item and all accompanying derived resources will be removed from the system. * * @method * @param userId User Id from the User that the Shopping Cart Item resource from the system belongs to. * @param productId Product id from the Product that the Shopping Cart Item contains. * @example // The following action will remove the original shopping cart item resource and all accompanying derived shopping cart item resources. shoppingCartClient.removeByUserIdAndProductId(userId, productId) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ShoppingCartItemClient.prototype.removeByUserIdAndProductId = function (userId, productId) { return this.apiClient.delete(this.routeDefinition.deleteByUserIdAndProductId(userId, productId)); }; /** * Returns a promise that is resolved once the remove action has been performed. This action will remove all shopping cart item resources for a given userId from the system if successfully completed. * * @method * @param userId User Id from the User that the Shopping Cart Item resource from the system belongs to. * @example // The following action will remove the original shopping cart item resource and all accompanying derived shopping cart item resources. shoppingCartClient.removeByUserIdAndProductId(userId) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ShoppingCartItemClient.prototype.removeByUserId = function (userId) { return this.apiClient.delete(this.routeDefinition.deleteByUserId(userId)); }; /** * Returns a promise that is resolved once the create shopping cart item action has been performed; this action creates a new shopping cart item. * @method * @param data Shopping Cart Item object. * @returns A promise that is resolved once the create shopping cart item action has been performed. * @example shoppingCartClient.create(shoppingCartItem) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ShoppingCartItemClient.prototype.create = function (data) { return this.apiClient.post(this.routeDefinition.create(), this.routeDefinition.createParams(data)); }; /** * Returns a promise that is resolved once the create shopping cart item action has been performed; this action creates a new shopping cart item. * @method * @param data Shopping Cart Item object. * @returns A promise that is resolved once the create shopping cart item action has been performed. * @example shoppingCartClient.createByUserIdAndProductId(shoppingCartItem) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ShoppingCartItemClient.prototype.createByUserIdAndProductId = function (userId, productId, string, data) { data.userId = userId; data.productId = productId; return this.apiClient.post(this.routeDefinition.createByUserIdAndProductId(data), this.routeDefinition.createParams(data)); }; /** * Returns a promise that is resolved once the purge action has been performed. This action will remove all shopping cart item resources from the system if successfully completed. * @method * @example // Remove original shopping cart item resources shoppingCartClient.purge() .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ ShoppingCartItemClient.prototype.purge = function () { return this.apiClient.delete(this.routeDefinition.purge()); }; ShoppingCartItemClient = tslib_1.__decorate([ inversify_1.injectable(), tslib_1.__param(0, inversify_1.inject(_1.TYPES.ShoppingCartItemRoute)), tslib_1.__param(1, inversify_1.inject(httpApi_1.httpTYPES.ApiClient)), tslib_1.__param(2, inversify_1.inject(_1.TYPES.ShoppingCartItemBatchClient)), tslib_1.__metadata("design:paramtypes", [_1.ShoppingCartItemRoute, httpApi_1.ApiClient, _1.ShoppingCartItemBatchClient]) ], ShoppingCartItemClient); return ShoppingCartItemClient; }()); exports.ShoppingCartItemClient = ShoppingCartItemClient; /** * @overview ***Notes:** - Refer to the [REST API documentation](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. */