This commit is contained in:
Sébastien ANDRE
2023-06-15 10:02:14 +02:00
parent 174ad39799
commit 146bbe89c3
6 changed files with 71 additions and 42 deletions

View File

@@ -0,0 +1,33 @@
import { Injectable } from "@angular/core";
import { DatePipe } from "@angular/common";
import { HttpClient } from "@angular/common/http";
import { TunnelFlightReq } from "../models/tunnel-flight";
import { BaseService } from "./base.service";
@Injectable()
export class TunnelFlightService extends BaseService {
private datePipe: DatePipe;
constructor(private http: HttpClient) {
super();
}
public addFlight(selectedTunnel: number,
flightDate: Date,
nbMinutes: number,
comment: string)
{
const bodyNewFlight: TunnelFlightReq = {
id: 0,
tunnelId: selectedTunnel,
flightDate: this.datePipe.transform(flightDate, "yyyy-MM-dd"),
notes: comment,
nbMinutes: nbMinutes
};
return this.http.post(`${this.apiUrl}/TunnelFlight`, bodyNewFlight, { headers: this.headers});
}
}

View File

@@ -4,14 +4,13 @@ import { HttpClient } from "@angular/common/http";
import { Observable } from "rxjs";
import { map } from "rxjs/operators";
import { TunnelResp, TunnelReq } from "../models/tunnel";
import { TunnelResp } from "../models/tunnel";
import { BaseService } from "./base.service";
import { CacheApiKey } from "../models/cache-api-key.enum";
@Injectable()
export class TunnelService extends BaseService {
private datePipe: DatePipe;
constructor(private http: HttpClient) {
super();
@@ -22,23 +21,6 @@ export class TunnelService extends BaseService {
return this.serviceCacheApi.get<Array<TunnelResp>>(CacheApiKey.Gear, callToApi);
}
public AddFlight(selectedTunnel: number,
flightDate: Date,
nbMinutes: number,
comment: string)
{
const bodyNewFlight: TunnelReq = {
id: 0,
tunnelId: selectedTunnel,
flightDate: this.datePipe.transform(flightDate, "yyyy-MM-dd"),
comment: comment,
nbMinutes: nbMinutes
};
return this.http.post(`${this.apiUrl}/Tunnel`, bodyNewFlight, { headers: this.headers});
}
public getById(id: number) : Observable<TunnelResp> {
return this.serviceCacheApi.getByKey<Array<TunnelResp>>(CacheApiKey.Tunnel)
.pipe(map(data => {