Replace use of deprecated RequestOptions and RequestMethod (CC-66)

pull/47/head
HardiReady 2018-10-20 22:40:18 +02:00
parent 67aaf50f26
commit 859df0359d
7 changed files with 34 additions and 53 deletions

View File

@ -1,10 +1,9 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {Decoration} from '../../models/model-interfaces'; import {Decoration} from '../../models/model-interfaces';
import {RequestMethod, RequestOptions} from '@angular/http';
import {Observable} from 'rxjs/Observable'; import {Observable} from 'rxjs/Observable';
import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store';
import {AppConfig} from '../../app.config'; import {AppConfig} from '../../app.config';
import {HttpGateway} from '../http-gateway'; import {HttpGateway, HttpMethod} from '../http-gateway';
import {HttpParams} from '@angular/common/http'; import {HttpParams} from '@angular/common/http';
@Injectable() @Injectable()
@ -44,16 +43,16 @@ export class DecorationService {
*/ */
submitDecoration(decoration: Decoration, imageFile?) { submitDecoration(decoration: Decoration, imageFile?) {
let requestUrl = this.config.apiDecorationPath; let requestUrl = this.config.apiDecorationPath;
let requestMethod: RequestMethod; let requestMethod: HttpMethod;
let accessType; let accessType;
let body; let body;
if (decoration._id) { if (decoration._id) {
requestUrl += decoration._id; requestUrl += decoration._id;
requestMethod = RequestMethod.Patch; requestMethod = 'PATCH';
accessType = EDIT; accessType = EDIT;
} else { } else {
requestMethod = RequestMethod.Post; requestMethod = 'POST';
accessType = ADD; accessType = ADD;
} }
@ -69,12 +68,7 @@ export class DecorationService {
body = decoration; body = decoration;
} }
const options = new RequestOptions({ return this.httpGateway.request<Decoration>(requestUrl, body, requestMethod)
body: body,
method: requestMethod,
});
return this.httpGateway.request<Decoration>(requestUrl, options)
.do(savedDecoration => { .do(savedDecoration => {
const action = {type: accessType, data: savedDecoration}; const action = {type: accessType, data: savedDecoration};
this.decorationStore.dispatch(action); this.decorationStore.dispatch(action);

View File

@ -1,10 +1,9 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {Rank} from '../../models/model-interfaces'; import {Rank} from '../../models/model-interfaces';
import {RequestMethod, RequestOptions} from '@angular/http';
import {Observable} from 'rxjs/Observable'; import {Observable} from 'rxjs/Observable';
import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store';
import {AppConfig} from '../../app.config'; import {AppConfig} from '../../app.config';
import {HttpGateway} from '../http-gateway'; import {HttpGateway, HttpMethod} from '../http-gateway';
import {HttpParams} from '@angular/common/http'; import {HttpParams} from '@angular/common/http';
@Injectable() @Injectable()
@ -44,16 +43,16 @@ export class RankService {
*/ */
submitRank(rank: Rank, imageFile?): Observable<Rank> { submitRank(rank: Rank, imageFile?): Observable<Rank> {
let requestUrl = this.config.apiRankPath; let requestUrl = this.config.apiRankPath;
let requestMethod: RequestMethod; let requestMethod: HttpMethod;
let accessType; let accessType;
let body; let body;
if (rank._id) { if (rank._id) {
requestUrl += rank._id; requestUrl += rank._id;
requestMethod = RequestMethod.Patch; requestMethod = 'PATCH';
accessType = EDIT; accessType = EDIT;
} else { } else {
requestMethod = RequestMethod.Post; requestMethod = 'POST';
accessType = ADD; accessType = ADD;
} }
@ -70,12 +69,7 @@ export class RankService {
body = rank; body = rank;
} }
const options = new RequestOptions({ return this.httpGateway.request<Rank>(requestUrl, body, requestMethod)
body: body,
method: requestMethod
});
return this.httpGateway.request<Rank>(requestUrl, options)
.do(savedRank => { .do(savedRank => {
const action = {type: accessType, data: savedRank}; const action = {type: accessType, data: savedRank};
// leave some time to save image file before accessing it through list view // leave some time to save image file before accessing it through list view

View File

@ -1,10 +1,9 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {Squad} from '../../models/model-interfaces'; import {Squad} from '../../models/model-interfaces';
import {RequestMethod, RequestOptions} from '@angular/http';
import {Observable} from 'rxjs/Observable'; import {Observable} from 'rxjs/Observable';
import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store';
import {AppConfig} from '../../app.config'; import {AppConfig} from '../../app.config';
import {HttpGateway} from '../http-gateway'; import {HttpGateway, HttpMethod} from '../http-gateway';
import {HttpParams} from '@angular/common/http'; import {HttpParams} from '@angular/common/http';
@Injectable() @Injectable()
@ -42,16 +41,16 @@ export class SquadService {
*/ */
submitSquad(squad: Squad, imageFile?): Observable<Squad> { submitSquad(squad: Squad, imageFile?): Observable<Squad> {
let requestUrl = this.config.apiSquadPath; let requestUrl = this.config.apiSquadPath;
let requestMethod: RequestMethod; let requestMethod: HttpMethod;
let accessType; let accessType;
let body; let body;
if (squad._id) { if (squad._id) {
requestUrl += squad._id; requestUrl += squad._id;
requestMethod = RequestMethod.Patch; requestMethod = 'PATCH';
accessType = EDIT; accessType = EDIT;
} else { } else {
requestMethod = RequestMethod.Post; requestMethod = 'POST';
accessType = ADD; accessType = ADD;
} }
@ -67,12 +66,7 @@ export class SquadService {
body = squad; body = squad;
} }
const options = new RequestOptions({ return this.httpGateway.request<Squad>(requestUrl, body, requestMethod)
body: body,
method: requestMethod
});
return this.httpGateway.request<Squad>(requestUrl, options)
.do(savedSquad => { .do(savedSquad => {
const action = {type: accessType, data: savedSquad}; const action = {type: accessType, data: savedSquad};
this.squadStore.dispatch(action); this.squadStore.dispatch(action);

View File

@ -1,10 +1,11 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {RequestMethod} from '@angular/http';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import {CookieService} from 'ngx-cookie-service'; import {CookieService} from 'ngx-cookie-service';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http'; import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {Observable} from 'rxjs'; import {Observable} from 'rxjs';
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH'
@Injectable() @Injectable()
export class HttpGateway { export class HttpGateway {
@ -62,12 +63,16 @@ export class HttpGateway {
return this.http.delete(url, this.createAuthorizationHeader()); return this.http.delete(url, this.createAuthorizationHeader());
} }
request<T>(requestUrl, options): Observable<T> { request<T>(requestUrl, body, method: HttpMethod): Observable<T> {
if (options.method === RequestMethod.Post) { switch (method) {
return this.post<T>(requestUrl, options.body); case 'GET':
} return this.get(requestUrl);
if (options.method === RequestMethod.Patch) { case 'POST':
return this.patch<T>(requestUrl, options.body); return this.post<T>(requestUrl, body);
case 'PUT':
return this.put(requestUrl, body);
case 'PATCH':
return this.patch<T>(requestUrl, body);
} }
} }
} }

View File

@ -3,8 +3,7 @@ import {Campaign} from '../../models/model-interfaces';
import {AppConfig} from '../../app.config'; import {AppConfig} from '../../app.config';
import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store';
import {Observable} from 'rxjs'; import {Observable} from 'rxjs';
import {RequestMethod, RequestOptions} from '@angular/http'; import {HttpGateway, HttpMethod} from '../http-gateway';
import {HttpGateway} from '../http-gateway';
@Injectable() @Injectable()
export class CampaignService { export class CampaignService {
@ -33,25 +32,20 @@ export class CampaignService {
submitCampaign(campaign: Campaign) { submitCampaign(campaign: Campaign) {
let requestUrl: string; let requestUrl: string;
let requestMethod: RequestMethod; let requestMethod: HttpMethod;
let accessType; let accessType;
if (campaign._id) { if (campaign._id) {
requestUrl = this.config.apiCampaignPath + '/' + campaign._id; requestUrl = this.config.apiCampaignPath + '/' + campaign._id;
requestMethod = RequestMethod.Patch; requestMethod = 'PATCH';
accessType = EDIT; accessType = EDIT;
} else { } else {
requestUrl = this.config.apiCampaignPath; requestUrl = this.config.apiCampaignPath;
requestMethod = RequestMethod.Post; requestMethod = 'POST';
accessType = ADD; accessType = ADD;
} }
const options = new RequestOptions({ return this.httpGateway.request<Campaign>(requestUrl, campaign, requestMethod)
body: campaign,
method: requestMethod
});
return this.httpGateway.request<Campaign>(requestUrl, options)
.do(savedCampaign => { .do(savedCampaign => {
const action = {type: accessType, data: savedCampaign}; const action = {type: accessType, data: savedCampaign};
this.campaignStore.dispatch(action); this.campaignStore.dispatch(action);

View File

@ -39,7 +39,7 @@ export class LogsService {
params.append('fraction', fraction); params.append('fraction', fraction);
params.append('stabilized', stabilizedOnly ? 'true' : ''); params.append('stabilized', stabilizedOnly ? 'true' : '');
params.append('revive', reviveOnly ? '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) { getKillLogs(warId: string, shooterName = '', targetName = '', fraction = '', friendlyFireOnly = false, notFriendlyFireOnly = false) {