Call API to get the tunnel flights
This commit is contained in:
@@ -106,7 +106,7 @@ export class NewTunnelFlightComponent implements OnInit {
|
|||||||
|
|
||||||
private updateTitle() {
|
private updateTitle() {
|
||||||
this.translateService.get("NewTunnelFlight_Title").subscribe(
|
this.translateService.get("NewTunnelFlight_Title").subscribe(
|
||||||
data => { this.serviceComm.UpdatedComponentTitle(data); }
|
data => { this.serviceComm.updatedComponentTitle(data); }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,4 +8,30 @@ export class TunnelFlightReq {
|
|||||||
public nbMinutes: number;
|
public nbMinutes: number;
|
||||||
public notes: string;
|
public notes: string;
|
||||||
public flightDate: string;
|
public flightDate: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TunnelFlightResp {
|
||||||
|
constructor(data: any) {
|
||||||
|
Object.assign(this, data);
|
||||||
|
this.flightDate = new Date(data.flightDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public id: number;
|
||||||
|
public tunnelId: number;
|
||||||
|
public nbMinutes: number;
|
||||||
|
public notes: string;
|
||||||
|
public flightDate: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TunnelFlight {
|
||||||
|
constructor(data: any) {
|
||||||
|
Object.assign(this, data);
|
||||||
|
this.flightDate = new Date(data.flightDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public id: number;
|
||||||
|
public tunnelId: number;
|
||||||
|
public nbMinutes: number;
|
||||||
|
public notes: string;
|
||||||
|
public flightDate: Date;
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,23 @@
|
|||||||
import { Injectable } from "@angular/core";
|
import { Injectable } from "@angular/core";
|
||||||
import { DatePipe } from "@angular/common";
|
import { DatePipe } from "@angular/common";
|
||||||
import { HttpClient } from "@angular/common/http";
|
import { HttpClient } from "@angular/common/http";
|
||||||
|
import { Observable } from "rxjs";
|
||||||
|
import { map } from "rxjs/operators";
|
||||||
|
|
||||||
import { TunnelFlightReq } from "../models/tunnel-flight";
|
import { TunnelFlightReq, TunnelFlightResp, TunnelFlight } from "../models/tunnel-flight";
|
||||||
|
|
||||||
import { BaseService } from "./base.service";
|
import { BaseService } from "./base.service";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TunnelFlightService extends BaseService {
|
export class TunnelFlightService extends BaseService {
|
||||||
constructor(private http: HttpClient,
|
constructor(private http: HttpClient, private datePipe: DatePipe) {
|
||||||
private datePipe: DatePipe) {
|
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public addFlight(selectedTunnel: number,
|
public addFlight(selectedTunnel: number,
|
||||||
flightDate: Date,
|
flightDate: Date,
|
||||||
nbMinutes: number,
|
nbMinutes: number,
|
||||||
comment: string)
|
comment: string) {
|
||||||
{
|
|
||||||
|
|
||||||
const bodyNewFlight: TunnelFlightReq = {
|
const bodyNewFlight: TunnelFlightReq = {
|
||||||
id: 0,
|
id: 0,
|
||||||
@@ -27,6 +27,19 @@ export class TunnelFlightService extends BaseService {
|
|||||||
nbMinutes: nbMinutes
|
nbMinutes: nbMinutes
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.http.post(`${this.apiUrl}/TunnelFlight`, bodyNewFlight, { headers: this.headers});
|
return this.http.post(`${this.apiUrl}/TunnelFlight`, bodyNewFlight, { headers: this.headers });
|
||||||
|
}
|
||||||
|
|
||||||
|
public getTunnelFlights(begin: Date, end: Date): Observable<Array<TunnelFlight>> {
|
||||||
|
let beginDate = this.datePipe.transform(begin, "yyyyMMdd");
|
||||||
|
let endDate = this.datePipe.transform(end, "yyyyMMdd");
|
||||||
|
|
||||||
|
return this.http.get<Array<TunnelFlightResp>>(`${this.apiUrl}/TunnelFlight/${beginDate}/${endDate}`, { headers: this.headers })
|
||||||
|
.pipe(
|
||||||
|
map(response => {
|
||||||
|
const stats = response.map(data => new TunnelFlightResp(data));
|
||||||
|
return stats;
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user