Add an equipement when you add and update a gear
This commit is contained in:
@@ -10,46 +10,59 @@ import { CacheApiKey } from "../models/cache-api-key.enum";
|
||||
|
||||
@Injectable()
|
||||
export class GearService extends BaseService {
|
||||
constructor(private http: HttpClient) {
|
||||
super();
|
||||
}
|
||||
constructor(private http: HttpClient) {
|
||||
super();
|
||||
}
|
||||
|
||||
public getListOfGears(): Observable<Array<GearResp>> {
|
||||
let callToApi = this.http.get<Array<GearResp>>(`${this.apiUrl}/Gear`, { headers: this.headers });
|
||||
return this.serviceCacheApi.get<Array<GearResp>>(CacheApiKey.Gear, callToApi);
|
||||
}
|
||||
public getListOfGears(): Observable<Array<GearResp>> {
|
||||
let callToApi = this.http.get<Array<GearResp>>(`${this.apiUrl}/Gear`, {
|
||||
headers: this.headers,
|
||||
});
|
||||
return this.serviceCacheApi.get<Array<GearResp>>(
|
||||
CacheApiKey.Gear,
|
||||
callToApi,
|
||||
);
|
||||
}
|
||||
|
||||
public addGear(name: string,
|
||||
manufacturer: string,
|
||||
minSize: number,
|
||||
maxSize: number,
|
||||
aad: string,
|
||||
mainCanopy: string,
|
||||
reserveCanopy: string)
|
||||
{
|
||||
const bodyNewGear: GearReq = {
|
||||
id: 0,
|
||||
name: name,
|
||||
manufacturer: manufacturer,
|
||||
minSize: minSize,
|
||||
maxSize: maxSize,
|
||||
aad: aad,
|
||||
mainCanopy: mainCanopy,
|
||||
reserveCanopy: reserveCanopy
|
||||
};
|
||||
public addGear(
|
||||
name: string,
|
||||
manufacturer: string,
|
||||
minSize: number,
|
||||
maxSize: number,
|
||||
aad: string,
|
||||
mainCanopy: string,
|
||||
reserveCanopy: string,
|
||||
equipment: string,
|
||||
) {
|
||||
const bodyNewGear: GearReq = {
|
||||
id: 0,
|
||||
name: name,
|
||||
manufacturer: manufacturer,
|
||||
minSize: minSize,
|
||||
maxSize: maxSize,
|
||||
aad: aad,
|
||||
mainCanopy: mainCanopy,
|
||||
reserveCanopy: reserveCanopy,
|
||||
equipment: equipment,
|
||||
};
|
||||
|
||||
this.serviceCacheApi.delete(CacheApiKey.Gear);
|
||||
return this.http.post(`${this.apiUrl}/Gear`, bodyNewGear, { headers: this.headers});
|
||||
}
|
||||
this.serviceCacheApi.delete(CacheApiKey.Gear);
|
||||
return this.http.post(`${this.apiUrl}/Gear`, bodyNewGear, {
|
||||
headers: this.headers,
|
||||
});
|
||||
}
|
||||
|
||||
public getById(id: number) : Observable<GearResp> {
|
||||
return this.serviceCacheApi.getByKey<Array<GearResp>>(CacheApiKey.Gear)
|
||||
.pipe(map(data => {
|
||||
return data.find(f => f.id === id);
|
||||
}));
|
||||
}
|
||||
public getById(id: number): Observable<GearResp> {
|
||||
return this.serviceCacheApi
|
||||
.getByKey<Array<GearResp>>(CacheApiKey.Gear)
|
||||
.pipe(
|
||||
map((data) => {
|
||||
return data.find((f) => f.id === id);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public getFromCache(): Observable<Array<GearResp>> {
|
||||
return this.serviceCacheApi.getByKey<Array<GearResp>>(CacheApiKey.Gear);
|
||||
}
|
||||
public getFromCache(): Observable<Array<GearResp>> {
|
||||
return this.serviceCacheApi.getByKey<Array<GearResp>>(CacheApiKey.Gear);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user