baasic-sdk-javascript
Version:
JavaScript SDK provides core functionality for building web and mobile applications on [Baasic](http://www.baasic.com/).
163 lines (162 loc) • 8.59 kB
JavaScript
"use strict";
/* globals module */
/**
* @module blogPostFilesClient
* @description Blog Post Files Client provides Baasic route templates which can be expanded to Baasic REST URIs. Various services can use Baasic Files 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 BlogPostFilesClient = /** @class */ (function () {
function BlogPostFilesClient(blogPostFilesRoute, blogPostFilesStreamsClient, BlogPostFilesBatchClient, apiClient) {
this.blogPostFilesRoute = blogPostFilesRoute;
this.blogPostFilesStreamsClient = blogPostFilesStreamsClient;
this.BlogPostFilesBatchClient = BlogPostFilesBatchClient;
this.apiClient = apiClient;
}
Object.defineProperty(BlogPostFilesClient.prototype, "routeDefinition", {
get: function () {
return this.blogPostFilesRoute;
},
enumerable: true,
configurable: true
});
Object.defineProperty(BlogPostFilesClient.prototype, "streams", {
get: function () {
return this.blogPostFilesStreamsClient;
},
enumerable: true,
configurable: true
});
Object.defineProperty(BlogPostFilesClient.prototype, "batch", {
get: function () {
return this.BlogPostFilesBatchClient;
},
enumerable: true,
configurable: true
});
/**
* Returns a promise that is resolved once the find action has been performed. Success response returns a list of file 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 blogPostFilesClient.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
});
**/
BlogPostFilesClient.prototype.find = function (options) {
return this.apiClient.get(this.routeDefinition.find(options));
};
/**
* Returns a promise that is resolved once the get action has been performed. Success response returns requested file resource.
* @method
* @param id BlogPost file id which uniquely identifies blogPost 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 blogPostFilesClient.get('<file-id>')
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
BlogPostFilesClient.prototype.get = function (id, options) {
return this.apiClient.get(this.blogPostFilesRoute.get(id, options));
};
/**
* Returns a promise that is resolved once the unlink action has been performed. This action will remove one or many file resources from the system if successfully completed. Specified file and all its accompanying derived resources will be removed from the system. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply baasicBlogPostFilesRouteService route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.removeParams(fileEntry);
* let uri = params['model'].links('unlink').href;
* ```
* @method
* @param data BlogPost file object.
* @param options options object.
* @returns A promise that is resolved once the unlink action has been performed.
* @example // fileEntry is a file resource previously fetched using get action. The following action will remove the original file resource and all accompanying derived file resources.
blogPostFilesRoute.remove(fileEntry)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
BlogPostFilesClient.prototype.unlink = function (data, options) {
if (!options) {
options = {};
}
return this.apiClient.delete(this.blogPostFilesRoute.unlink(data, options));
};
/**
* Returns a promise that is resolved once the update file action has been performed; this action will update a file resource if successfully completed. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicBlogPostFilesRouteService` route template. Here is an example of how a route can be obtained from HAL enabled objects:
```
let params = modelMapper.updateParams(fileEntry);
let uri = params['model'].links('put').href;
```
* @method
* @param data BlogPost file object that need to be updated in the system.
* @returns A promise that is resolved once the update file action has been performed.
* @example // fileEntry is a file resource previously fetched using get action.
fileEntry.description = '<description>';
blogPostFilesClient.update(fileEntry)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
BlogPostFilesClient.prototype.update = function (data) {
return this.apiClient.put(this.routeDefinition.update(data), this.routeDefinition.updateParams(data));
};
/**
* Returns a promise that is resolved once the link action has been performed; this action links file resource from other modules into the BlogPost Files module (For example: file resources from the Media Vault module can be linked directly into the BlogPost Files module).
* @method
* @param data BlogPost file object.
* @returns A promise that is resolved once the link action has been performed.
* @example blogPostFilesClient.link(fileObject)
.then(function (response, status, headers, config) {
// perform success handling here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
BlogPostFilesClient.prototype.link = function (data) {
return this.apiClient.post(this.routeDefinition.link(), this.routeDefinition.createParams(data));
};
BlogPostFilesClient = tslib_1.__decorate([
inversify_1.injectable(),
tslib_1.__param(0, inversify_1.inject(_1.TYPES.BlogPostFilesRoute)),
tslib_1.__param(1, inversify_1.inject(_1.TYPES.BlogPostFilesStreamsClient)),
tslib_1.__param(2, inversify_1.inject(_1.TYPES.BlogPostFilesBatchClient)),
tslib_1.__param(3, inversify_1.inject(httpApi_1.httpTYPES.ApiClient)),
tslib_1.__metadata("design:paramtypes", [_1.BlogPostFilesRoute,
_1.BlogPostFilesStreamsClient,
_1.BlogPostFilesBatchClient,
httpApi_1.ApiClient])
], BlogPostFilesClient);
return BlogPostFilesClient;
}());
exports.BlogPostFilesClient = BlogPostFilesClient;
/**
* @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.
*/