Correction sur la mise en cache des

données référentiel et leurs utilisation
sur la liste des sauts.
This commit is contained in:
Sébastien André
2021-05-28 17:19:12 +02:00
parent dba69b938e
commit ba99a0f047
14 changed files with 143 additions and 79 deletions
@@ -5,6 +5,10 @@ import { Observable } from "rxjs";
import { map } from "rxjs/operators";
import { JumpResp, JumpReq, Jump } from "../models/jump";
import { GearResp } from "../models/gear";
import { DropZoneResp } from "../models/dropzone";
import { AircraftResp } from "../models/aircraft";
import { JumpTypeResp } from "../models/jumpType";
import { DateService } from "./date.service";
import { BaseService } from "./base.service";
@@ -29,16 +33,7 @@ export class JumpService extends BaseService {
return this.http.get<Array<JumpResp>>(`${this.apiUrl}/Jump`,
{ headers: this.headers })
.pipe(map((response) => {
let details = response.map((data) =>
{
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;
return this.MapWithDataInCache(response);
}));
}
@@ -145,4 +140,27 @@ export class JumpService extends BaseService {
.subscribe();
}
}
private MapWithDataInCache(apiResp: Array<JumpResp>) : Array<Jump> {
let allDropzones: Array<DropZoneResp>;
this.dropzoneService.getFromCache().subscribe(data => { allDropzones = data; });
let allAircrafts: Array<AircraftResp>;
this.aircraftService.getFromCache().subscribe(data => { allAircrafts = data; });
let allJumpType: Array<JumpTypeResp>;
this.jumpTypeService.getFromCache().subscribe(data => { allJumpType = data; });
let allGears: Array<GearResp>;
this.gearService.getFromCache().subscribe(data => { allGears = data; });
return apiResp.map((data) =>
{
let tmp = new Jump(data);
tmp.dropZone = allDropzones.find(d => d.id == data.dropZoneId);
tmp.aircraft = allAircrafts.find(d => d.id == data.aircraftId);
tmp.jumpType = allJumpType.find(d => d.id == data.jumpTypeId);
tmp.gear = allGears.find(d => d.id == data.gearId);
return tmp;
});
}
}