{ "version": 3, "sources": ["src/app/_services/device.service.ts"], "sourcesContent": ["import { HttpClient } from '@angular/common/http';\r\nimport { Injectable } from '@angular/core';\r\nimport { ReplaySubject, shareReplay, tap } from 'rxjs';\r\nimport { environment } from 'src/environments/environment';\r\nimport { Device } from '../_models/device/device';\r\nimport { DevicePlatform } from '../_models/device/device-platform';\r\nimport { TextResonse } from '../_types/text-response';\r\nimport { AccountService } from './account.service';\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\nexport class DeviceService {\r\n\r\n baseUrl = environment.apiUrl;\r\n\r\n private devicesSource: ReplaySubject = new ReplaySubject(1);\r\n public devices$ = this.devicesSource.asObservable().pipe(shareReplay());\r\n\r\n\r\n constructor(private httpClient: HttpClient, private accountService: AccountService) {\r\n // Ensure we are authenticated before we make an authenticated api call.\r\n this.accountService.currentUser$.subscribe(user => {\r\n if (!user) {\r\n this.devicesSource.next([]);\r\n return;\r\n }\r\n\r\n this.httpClient.get(this.baseUrl + 'device', {}).subscribe(data => {\r\n this.devicesSource.next(data);\r\n });\r\n });\r\n }\r\n\r\n createDevice(name: string, platform: DevicePlatform, emailAddress: string) {\r\n return this.httpClient.post(this.baseUrl + 'device/create', {name, platform, emailAddress}, TextResonse);\r\n }\r\n\r\n updateDevice(id: number, name: string, platform: DevicePlatform, emailAddress: string) {\r\n return this.httpClient.post(this.baseUrl + 'device/update', {id, name, platform, emailAddress}, TextResonse);\r\n }\r\n\r\n deleteDevice(id: number) {\r\n return this.httpClient.delete(this.baseUrl + 'device?deviceId=' + id);\r\n }\r\n\r\n getDevices() {\r\n return this.httpClient.get(this.baseUrl + 'device', {}).pipe(tap(data => {\r\n this.devicesSource.next(data);\r\n }));\r\n }\r\n\r\n sendTo(chapterIds: Array, deviceId: number) {\r\n return this.httpClient.post(this.baseUrl + 'device/send-to', {deviceId, chapterIds}, TextResonse);\r\n }\r\n\r\n sendSeriesTo(seriesId: number, deviceId: number) {\r\n return this.httpClient.post(this.baseUrl + 'device/send-series-to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AAO,KAAK/B,WAAWqB,KAAK,KAAKnB,QAAU,iBAAkB,CAAC6B,SAAAA,EAAUD,WAAAA,CAAU,EAAGR,CAAW,CAClG,CAEAU,aAAaC,EAAkBF,EAAgB,CAC7C,OAAO,KAAK/B,WAAWqB,KAAK,KAAKnB,QAAU,wBAAyB,CAAC6B,SAAAA,EAAUE,SAAAA,CAAQ,EAAGX,CAAW,CACvG,yCA9CWxB,GAAaoC,EAAAC,CAAA,EAAAD,EAAAE,CAAA,CAAA,CAAA,wBAAbtC,EAAauC,QAAbvC,EAAawC,UAAAC,WAFZ,MAAM,CAAA,EAEd,IAAOzC,EAAP0C,SAAO1C,CAAa,GAAA", "names": ["DeviceService", "constructor", "httpClient", "accountService", "baseUrl", "environment", "apiUrl", "devicesSource", "ReplaySubject", "devices$", "asObservable", "pipe", "shareReplay", "currentUser$", "subscribe", "user", "next", "get", "data", "createDevice", "name", "platform", "emailAddress", "post", "TextResonse", "updateDevice", "id", "deleteDevice", "delete", "getDevices", "tap", "sendTo", "chapterIds", "deviceId", "sendSeriesTo", "seriesId", "\u0275\u0275inject", "HttpClient", "AccountService", "factory", "\u0275fac", "providedIn", "_DeviceService"] }