{ "version": 3, "sources": ["src/app/services/floorplan.service.ts"], "sourcesContent": ["import { Injectable } from '@angular/core';\r\nimport { HttpClient, HttpErrorResponse } from '@angular/common/http';\r\nimport { BehaviorSubject, Observable, of, Subject, throwError } from 'rxjs';\r\nimport { Router } from '@angular/router';\r\nimport { catchError, tap } from 'rxjs/operators';\r\nimport { Floorplan } from './../models/floorplan';\r\nimport { environment } from 'src/environments/environment';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class FloorplanService {\r\n floorPlans!: Floorplan[];\r\n floorPlansOnDisplay!: Floorplan[];\r\n\r\n constructor(private readonly http: HttpClient, private router: Router) {}\r\n\r\n getFloorplans(): Observable {\r\n return this.http\r\n .get(`${environment.API.BASE_URL}/${environment.ordered}`)\r\n .pipe(\r\n tap((floorPlans: Floorplan[]) => {\r\n this.floorPlans = floorPlans;\r\n this.floorPlansOnDisplay = floorPlans.filter(\r\n (floorPlan: Floorplan) => floorPlan.onDisplay === true\r\n );\r\n }),\r\n // Now using the unified handleError with a fallback of []\r\n catchError(this.handleError('getFloorplans', []))\r\n );\r\n }\r\n\r\n //*********************************************************************************/\r\n //************************return ***************************************/\r\n //*********************************************************************************/\r\n //service that returns a observable Floorplan when passing in a floorplanId paramater\r\n //REVISED\r\n getFloorplan(floorplanId: number): Observable {\r\n // Construct the full URL used for the request\r\n const attemptedUrl = `${environment.API.BASE_URL}/${environment.fp}/${floorplanId}`;\r\n\r\n return this.http\r\n .get(attemptedUrl)\r\n .pipe(\r\n catchError(\r\n this.handleError(\r\n 'getFloorplan',\r\n undefined,\r\n floorplanId,\r\n attemptedUrl\r\n )\r\n )\r\n );\r\n }\r\n\r\n //*********************************************************************************/\r\n //************************Error Handling ******************************************/\r\n //*********************************************************************************/\r\n /**\r\n * Unified error handler covering getfloorplans and getfloorplan that can:\r\n * - Return a fallback for 404 on \"getFloorplans\"\r\n * - Navigate to pagenotfound for 404 on \"getFloorplan\"\r\n * - Otherwise, log and throw the error\r\n */\r\n private handleError(\r\n operation = 'operation',\r\n fallbackValue?: T,\r\n floorplanId?: number,\r\n attemptedUrl?: string\r\n ) {\r\n return (error: HttpErrorResponse): Observable => {\r\n console.error(`Http ERROR during ${operation}`, error);\r\n if (error.status === 404) {\r\n // If it was a single floorplan lookup\r\n if (operation === 'getFloorplan' && floorplanId != null) {\r\n console.error(`Floorplan with ID ${floorplanId} not found. (404)`);\r\n this.router.navigate(['/pagenotfound'], {\r\n state: {\r\n message: `Floorplan with ID ${floorplanId} does not exist.`,\r\n triedUrl: attemptedUrl ?? 'Unknown URL',\r\n },\r\n });\r\n // Throw an error so the observable stream emits an error\r\n return throwError(() => new Error('Floorplan not found (404)'));\r\n } else {\r\n // For a 404 on \"getFloorplans\" or another scenario, you might want to:\r\n // - Return an empty array\r\n // - Navigate to a not-found page\r\n // - Or handle differently as needed\r\n console.error(`Resource not found during ${operation}. (404)`);\r\n return of(fallbackValue as T);\r\n }\r\n }\r\n\r\n // For non-404 errors, log and rethrow\r\n console.error('An error occurred:', error.message);\r\n return throwError(() => new Error(error.message));\r\n };\r\n }\r\n}\r\n"], "mappings": "mIAWA,IAAaA,GAAgB,IAAA,CAAvB,MAAOA,CAAgB,CAIEC,KAA0BC,OAHvDC,WACAC,oBAEAC,YAA6BJ,EAA0BC,EAAc,CAAxC,KAAAD,KAAAA,EAA0B,KAAAC,OAAAA,CAAiB,CAExEI,eAAa,CACX,OAAO,KAAKL,KACTM,IAAiB,GAAGC,EAAYC,IAAIC,QAAQ,IAAIF,EAAYG,OAAO,EAAE,EACrEC,KACCC,EAAKV,GAA2B,CAC9B,KAAKA,WAAaA,EAClB,KAAKC,oBAAsBD,EAAWW,OACnCC,GAAyBA,EAAUC,YAAc,EAAI,CAE1D,CAAC,EAEDC,EAAW,KAAKC,YAAyB,gBAAiB,CAAA,CAAE,CAAC,CAAC,CAEpE,CAOAC,aAAaC,EAAmB,CAE9B,IAAMC,EAAe,GAAGb,EAAYC,IAAIC,QAAQ,IAAIF,EAAYc,EAAE,IAAIF,CAAW,GAEjF,OAAO,KAAKnB,KACTM,IAAec,CAAY,EAC3BT,KACCK,EACE,KAAKC,YACH,eACAK,OACAH,EACAC,CAAY,CACb,CACF,CAEP,CAWQH,YACNM,EAAY,YACZC,EACAL,EACAC,EAAqB,CAErB,OAAQK,IACNC,QAAQD,MAAM,qBAAqBF,CAAS,GAAIE,CAAK,EACjDA,EAAME,SAAW,IAEfJ,IAAc,gBAAkBJ,GAAe,MACjDO,QAAQD,MAAM,qBAAqBN,CAAW,mBAAmB,EACjE,KAAKlB,OAAO2B,SAAS,CAAC,eAAe,EAAG,CACtCC,MAAO,CACLC,QAAS,qBAAqBX,CAAW,mBACzCY,SAAUX,GAAgB,eAE7B,EAEMY,EAAW,IAAM,IAAIC,MAAM,2BAA2B,CAAC,IAM9DP,QAAQD,MAAM,6BAA6BF,CAAS,SAAS,EACtDW,EAAGV,CAAkB,IAKhCE,QAAQD,MAAM,qBAAsBA,EAAMK,OAAO,EAC1CE,EAAW,IAAM,IAAIC,MAAMR,EAAMK,OAAO,CAAC,GAEpD,4CAvFW/B,GAAgBoC,EAAAC,CAAA,EAAAD,EAAAE,CAAA,CAAA,CAAA,6BAAhBtC,EAAgBuC,QAAhBvC,EAAgBwC,UAAAC,WAFf,MAAM,CAAA,SAEPzC,CAAgB,GAAA", "names": ["FloorplanService", "http", "router", "floorPlans", "floorPlansOnDisplay", "constructor", "getFloorplans", "get", "environment", "API", "BASE_URL", "ordered", "pipe", "tap", "filter", "floorPlan", "onDisplay", "catchError", "handleError", "getFloorplan", "floorplanId", "attemptedUrl", "fp", "undefined", "operation", "fallbackValue", "error", "console", "status", "navigate", "state", "message", "triedUrl", "throwError", "Error", "of", "\u0275\u0275inject", "HttpClient", "Router", "factory", "\u0275fac", "providedIn"] }