diff --git a/static/src/app/services/army-management/decoration.service.ts b/static/src/app/services/army-management/decoration.service.ts index e4f1905..3ca6675 100644 --- a/static/src/app/services/army-management/decoration.service.ts +++ b/static/src/app/services/army-management/decoration.service.ts @@ -1,10 +1,9 @@ import {Injectable} from '@angular/core'; import {Decoration} from '../../models/model-interfaces'; -import {RequestMethod, RequestOptions} from '@angular/http'; import {Observable} from 'rxjs/Observable'; import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; import {AppConfig} from '../../app.config'; -import {HttpGateway} from '../http-gateway'; +import {HttpGateway, HttpMethod} from '../http-gateway'; import {HttpParams} from '@angular/common/http'; @Injectable() @@ -44,16 +43,16 @@ export class DecorationService { */ submitDecoration(decoration: Decoration, imageFile?) { let requestUrl = this.config.apiDecorationPath; - let requestMethod: RequestMethod; + let requestMethod: HttpMethod; let accessType; let body; if (decoration._id) { requestUrl += decoration._id; - requestMethod = RequestMethod.Patch; + requestMethod = 'PATCH'; accessType = EDIT; } else { - requestMethod = RequestMethod.Post; + requestMethod = 'POST'; accessType = ADD; } @@ -69,12 +68,7 @@ export class DecorationService { body = decoration; } - const options = new RequestOptions({ - body: body, - method: requestMethod, - }); - - return this.httpGateway.request(requestUrl, options) + return this.httpGateway.request(requestUrl, body, requestMethod) .do(savedDecoration => { const action = {type: accessType, data: savedDecoration}; this.decorationStore.dispatch(action); diff --git a/static/src/app/services/army-management/rank.service.ts b/static/src/app/services/army-management/rank.service.ts index d6d2cf7..bce50d1 100644 --- a/static/src/app/services/army-management/rank.service.ts +++ b/static/src/app/services/army-management/rank.service.ts @@ -1,10 +1,9 @@ import {Injectable} from '@angular/core'; import {Rank} from '../../models/model-interfaces'; -import {RequestMethod, RequestOptions} from '@angular/http'; import {Observable} from 'rxjs/Observable'; import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; import {AppConfig} from '../../app.config'; -import {HttpGateway} from '../http-gateway'; +import {HttpGateway, HttpMethod} from '../http-gateway'; import {HttpParams} from '@angular/common/http'; @Injectable() @@ -44,16 +43,16 @@ export class RankService { */ submitRank(rank: Rank, imageFile?): Observable { let requestUrl = this.config.apiRankPath; - let requestMethod: RequestMethod; + let requestMethod: HttpMethod; let accessType; let body; if (rank._id) { requestUrl += rank._id; - requestMethod = RequestMethod.Patch; + requestMethod = 'PATCH'; accessType = EDIT; } else { - requestMethod = RequestMethod.Post; + requestMethod = 'POST'; accessType = ADD; } @@ -70,12 +69,7 @@ export class RankService { body = rank; } - const options = new RequestOptions({ - body: body, - method: requestMethod - }); - - return this.httpGateway.request(requestUrl, options) + return this.httpGateway.request(requestUrl, body, requestMethod) .do(savedRank => { const action = {type: accessType, data: savedRank}; // leave some time to save image file before accessing it through list view diff --git a/static/src/app/services/army-management/squad.service.ts b/static/src/app/services/army-management/squad.service.ts index 18c7d7a..cee269a 100644 --- a/static/src/app/services/army-management/squad.service.ts +++ b/static/src/app/services/army-management/squad.service.ts @@ -1,10 +1,9 @@ import {Injectable} from '@angular/core'; import {Squad} from '../../models/model-interfaces'; -import {RequestMethod, RequestOptions} from '@angular/http'; import {Observable} from 'rxjs/Observable'; import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; import {AppConfig} from '../../app.config'; -import {HttpGateway} from '../http-gateway'; +import {HttpGateway, HttpMethod} from '../http-gateway'; import {HttpParams} from '@angular/common/http'; @Injectable() @@ -42,16 +41,16 @@ export class SquadService { */ submitSquad(squad: Squad, imageFile?): Observable { let requestUrl = this.config.apiSquadPath; - let requestMethod: RequestMethod; + let requestMethod: HttpMethod; let accessType; let body; if (squad._id) { requestUrl += squad._id; - requestMethod = RequestMethod.Patch; + requestMethod = 'PATCH'; accessType = EDIT; } else { - requestMethod = RequestMethod.Post; + requestMethod = 'POST'; accessType = ADD; } @@ -67,12 +66,7 @@ export class SquadService { body = squad; } - const options = new RequestOptions({ - body: body, - method: requestMethod - }); - - return this.httpGateway.request(requestUrl, options) + return this.httpGateway.request(requestUrl, body, requestMethod) .do(savedSquad => { const action = {type: accessType, data: savedSquad}; this.squadStore.dispatch(action); diff --git a/static/src/app/services/http-gateway.ts b/static/src/app/services/http-gateway.ts index ee3779e..26ce12f 100644 --- a/static/src/app/services/http-gateway.ts +++ b/static/src/app/services/http-gateway.ts @@ -1,10 +1,11 @@ import {Injectable} from '@angular/core'; -import {RequestMethod} from '@angular/http'; import {Router} from '@angular/router'; import {CookieService} from 'ngx-cookie-service'; import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http'; import {Observable} from 'rxjs'; +export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' + @Injectable() export class HttpGateway { @@ -62,12 +63,16 @@ export class HttpGateway { return this.http.delete(url, this.createAuthorizationHeader()); } - request(requestUrl, options): Observable { - if (options.method === RequestMethod.Post) { - return this.post(requestUrl, options.body); - } - if (options.method === RequestMethod.Patch) { - return this.patch(requestUrl, options.body); + request(requestUrl, body, method: HttpMethod): Observable { + switch (method) { + case 'GET': + return this.get(requestUrl); + case 'POST': + return this.post(requestUrl, body); + case 'PUT': + return this.put(requestUrl, body); + case 'PATCH': + return this.patch(requestUrl, body); } } } diff --git a/static/src/app/services/logs/campaign.service.ts b/static/src/app/services/logs/campaign.service.ts index 04ead21..7c08ad8 100644 --- a/static/src/app/services/logs/campaign.service.ts +++ b/static/src/app/services/logs/campaign.service.ts @@ -3,8 +3,7 @@ import {Campaign} from '../../models/model-interfaces'; import {AppConfig} from '../../app.config'; import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; import {Observable} from 'rxjs'; -import {RequestMethod, RequestOptions} from '@angular/http'; -import {HttpGateway} from '../http-gateway'; +import {HttpGateway, HttpMethod} from '../http-gateway'; @Injectable() export class CampaignService { @@ -33,25 +32,20 @@ export class CampaignService { submitCampaign(campaign: Campaign) { let requestUrl: string; - let requestMethod: RequestMethod; + let requestMethod: HttpMethod; let accessType; if (campaign._id) { requestUrl = this.config.apiCampaignPath + '/' + campaign._id; - requestMethod = RequestMethod.Patch; + requestMethod = 'PATCH'; accessType = EDIT; } else { requestUrl = this.config.apiCampaignPath; - requestMethod = RequestMethod.Post; + requestMethod = 'POST'; accessType = ADD; } - const options = new RequestOptions({ - body: campaign, - method: requestMethod - }); - - return this.httpGateway.request(requestUrl, options) + return this.httpGateway.request(requestUrl, campaign, requestMethod) .do(savedCampaign => { const action = {type: accessType, data: savedCampaign}; this.campaignStore.dispatch(action); diff --git a/static/src/app/services/logs/logs.service.ts b/static/src/app/services/logs/logs.service.ts index 317779b..cfda5c2 100644 --- a/static/src/app/services/logs/logs.service.ts +++ b/static/src/app/services/logs/logs.service.ts @@ -39,7 +39,7 @@ export class LogsService { params.append('fraction', fraction); params.append('stabilized', stabilizedOnly ? 'true' : ''); params.append('revive', reviveOnly ? 'true' : ''); - return this.httpGateway.get(this.config .apiLogsPath + '/' + warId + '/revive', params); + return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/revive', params); } getKillLogs(warId: string, shooterName = '', targetName = '', fraction = '', friendlyFireOnly = false, notFriendlyFireOnly = false) { diff --git a/static/src/app/services/user-interface/snack-bar/snack-bar.service.ts b/static/src/app/services/user-interface/snack-bar/snack-bar.service.ts index 7aafaa4..f4c7842 100644 --- a/static/src/app/services/user-interface/snack-bar/snack-bar.service.ts +++ b/static/src/app/services/user-interface/snack-bar/snack-bar.service.ts @@ -38,7 +38,7 @@ export class SnackBarService { showError(i18n: string, duration?: number) { this.translate.get(i18n).subscribe((translated) => { this.translate.get('generic.snackbar.error.button.okay').subscribe((translatedOkay) => { - return this.show(translated, translatedOkay, duration, ['custom-snack-bar', 'label-danger']); + return this.show(translated, translatedOkay, duration, ['custom-snack-bar', 'label-danger']); }); }); }