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 {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<Decoration>(requestUrl, options)
return this.httpGateway.request<Decoration>(requestUrl, body, requestMethod)
.do(savedDecoration => {
const action = {type: accessType, data: savedDecoration};
this.decorationStore.dispatch(action);

View File

@ -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<Rank> {
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<Rank>(requestUrl, options)
return this.httpGateway.request<Rank>(requestUrl, body, requestMethod)
.do(savedRank => {
const action = {type: accessType, data: savedRank};
// 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 {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<Squad> {
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<Squad>(requestUrl, options)
return this.httpGateway.request<Squad>(requestUrl, body, requestMethod)
.do(savedSquad => {
const action = {type: accessType, data: savedSquad};
this.squadStore.dispatch(action);

View File

@ -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<T>(requestUrl, options): Observable<T> {
if (options.method === RequestMethod.Post) {
return this.post<T>(requestUrl, options.body);
}
if (options.method === RequestMethod.Patch) {
return this.patch<T>(requestUrl, options.body);
request<T>(requestUrl, body, method: HttpMethod): Observable<T> {
switch (method) {
case 'GET':
return this.get(requestUrl);
case 'POST':
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 {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<Campaign>(requestUrl, options)
return this.httpGateway.request<Campaign>(requestUrl, campaign, requestMethod)
.do(savedCampaign => {
const action = {type: accessType, data: savedCampaign};
this.campaignStore.dispatch(action);

View File

@ -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) {

View File

@ -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']);
});
});
}