Call API to get the tunnel flights
This commit is contained in:
@@ -106,7 +106,7 @@ export class NewTunnelFlightComponent implements OnInit {
|
||||
|
||||
private updateTitle() {
|
||||
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 notes: 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 { DatePipe } from "@angular/common";
|
||||
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";
|
||||
|
||||
@Injectable()
|
||||
export class TunnelFlightService extends BaseService {
|
||||
constructor(private http: HttpClient,
|
||||
private datePipe: DatePipe) {
|
||||
constructor(private http: HttpClient, private datePipe: DatePipe) {
|
||||
super();
|
||||
}
|
||||
|
||||
public addFlight(selectedTunnel: number,
|
||||
flightDate: Date,
|
||||
nbMinutes: number,
|
||||
comment: string)
|
||||
{
|
||||
comment: string) {
|
||||
|
||||
const bodyNewFlight: TunnelFlightReq = {
|
||||
id: 0,
|
||||
@@ -27,6 +27,19 @@ export class TunnelFlightService extends BaseService {
|
||||
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