| .. | .. |
|---|
| 1 | 1 | import { Observable } from 'rxjs/Rx'; |
|---|
| 2 | 2 | import { Injectable } from '@angular/core'; |
|---|
| 3 | 3 | import { Http, RequestOptions } from '@angular/http'; |
|---|
| 4 | +import { Locker } from 'angular-safeguard'; |
|---|
| 4 | 5 | import { SeCurisResourceServices, MySearchParams } from './base'; |
|---|
| 5 | 6 | import { LocaleService } from '../common/i18n'; |
|---|
| 6 | 7 | |
|---|
| .. | .. |
|---|
| 82 | 83 | |
|---|
| 83 | 84 | @Injectable() |
|---|
| 84 | 85 | export class PacksService extends SeCurisResourceServices { |
|---|
| 85 | | - constructor(http: Http, $L: LocaleService) { |
|---|
| 86 | | - super($L, http, 'pack'); |
|---|
| 86 | + constructor(http: Http, $L: LocaleService, store: Locker) { |
|---|
| 87 | + super($L, http, store, 'pack'); |
|---|
| 87 | 88 | } |
|---|
| 88 | 89 | |
|---|
| 89 | 90 | public get(filter?: PacksFilter | number | string) { |
|---|
| 90 | | - if (!filter || typeof filter === "number" || typeof filter === "string") { |
|---|
| 91 | | - return super.get(filter); |
|---|
| 92 | | - } |
|---|
| 93 | | - let searchParams = new MySearchParams(filter); |
|---|
| 94 | | - let url = `${this.resource}/?${searchParams}`; |
|---|
| 95 | | - return this.http.get(url).map(response => response.json()).catch(err => super.processErrorResponse(err)); |
|---|
| 96 | | - } |
|---|
| 97 | | - |
|---|
| 91 | + if (!filter || typeof filter === "number" || typeof filter === "string") { |
|---|
| 92 | + return super.get(filter); |
|---|
| 93 | + } |
|---|
| 94 | + const searchParams = new MySearchParams(filter); |
|---|
| 95 | + const url = `${this.resource}/?${searchParams}`; |
|---|
| 96 | + // Añade las cabeceras usando el método de la base |
|---|
| 97 | + return this.http.get(url, this.getAuthHeaders()) |
|---|
| 98 | + .map(response => response.json()) |
|---|
| 99 | + .catch(err => super.processErrorResponse(err)); |
|---|
| 100 | + } |
|---|
| 98 | 101 | |
|---|
| 99 | 102 | public activate(id: number) { |
|---|
| 100 | 103 | return super.action(id, "activate"); |
|---|
| .. | .. |
|---|
| 108 | 111 | return super.action(id, "putonhold"); |
|---|
| 109 | 112 | } |
|---|
| 110 | 113 | public nextLicCode(id: number) { |
|---|
| 111 | | - let url = `pack/${id}/next_license_code` |
|---|
| 112 | | - return this.http.get(url).map(response => response.text()); |
|---|
| 114 | + const url = `api/pack/${id}/next_license_code`; |
|---|
| 115 | + return this.http.get(url, this.getAuthHeaders()) |
|---|
| 116 | + .map(response => response.text()); |
|---|
| 113 | 117 | } |
|---|
| 114 | | - |
|---|
| 115 | | - |
|---|
| 116 | | - public isActionAvailable(action:string, pack:any) { |
|---|
| 118 | + |
|---|
| 119 | + public isActionAvailable(action:string, pack:any) { |
|---|
| 117 | 120 | var validStatuses = PACK_ACTIONS_BY_STATUS[action]; |
|---|
| 118 | 121 | return pack && validStatuses && validStatuses.indexOf(pack.status) !== -1; |
|---|
| 119 | 122 | } |
|---|