baasic-sdk-javascript
Version:
JavaScript SDK provides core functionality for building web and mobile applications on [Baasic](http://www.baasic.com/).
154 lines (153 loc) • 7.22 kB
JavaScript
"use strict";
/* globals module */
/**
* @module userRoute
* @description Baasic User Route Definition provides Baasic route templates which can be expanded to Baasic REST URIs. Various services can use Baasic User 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 common_1 = require("../../common");
var _1 = require("./");
var contracts_1 = require("../../core/contracts");
var UserRoute = /** @class */ (function (_super) {
tslib_1.__extends(UserRoute, _super);
function UserRoute(appOptions, userSocialLoginRoute) {
var _this = _super.call(this, appOptions) || this;
_this.appOptions = appOptions;
_this.userSocialLoginRoute = userSocialLoginRoute;
/**
* Find route with route and query parameters.
**/
_this.findRoute = 'users/{?searchQuery,userIds,roleIds,roleNames,isApproved,isLocked,page,rpp,sort,embed,fields}';
/**
* Get route with route and query parameters.
**/
_this.getRoute = 'users/{username}/{?embed,fields}';
/**
* Create route with route and query parameters.
**/
_this.createRoute = 'users';
/**
* Update route with route and query parameters.
**/
_this.updateRoute = 'users/{id}';
/**
* Delete route with route and query parameters.
**/
_this.deleteRoute = 'users/{id}';
/**
* Exists route with route and query parameters.
**/
_this.existsRoute = 'users/{username}/exists/';
/**
* Change password route with route and query parameters.
**/
_this.changePasswordRoute = 'users/{username}/change-password';
/**
* Unlock route with route and query parameters.
**/
_this.unlockRoute = 'users/{id}/unlock';
/**
* Lock route with route and query parameters.
**/
_this.lockRoute = 'users/{id}/lock';
/**
* Approve route with route and query parameters.
**/
_this.approveRoute = 'users/{id}/approve';
/**
* Disapprove route with route and query parameters.
**/
_this.disapproveRoute = 'users/{id}/disapprove';
return _this;
}
Object.defineProperty(UserRoute.prototype, "socialLogin", {
get: function () {
return this.userSocialLoginRoute;
},
enumerable: true,
configurable: true
});
/**
* Parses find user route which can be expanded with additional options. Supported items are:
* - `searchQuery` - A string referencing user properties using the phrase or BQL (Baasic Query Language) search.
* - `page` - A value used to set the page number, i.e. to retrieve certain user subset from the storage.
* - `rpp` - A value used to limit the size of result set per page.
* - `sort` - A string used to set the user property to sort the result collection by.
* - `embed` - Comma separated list of resources to be contained within the current representation.
* @method
* @example userRoute.find({searchQuery: '<search-phrase>'});
**/
UserRoute.prototype.find = function (options) {
return _super.prototype.baseFind.call(this, this.findRoute, options);
};
/**
* Parses get user route which must be expanded with the username of the previously created user resource in the system. Additional expand supported items are:
* - `embed` - Comma separated list of resources to be contained within the current representation.
* @method
* @example userRoute.get({username: '<username>'})
**/
UserRoute.prototype.get = function (id, options) {
return _super.prototype.baseGet.call(this, this.getRoute, id, options, 'username');
};
/**
* Parses create user route, this URI template does not expose any additional options.
* @method
* @example userRoute.create();
**/
UserRoute.prototype.create = function () {
return _super.prototype.baseCreate.call(this, this.createRoute, {});
};
UserRoute.prototype.update = function (data) {
return _super.prototype.baseUpdate.call(this, this.updateRoute, data);
};
UserRoute.prototype.delete = function (data) {
return _super.prototype.baseDelete.call(this, this.deleteRoute, data);
};
/**
* Parses user exists route; URI template should be expanded with the username whose availability you'd like to check.
* @method
* @param username A username which uniquely identifies an application user.
* @example userRoute.exists({username: '<username>'});
**/
UserRoute.prototype.exists = function (username, options) {
return _super.prototype.baseGet.call(this, this.existsRoute, username, options, 'username');
};
/**
* Parses change password route, URI template should be expanded with the username of the user resource whose password should be updated.
* @method
* @param username A username or id which uniquely identifies user resource.
* @example userRoute.changePassword({username: '<username>'});
**/
UserRoute.prototype.changePassword = function (username) {
return _super.prototype.baseUpdate.call(this, this.changePasswordRoute, { username: username });
};
UserRoute.prototype.unlock = function (data) {
return _super.prototype.baseUpdate.call(this, this.unlockRoute, data, null, 'unlock');
};
UserRoute.prototype.lock = function (data) {
return _super.prototype.baseUpdate.call(this, 'users/{id}/lock', data, null, 'lock');
};
UserRoute.prototype.approve = function (data) {
return _super.prototype.baseUpdate.call(this, this.approveRoute, data, null, 'approve');
};
UserRoute.prototype.disapprove = function (data) {
return _super.prototype.baseUpdate.call(this, this.disapproveRoute, data, null, 'disapprove');
};
UserRoute = tslib_1.__decorate([
inversify_1.injectable(),
tslib_1.__param(0, inversify_1.inject(contracts_1.TYPES.IAppOptions)),
tslib_1.__param(1, inversify_1.inject(_1.TYPES.UserSocialLoginRoute)),
tslib_1.__metadata("design:paramtypes", [Object, _1.UserSocialLoginRoute])
], UserRoute);
return UserRoute;
}(common_1.BaseRoute));
exports.UserRoute = UserRoute;
/**
* @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.
- [URI Template](https://github.com/Baasic/uritemplate-js) syntax enables expanding the Baasic route templates to Baasic REST URIs providing it with an object that contains URI parameters.
- All end-point objects are transformed by the associated route definition.
*/