UNPKG

baasic-sdk-angularjs

Version:

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

161 lines (114 loc) 4.81 kB
# baasicArticleRatingsService Baasic Article Ratings Service provides an easy way to consume Baasic Article Ratings REST API end-points. `baasicArticleRatingsService` functions enable performing standard CRUD operations directly on article rating resources, whereas the `baasicArticleService` functions allow management between article and article rating. In order to obtain needed routes `baasicArticleRatingsService` uses `baasicArticleRatingsRouteService`. * * * ### baasicArticleRatingsService.create() Returns a promise that is resolved once the create article rating action has been performed; this action creates a new rating for an article. **Example**: ```js baasicArticleRatingsService.create({ articleId : '<article-id>', rating : 5, userId : '<user-id>' }) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicArticleRatingsService.find() 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. **Example**: ```js baasicArticleRatingsService.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 }); ``` ### baasicArticleRatingsService.findByUser() 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. **Example**: ```js baasicArticleRatingsService.find('<username>', { pageNumber : 1, pageSize : 10, orderBy : '<field>', orderDirection : '<asc|desc>' }) .success(function (collection) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicArticleRatingsService.get() Returns a promise that is resolved once the get action has been performed. Success response returns the specified article rating resource. **Example**: ```js baasicArticleRatingsService.get('<articleRating-id>') .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicArticleRatingsService.update() 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 `baasicArticleRatingsRouteService` route template. Here is an example of how a route can be obtained from HAL enabled objects: ``` var params = baasicApiService.removeParams(articleRating); var uri = params['model'].links('put').href; ``` **Example**: ```js // articleRating is a resource previously fetched using get action. articleRating.rating = 4; baasicArticleRatingsService.update(articleRating) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicArticleRatingsService.remove() 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 `baasicArticleRatingsRouteService` route template. Here is an example of how a route can be obtained from HAL enabled objects: ``` var params = baasicApiService.removeParams(articleRating); var uri = params['model'].links('delete').href; ``` **Example**: ```js // articleRating is a resource previously fetched using get action. baasicArticleRatingsService.remove(articleRating) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicArticleRatingsService.routeService() Provides direct access to `baasicArticleRatingsRouteService`. **Example**: ```js baasicArticleRatingsService.routeService.get(expandObject); ``` * * * **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. *(c) 2017 Mono Ltd* **Author:** Mono Ltd **License:** MIT