New service and model for the tunnel flights

This commit is contained in:
Sébastien ANDRE
2023-05-05 17:59:11 +02:00
parent 487b287924
commit e41e7a1fe4
6 changed files with 163 additions and 53 deletions
@@ -20,37 +20,37 @@ import { GearService } from "./gear.service";
@Injectable()
export class JumpService extends BaseService {
private callsToAdd : Array<Observable<any>>;
private callsToAdd: Array<Observable<any>>;
constructor(private http: HttpClient,
private dateService: DateService,
private datePipe: DatePipe,
private dropzoneService: DropzoneService,
private aircraftService: AircraftService,
private jumpTypeService: JumpTypeService,
private gearService: GearService) {
constructor(private http: HttpClient,
private dateService: DateService,
private datePipe: DatePipe,
private dropzoneService: DropzoneService,
private aircraftService: AircraftService,
private jumpTypeService: JumpTypeService,
private gearService: GearService) {
super();
}
public GetListOfJumps(): Observable<Array<Jump>> {
return this.http.get<Array<JumpResp>>(`${this.apiUrl}/Jump`,
{ headers: this.headers })
.pipe(map((response) => {
return this.MapWithDataInCache(response);
}));
return this.http.get<Array<JumpResp>>(`${this.apiUrl}/Jump`,
{ headers: this.headers })
.pipe(map((response) => {
return this.MapWithDataInCache(response);
}));
}
public GetJumps(beginIndex: number, endIndex: number): Observable<JumpList> {
return this.http.get<JumpListResp>(`${this.apiUrl}/Jump/${beginIndex}/${endIndex}`,
{ headers: this.headers })
.pipe(map((response) => {
let result: JumpList = {
rows : this.MapWithDataInCache(response.rows),
count : response.count
};
return this.http.get<JumpListResp>(`${this.apiUrl}/Jump/${beginIndex}/${endIndex}`,
{ headers: this.headers })
.pipe(map((response) => {
let result: JumpList = {
rows: this.MapWithDataInCache(response.rows),
count: response.count
};
return new JumpList(result);
}));
return new JumpList(result);
}));
}
public AddListOfJump(selectedJumpType: number,
@@ -64,8 +64,7 @@ export class JumpService extends BaseService {
defaultDeployAltitude: number,
countOfJumps: number,
notes: string,
isSpecial: boolean): Observable<any[]>
{
isSpecial: boolean): Observable<any[]> {
this.callsToAdd = new Array<Observable<any>>();
const diffInDays = this.dateService.DiffBetweenDates(beginDate, endDate) + 1;
const countOfJumpsPerDay = Math.trunc(countOfJumps / diffInDays);
@@ -105,25 +104,25 @@ export class JumpService extends BaseService {
public DeleteJump(item: Jump) {
this.http.delete(`${this.apiUrl}/Jump/${item.id}`,
{ headers: this.headers, })
.subscribe();
{ headers: this.headers, })
.subscribe();
}
public UpdateJump(id: number,
isSpecial: boolean,
withCutaway: boolean,
notes: string) {
isSpecial: boolean,
withCutaway: boolean,
notes: string) {
const jumpData = {
id: id,
isSpecial: isSpecial,
withCutaway: withCutaway,
notes: notes
};
};
const bodyUpdatedJump = new JumpReq(jumpData);
return this.http.put(`${this.apiUrl}/Jump/${id}`,
bodyUpdatedJump,
{ headers: this.headers, });
bodyUpdatedJump,
{ headers: this.headers, });
}
private AddJumps(selectedJumpType: number,
@@ -136,8 +135,7 @@ export class JumpService extends BaseService {
defaultDeployAltitude: number,
countOfJumps: number,
notes: string,
isSpecial: boolean)
{
isSpecial: boolean) {
for (let i = 0; i < countOfJumps; i++) {
const bodyNewjump: JumpReq = {
jumpTypeId: selectedJumpType,
@@ -153,15 +151,13 @@ export class JumpService extends BaseService {
isSpecial: isSpecial
};
let call = this.http.post(`${this.apiUrl}/Jump`,
bodyNewjump,
{ headers: this.headers });
let call = this.http.post(`${this.apiUrl}/Jump`, bodyNewjump, { headers: this.headers });
this.callsToAdd.push(call);
}
}
private MapWithDataInCache(apiResp: Array<JumpResp>) : Array<Jump> {
private MapWithDataInCache(apiResp: Array<JumpResp>): Array<Jump> {
let allDropzones: Array<DropZoneResp>;
this.dropzoneService.getFromCache().subscribe(data => { allDropzones = data; });
let allAircrafts: Array<AircraftResp>;
@@ -171,8 +167,7 @@ export class JumpService extends BaseService {
let allGears: Array<GearResp>;
this.gearService.getFromCache().subscribe(data => { allGears = data; });
return apiResp.map((data) =>
{
return apiResp.map((data) => {
let tmp = new Jump(data);
tmp.dropZone = allDropzones.find(d => d.id == data.dropZoneId);