opt-cc/static/src/app/services/war-service/war.service.ts

50 lines
1.1 KiB
TypeScript

import {Injectable} from "@angular/core";
import {Campaign, War} from "../../models/model-interfaces";
import {AppConfig} from "../../app.config";
import {HttpClient} from "../http-client";
@Injectable()
export class WarService {
campaigns: Campaign[];
constructor(private http: HttpClient,
private config: AppConfig) {
}
getAllCampaigns() {
return this.http.get(this.config.apiWarPath)
.map(res => res.json())
}
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())
}
}