-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…up, layout improvements - Finish date and vehicle selection - Auto-select vehicle when initiated from vehicles list - Improve vehicle card and container layout
- Loading branch information
1 parent
713cfe7
commit 020e229
Showing
10 changed files
with
328 additions
and
125 deletions.
There are no files selected for viewing
58 changes: 54 additions & 4 deletions
58
projects/MyCar/src/app/appointment-scheduler/appointment-scheduler-http.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,81 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { HttpClient, HttpHeaders } from '@angular/common/http'; | ||
import { JwtHelperService } from '@auth0/angular-jwt'; | ||
import { sortBy } from 'lodash-es'; | ||
import { Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
import { environment } from '../../environments/environment'; | ||
import { AuthTokenService } from '../auth/auth-token.service'; | ||
import { AppointmentScheduleResponse } from './appointment-scheduler.models'; | ||
import { DynamicFormData } from './appointment-scheduler.component'; | ||
|
||
@Injectable() | ||
export class AppointmentSchedulerHttpService { | ||
|
||
private static fuelEconomyApiMapper(dto): DynamicFormData[] { | ||
return dto.menuItem.map(item => { | ||
return { | ||
formValue: item.value, | ||
viewValue: item.text | ||
} as DynamicFormData | ||
}); | ||
} | ||
|
||
private static fuelEconomyApiHttpOptions = { headers: new HttpHeaders({'Accept': 'application/json'}) }; | ||
|
||
constructor( | ||
private authTokenService: AuthTokenService, | ||
private httpClient: HttpClient, | ||
private jwtHelperService: JwtHelperService) { | ||
} | ||
|
||
public getAvaliableDates(): Observable<any> { | ||
public getScheduleViewModel(): Observable<AppointmentScheduleResponse> { | ||
const token = this.jwtHelperService.decodeToken(this.authTokenService.authToken); | ||
|
||
return this.httpClient.get<any>(`${environment.apiBaseUrl}/${token.conos[0]}/schedule`, environment.httpOptions).pipe( | ||
map(dto => { | ||
dto.daysAvailable = dto.daysAvailable.map(d => new Date(d * 1000).toISOString()); | ||
dto.daysAvailable = dto.daysAvailable.map(d => new Date(d * 1000)); | ||
|
||
const problemDescriptions = []; | ||
for (let p of dto.problemDescriptions) { | ||
for (let viewValue of p.Desc) { | ||
problemDescriptions.push({ | ||
formValue: p.category, | ||
viewValue: viewValue | ||
} as DynamicFormData); | ||
} | ||
} | ||
dto.problemDescriptions = problemDescriptions; | ||
|
||
return dto as AppointmentScheduleResponse; | ||
}) | ||
); | ||
} | ||
|
||
public getVehicleYears(): Observable<DynamicFormData[]> { | ||
return this.httpClient.get<any>( | ||
`https://www.fueleconomy.gov/ws/rest/vehicle/menu/year`, | ||
AppointmentSchedulerHttpService.fuelEconomyApiHttpOptions) | ||
.pipe( | ||
map(AppointmentSchedulerHttpService.fuelEconomyApiMapper) | ||
); | ||
} | ||
|
||
public getVehicleMakesByYear(year: string): Observable<DynamicFormData[]> { | ||
return this.httpClient.get<any>( | ||
`https://www.fueleconomy.gov/ws/rest/vehicle/menu/make?year=${year}`, | ||
AppointmentSchedulerHttpService.fuelEconomyApiHttpOptions) | ||
.pipe( | ||
map(AppointmentSchedulerHttpService.fuelEconomyApiMapper) | ||
); | ||
} | ||
|
||
public getVehicleModelsByYearAndMake(year: string, make: string): Observable<DynamicFormData[]> { | ||
return this.httpClient.get<any>( | ||
`https://www.fueleconomy.gov/ws/rest/vehicle/menu/model?year=${year}&make=${make}`, | ||
AppointmentSchedulerHttpService.fuelEconomyApiHttpOptions) | ||
.pipe( | ||
map(AppointmentSchedulerHttpService.fuelEconomyApiMapper) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.