UNPKG

baasic-sdk-angularjs

Version:

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

214 lines (152 loc) 6.04 kB
# baasicUserProfileService Baasic User Profile Service provides an easy way to consume Baasic User Profile REST API end-points. In order to obtain needed routes `baasicUserProfileService` uses `baasicUserProfileRouteService`. * * * ### baasicUserProfileService.find() Returns a promise that is resolved once the find action has been performed. Success response returns a list of user profile resources matching the given criteria. **Example**: ```js userProfileService.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 }); ``` ### baasicUserProfileService.get() Returns a promise that is resolved once the get action has been performed. Success response returns the user profile resource. **Example**: ```js baasicUserProfileService.get() .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicUserProfileService.create() Returns a promise that is resolved once the create user profile action has been performed; this action creates a new user profile resource. **Example**: ```js baasicUserProfileService.create({ firstName : '<first-name>', lastName : '<last-name>', displayName: '<nick-name>' }) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicUserProfileService.update() Returns a promise that is resolved once the update user profile action has been performed; this action updates a user profile resource. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicUserProfileRouteService` route template. Here is an example of how a route can be obtained from HAL enabled objects: ``` var params = baasicApiService.removeParams(userProfile); var uri = params['model'].links('put').href; ``` **Example**: ```js // userProfile is a resource previously fetched using get action. userProfile.displayName = '<nick-name>'; baasicUserProfileService.update(userProfile) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicUserProfileService.remove() Returns a promise that is resolved once the remove action has been performed. This action will remove a user profile resource from the system if successfully completed. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicUserProfileRouteService` route template. Here is an example of how a route can be obtained from HAL enabled objects: ``` var params = baasicApiService.removeParams(userProfile); var uri = params['model'].links('delete').href; ``` **Example**: ```js // userProfile is a resource previously fetched using get action. baasicUserProfileService.remove(userProfile) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicUserProfileService.acl.get() Returns a promise that is resolved once the get action has been performed. Success response returns a list of ACL policies established for the specified user profile resource. **Example**: ```js baasicUserProfileService.acl.get({id: '<profile-id>'}) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicUserProfileService.acl.update() Returns a promise that is resolved once the update acl action has been performed, this action creates new ACL policy for the specified user profile resource. **Example**: ```js var options = {id : '<profile-id>'}; var aclObj = { actionId: '<action-id'>, roleId: '<roleId>', userId: '<userId>' }; options[baasicConstants.modelPropertyName] = aclObj; baasicUserProfileService.acl.update(options) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicUserProfileService.acl.deleteByUser() Returns a promise that is resolved once the removeByUser action has been performed. This action deletes ACL policy assigned to the specified user and user profile resource. **Example**: ```js baasicUserProfileService.acl.removeByUser('<profile-id>', '<access-action>', '<username>') .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicUserProfileService.acl.deleteByRole() Returns a promise that is resolved once the removeByRole action has been performed. This action deletes ACL policy assigned to the specified role and user profile resource. **Example**: ```js baasicUserProfileService.acl.removeByRole('<profile-id>', '<access-action>', '<role-name>') .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicUserProfileService.routeService() Provides direct access to `userProfileRouteService`. **Example**: ```js baasicUserProfileService.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