import {Injectable} from '@angular/core'; import {War} from '../../models/model-interfaces'; import {AppConfig} from '../../app.config'; import {HttpClient} from '../http-client'; @Injectable() export class WarService { constructor(private http: HttpClient, private config: AppConfig) { } getWar(warId: string) { return this.http.get(this.config.apiWarPath + '/' + warId) .map(res => res.json()); } submitWar(war: War, logFile?) { let body; if (logFile) { body = new FormData(); Object.keys(war).map((objectKey) => { if (war[objectKey] !== undefined) { body.append(objectKey, war[objectKey]); } }); body.append('log', logFile, logFile.name); } return this.http.post(this.config.apiWarPath, body) .map(res => res.json()); } deleteWar(id: string) { return this.http.delete(this.config.apiWarPath + '/' + id) .map(res => res.json()); } updateWar(war: War) { return this.http.patch(this.config.apiWarPath + '/' + war._id, war) .map(res => res.json()); } }