UNPKG

baasic-sdk-javascript

Version:

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

125 lines (124 loc) 6.17 kB
"use strict"; /* globals module */ /** * @module calendarRoute * @description BaasicCalendarRoute Definition provides Baasic route templates which can be expanded to Baasic REST URIs. Various services can use BaasicCalendarRoute Definition 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 contracts_1 = require("../../core/contracts"); var CalendarRoute = /** @class */ (function (_super) { tslib_1.__extends(CalendarRoute, _super); function CalendarRoute(appOptions) { var _this = _super.call(this, appOptions) || this; _this.appOptions = appOptions; _this.findRoute = 'calendars/{?searchQuery,page,rpp,sort,embed,fields,from,to,ids,ownerIds}'; _this.getRoute = 'calendars/{id}/{?embed,fields}'; _this.createRoute = 'calendars'; _this.updateRoute = 'calendars/{id}'; _this.deleteRoute = 'calendars/{id}'; _this.purgeRoute = 'calendars/purge'; return _this; } /** * Parses find route which can be expanded with additional GetCalendarOptions. Supported items are: * - `searchQuery` - A string referencing Calendar properties using the phrase or BQL (Baasic Query Language) search. * - `page` - A value used to set the page number, i.e. to retrieve certain Calendar subset from the storage. * - `rpp` - A value used to limit the size of result set per page. * - `sort` - A string used to set the Calendar property to sort the result collection by. * - `embed` - Comma separated list of resources to be contained within the current representation. * - `from` - Fluent syntax for 'From' date. Used to limit the dataset to only use resources starting from this date * - `to` - Fluent syntax for 'To' date. Used to limit the dataset to only use resources ending to this date. * - `ownerIds` - Used to limit the dataset to only use resources beloging to specified owners. * @method * @param options Query resource GetCalendarOptions object. * @example calendarRoute.find({searchQuery: '<search-phrase>'}); */ CalendarRoute.prototype.find = function (options) { var opt; if (options) { opt = options; opt.to = this.getToDate(opt); opt.from = this.getFromDate(opt); } else { opt = {}; } return _super.prototype.baseFind.call(this, this.findRoute, opt); }; /** * Parses get route which must be expanded with the id of the previously created Calendar resource. This route can be expanded with additional eEtRequestOptions. Supported items are: * - `embed` - Comma separated list of resources to be contained within the current representation. * @method * @param id Calendar id which uniquely identifies Calendar resource that needs to be retrieved. * @param options Query resource options object. * @example calendarRoute.get(id); */ CalendarRoute.prototype.get = function (id, options) { return _super.prototype.baseGet.call(this, this.getRoute, id, options); }; /** * Parses create route. This URI template does not expose any additional options. * @method * @param data A Calendar object that needs to be inserted into the system. * @example calendarRoute.create(data); */ CalendarRoute.prototype.create = function (data) { return _super.prototype.baseCreate.call(this, this.createRoute, data); }; /** * Parses update route. This URI template does not expose any additional options. * @method * @param data A Calendar object used to update specified Calendar resource. * @example calendarRoute.update(data); */ CalendarRoute.prototype.update = function (data) { return _super.prototype.baseUpdate.call(this, this.updateRoute, data); }; /** * Parses delte route. This URI template does not expose any additional options. * @method * @param data A Calendar object used to delete specified Calendar resource. * @example calendarRoute.delete(data); */ CalendarRoute.prototype.delete = function (data) { return _super.prototype.baseDelete.call(this, this.deleteRoute, data); }; /** * Parses purge route. This URI template does not expose any additional options. * @method * @example calendarRoute.purge(); */ CalendarRoute.prototype.purge = function () { return _super.prototype.baseDelete.call(this, this.purgeRoute, {}); }; CalendarRoute.prototype.getToDate = function (options) { if (!this.utility.isUndefined(options.to) && options.to !== null) { return options.to.toISOString(); } return undefined; }; CalendarRoute.prototype.getFromDate = function (options) { if (!this.utility.isUndefined(options.from) && options.from !== null) { return options.from.toISOString(); } return undefined; }; CalendarRoute = tslib_1.__decorate([ inversify_1.injectable(), tslib_1.__param(0, inversify_1.inject(contracts_1.TYPES.IAppOptions)), tslib_1.__metadata("design:paramtypes", [Object]) ], CalendarRoute); return CalendarRoute; }(common_1.BaseRoute)); exports.CalendarRoute = CalendarRoute; /** * @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. - [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 service. */