Bug fix +

Meilleur chargement du cache après login
This commit is contained in:
Sébastien André
2021-05-03 16:13:55 +02:00
parent f9930a10e6
commit 784bdea786
9 changed files with 107 additions and 81 deletions

View File

@@ -4,7 +4,7 @@ import { DatePipe } from '@angular/common';
import { Observable } from "rxjs";
import { map } from "rxjs/operators";
import { JumpResp, JumpReq } from "../models/jump";
import { JumpResp, JumpReq, Jump } from "../models/jump";
import { DateService } from "./date.service";
import { BaseService } from "./base.service";
@@ -21,27 +21,25 @@ export class JumpService extends BaseService {
private dropzoneService: DropzoneService,
private aircraftService: AircraftService,
private jumpTypeService: JumpTypeService,
private gearService: GearService,) {
private gearService: GearService) {
super();
}
public GetListOfJumps(): Observable<Array<JumpResp>> {
public GetListOfJumps(): Observable<Array<Jump>> {
return this.http.get<Array<JumpResp>>(`${this.apiUrl}/Jump`,
{ headers: this.headers })
.pipe(
map((response) => {
.pipe(map((response) => {
let details = response.map((data) =>
{
let t = new JumpResp(data);
this.dropzoneService.getById(t.dropZoneId).subscribe((d)=> t.dropZone = d );
this.aircraftService.getById(t.aircraftId).subscribe((d)=> t.aircraft = d );
this.jumpTypeService.getById(t.jumpTypeId).subscribe((d)=> t.jumpType = d );
this.gearService.getById(t.gearId).subscribe((d)=> t.gear = d );
return t;
});
{
let tmp = new Jump(data);
this.dropzoneService.getById(data.dropZoneId).subscribe((d)=> tmp.dropZone = d );
this.aircraftService.getById(data.aircraftId).subscribe((d)=> tmp.aircraft = d );
this.jumpTypeService.getById(data.jumpTypeId).subscribe((d)=> tmp.jumpType = d );
this.gearService.getById(data.gearId).subscribe((d)=> tmp.gear = d );
return tmp;
});
return details;
})
);
}));
}
public AddListOfJump(selectedJumpType: number,
@@ -91,10 +89,10 @@ export class JumpService extends BaseService {
isSpecial);
}
public DeleteJump(item: JumpResp) {
public DeleteJump(item: Jump) {
this.http.delete(`${this.apiUrl}/Jump/${item.id}`,
{ headers: this.headers, })
.subscribe((data) => console.log(data));
.subscribe();
}
public UpdateJump(id: number,
@@ -144,7 +142,7 @@ export class JumpService extends BaseService {
this.http.post(`${this.apiUrl}/Jump`,
bodyNewjump,
{ headers: this.headers, })
.subscribe((data) => console.log(data));
.subscribe();
}
}
}

View File

@@ -5,15 +5,24 @@ import { map } from 'rxjs/operators';
import { StatsByDzResp, StatsByAircraftResp, StatsByJumpTypeResp,
StatsByGearResp, StatsByYearResp, StatsForLastMonthResp,
StatsForLastYearResp, SimpleSummary } from '../models/stats';
StatsForLastYearResp, SimpleSummary, SimpleSummaryResp } from '../models/stats';
import { BaseService } from './base.service';
import { DropzoneService } from "./dropzone.service";
import { AircraftService } from "./aircraft.service";
import { JumpTypeService } from "./jump-type.service";
import { GearService } from "./gear.service";
import { CacheApiKey } from '../models/cache-api-key.enum';
import { Jump } from '../models/jump';
@Injectable()
export class StatsService extends BaseService {
constructor(private http: HttpClient) {
constructor(private http: HttpClient,
private dropzoneService: DropzoneService,
private aircraftService: AircraftService,
private jumpTypeService: JumpTypeService,
private gearService: GearService) {
super();
}
@@ -29,10 +38,16 @@ export class StatsService extends BaseService {
}
public getSimpleSummary(): Observable<SimpleSummary> {
let callToApi = this.http.get<Array<SimpleSummary>>(`${this.apiUrl}/Stats/Simple`, { headers: this.headers })
.pipe(
map(response => {
const stats = new SimpleSummary(response);
let callToApi = this.http.get<SimpleSummaryResp>(`${this.apiUrl}/Stats/Simple`, { headers: this.headers })
.pipe(map(response => {
let tmp = new Jump(response.lastJump);
this.dropzoneService.getById(response.lastJump.dropZoneId).subscribe((d)=> tmp.dropZone = d );
this.aircraftService.getById(response.lastJump.aircraftId).subscribe((d)=> tmp.aircraft = d );
this.jumpTypeService.getById(response.lastJump.jumpTypeId).subscribe((d)=> tmp.jumpType = d );
this.gearService.getById(response.lastJump.gearId).subscribe((d)=> tmp.gear = d );
let stats = new SimpleSummary(response);
stats.lastJump = tmp;
return stats;
})
);