UNPKG

loop-modules

Version:

Shared modules for the Loop product suite.

64 lines (63 loc) 2.89 kB
var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; // angular import { Injectable } from '@angular/core'; import { Http } from '@angular/http'; // libs import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; import { Observable } from 'rxjs'; import { Store, } from '@ngrx/store'; import { APIDispatcher } from '../utils/index'; import { AuthAction, EntriesAction } from '../actions/loop-user.action'; var LoopUserService = (function (_super) { __extends(LoopUserService, _super); function LoopUserService(http, store) { var _this = _super.call(this, http, store) || this; _this.http = http; _this.store = store; return _this; } LoopUserService.prototype.getAuthorizedUser = function () { var _this = this; return this.http.get('ma_loop/api/v1/users/current/').map(function (res) { return res.json(); }) .subscribe(function (authUser) { _this.store.dispatch(new AuthAction(authUser)); }); }; LoopUserService.prototype.query = function () { var _this = this; return this.http.get('ma_loop/api/v1/users/fetch').map(function (res) { return res.json(); }) .subscribe(function (users) { _this.store.dispatch(new EntriesAction(users)); }); }; LoopUserService.prototype.fetchAvatars = function (userIdentities) { var _this = this; return Observable.create(function (observer) { _this.http.post('ma_loop/api/v1/users/thumbnails', userIdentities).map(function (res) { return res.json(); }) .subscribe(function (response) { observer.next(response); observer.complete(); }); }); }; return LoopUserService; }(APIDispatcher)); LoopUserService = __decorate([ Injectable(), __metadata("design:paramtypes", [Http, Store]) ], LoopUserService); export { LoopUserService };