UNPKG

3.09 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var core_1 = require("@angular/core");
4var http_1 = require("@angular/common/http");
5var Rx_1 = require("rxjs/Rx");
6var models_1 = require("../../models");
7var user_module_configuration_1 = require("../../services/user-module-configuration");
8var store_1 = require("@ngrx/store");
9var profile_view_actions_1 = require("../../profile-view/profile-view.actions");
10var infra_1 = require("@soushians/infra");
11var index_1 = require("../../index");
12var UserService = /** @class */ (function () {
13 function UserService(http, store, configurationService) {
14 var _this = this;
15 this.http = http;
16 this.store = store;
17 this.configurationService = configurationService;
18 setTimeout(function () {
19 _this.store.dispatch(new profile_view_actions_1.GetProfile());
20 }, 999);
21 }
22 UserService.prototype.getProfileInformation = function () {
23 var _this = this;
24 return this.configurationService.config$
25 .filter(function (config) { return config.endpoints.profileInformation != ""; })
26 .take(1)
27 .switchMap(function (config) { return _this.http.get(config.endpoints.profileInformation); })
28 .map(function (response) { return response; });
29 };
30 UserService.prototype.editProfile = function (data) {
31 var model = new models_1.EditProfile_ApiModel.Request(data);
32 return this.http
33 .put(infra_1.stringTemplate(this.configurationService.config.endpoints.editProfile, model), model.getRequestBody())
34 .map(function (response) {
35 return new models_1.EditProfile_ApiModel.Response(response).extractData();
36 });
37 };
38 UserService.prototype.getInfo = function (data) {
39 var _this = this;
40 var model = new models_1.ProfileViewModel.Request(data);
41 if (this.responseCache && this.responseCache.Email == model.Email)
42 return Rx_1.Observable.of(this.responseCache);
43 return this.http
44 .get(infra_1.stringTemplate(this.configurationService.config.endpoints.getUserInfo, model))
45 .do(function (response) { return (_this.responseCache = response); })
46 .map(function (response) { return response; });
47 };
48 UserService.prototype.is_role = function (role) {
49 return this.store
50 .select(index_1.getUser)
51 .filter(function (user) { return user && user.Roles != undefined; })
52 .take(1)
53 .map(function (user) { return user.Roles.indexOf(role) > -1; });
54 };
55 UserService.decorators = [
56 { type: core_1.Injectable },
57 ];
58 /** @nocollapse */
59 UserService.ctorParameters = function () { return [
60 { type: http_1.HttpClient, },
61 { type: store_1.Store, },
62 { type: user_module_configuration_1.UserConfigurationService, },
63 ]; };
64 return UserService;
65}());
66exports.UserService = UserService;
67//# sourceMappingURL=user.service.js.map
\No newline at end of file