Rename custom HttpClient to HttpGateway (CC-63)

pull/46/head
HardiReady 2018-10-09 23:23:41 +02:00
parent b425617a7d
commit 66022e4141
14 changed files with 80 additions and 82 deletions

View File

@ -21,8 +21,8 @@ import {SnackBarService} from './services/user-interface/snack-bar/snack-bar.ser
import {HttpClientModule} from '@angular/common/http'; import {HttpClientModule} from '@angular/common/http';
import {SpinnerService} from './services/user-interface/spinner/spinner.service'; import {SpinnerService} from './services/user-interface/spinner/spinner.service';
import {MatSelectModule, MatSnackBarModule} from '@angular/material'; import {MatSelectModule, MatSnackBarModule} from '@angular/material';
import {HttpClient} from './services/http-client';
import {SettingsService} from './services/settings.service'; import {SettingsService} from './services/settings.service';
import {HttpGateway} from './services/http-client';
@NgModule({ @NgModule({
imports: [ imports: [
@ -38,7 +38,7 @@ import {SettingsService} from './services/settings.service';
], ],
providers: [ providers: [
HttpClient, HttpGateway,
LoginService, LoginService,
LoginGuardSQL, LoginGuardSQL,
LoginGuardHL, LoginGuardHL,

View File

@ -3,7 +3,7 @@ import {AppUser} from '../../models/model-interfaces';
import {Observable} from 'rxjs/Observable'; import {Observable} from 'rxjs/Observable';
import {EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; import {EDIT, LOAD, REMOVE, Store} from '../stores/generic-store';
import {AppConfig} from '../../app.config'; import {AppConfig} from '../../app.config';
import {HttpClient} from '../http-client'; import {HttpGateway} from '../http-client';
@Injectable() @Injectable()
export class AppUserService { export class AppUserService {
@ -12,13 +12,13 @@ export class AppUserService {
private appUserStore = new Store<AppUser>(); private appUserStore = new Store<AppUser>();
constructor(private http: HttpClient, constructor(private httpGateway: HttpGateway,
private config: AppConfig) { private config: AppConfig) {
this.users$ = this.appUserStore.items$; this.users$ = this.appUserStore.items$;
} }
getUsers() { getUsers() {
this.http.get(this.config.apiAppUserPath) this.httpGateway.get(this.config.apiAppUserPath)
.map(res => res.json()) .map(res => res.json())
.do((users) => { .do((users) => {
this.appUserStore.dispatch({type: LOAD, data: users}); this.appUserStore.dispatch({type: LOAD, data: users});
@ -29,7 +29,7 @@ export class AppUserService {
} }
updateUser(user: AppUser) { updateUser(user: AppUser) {
return this.http.patch(this.config.apiAppUserPath + user._id, user) return this.httpGateway.patch(this.config.apiAppUserPath + user._id, user)
.map(res => res.json()) .map(res => res.json())
.do(savedUser => { .do(savedUser => {
const action = {type: EDIT, data: savedUser}; const action = {type: EDIT, data: savedUser};
@ -38,7 +38,7 @@ export class AppUserService {
} }
deleteUser(user) { deleteUser(user) {
return this.http.delete(this.config.apiAppUserPath + user._id) return this.httpGateway.delete(this.config.apiAppUserPath + user._id)
.do(res => { .do(res => {
this.appUserStore.dispatch({type: REMOVE, data: user}); this.appUserStore.dispatch({type: REMOVE, data: user});
}); });

View File

@ -1,14 +1,14 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {Award} from '../../models/model-interfaces'; import {Award} from '../../models/model-interfaces';
import {AppConfig} from '../../app.config'; import {AppConfig} from '../../app.config';
import {HttpClient} from '../http-client'; import {HttpGateway} from '../http-client';
@Injectable() @Injectable()
export class AwardingService { export class AwardingService {
hasUnprocessedAwards = false; hasUnprocessedAwards = false;
constructor(private http: HttpClient, constructor(private httpGateway: HttpGateway,
private config: AppConfig) { private config: AppConfig) {
} }
@ -18,24 +18,24 @@ export class AwardingService {
.concat('&fractFilter=').concat(fraction) .concat('&fractFilter=').concat(fraction)
.concat('&userId=').concat(userId) .concat('&userId=').concat(userId)
.concat('&squadId=').concat(squadId); .concat('&squadId=').concat(squadId);
return this.http.get(getUrl).map(res => res.json()); return this.httpGateway.get(getUrl).map(res => res.json());
} }
addAwarding(award: Award) { addAwarding(award: Award) {
return this.http.post(this.config.apiAwardPath, award); return this.httpGateway.post(this.config.apiAwardPath, award);
} }
updateAward(award) { updateAward(award) {
return this.http.patch(this.config.apiAwardPath + '/' + award._id, award) return this.httpGateway.patch(this.config.apiAwardPath + '/' + award._id, award)
.map(res => res.json()); .map(res => res.json());
} }
requestAwarding(award: Award) { requestAwarding(award: Award) {
return this.http.post(this.config.apiRequestAwardPath, award); return this.httpGateway.post(this.config.apiRequestAwardPath, award);
} }
deleteAwarding(awardingId) { deleteAwarding(awardingId) {
return this.http.delete(this.config.apiAwardPath + '/' + awardingId); return this.httpGateway.delete(this.config.apiAwardPath + '/' + awardingId);
} }
getUnconfirmedAwards(fraction?: string) { getUnconfirmedAwards(fraction?: string) {

View File

@ -4,7 +4,7 @@ import {RequestMethod, RequestOptions, URLSearchParams} 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 {HttpClient} from '../http-client'; import {HttpGateway} from '../http-client';
@Injectable() @Injectable()
export class DecorationService { export class DecorationService {
@ -13,7 +13,7 @@ export class DecorationService {
decorationStore = new Store<Decoration>(); decorationStore = new Store<Decoration>();
constructor(private http: HttpClient, constructor(private httpGateway: HttpGateway,
private config: AppConfig) { private config: AppConfig) {
this.decorations$ = this.decorationStore.items$; this.decorations$ = this.decorationStore.items$;
} }
@ -25,7 +25,7 @@ export class DecorationService {
searchParams.append('fractFilter', fractionFilter); searchParams.append('fractFilter', fractionFilter);
} }
this.http.get(this.config.apiDecorationPath, searchParams) this.httpGateway.get(this.config.apiDecorationPath, searchParams)
.map(res => res.json()) .map(res => res.json())
.do((squads) => { .do((squads) => {
this.decorationStore.dispatch({type: LOAD, data: squads}); this.decorationStore.dispatch({type: LOAD, data: squads});
@ -36,7 +36,7 @@ export class DecorationService {
} }
getDecoration(id: number | string): Observable<Decoration> { getDecoration(id: number | string): Observable<Decoration> {
return this.http.get(this.config.apiDecorationPath + id) return this.httpGateway.get(this.config.apiDecorationPath + id)
.map(res => res.json()); .map(res => res.json());
} }
@ -76,7 +76,7 @@ export class DecorationService {
method: requestMethod, method: requestMethod,
}); });
return this.http.request(requestUrl, options) return this.httpGateway.request(requestUrl, options)
.map(res => res.json()) .map(res => res.json())
.do(savedDecoration => { .do(savedDecoration => {
const action = {type: accessType, data: savedDecoration}; const action = {type: accessType, data: savedDecoration};
@ -85,7 +85,7 @@ export class DecorationService {
} }
deleteDecoration(decoration: Decoration) { deleteDecoration(decoration: Decoration) {
return this.http.delete(this.config.apiDecorationPath + decoration._id) return this.httpGateway.delete(this.config.apiDecorationPath + decoration._id)
.do(res => { .do(res => {
this.decorationStore.dispatch({type: REMOVE, data: decoration}); this.decorationStore.dispatch({type: REMOVE, data: decoration});
}); });

View File

@ -1,19 +1,19 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {AppConfig} from '../../app.config'; import {AppConfig} from '../../app.config';
import {HttpClient} from '../http-client';
import {Promotion} from '../../models/model-interfaces'; import {Promotion} from '../../models/model-interfaces';
import {HttpGateway} from '../http-client';
@Injectable() @Injectable()
export class PromotionService { export class PromotionService {
hasUnprocessedPromotion = false; hasUnprocessedPromotion = false;
constructor(private http: HttpClient, constructor(private httpGateway: HttpGateway,
private config: AppConfig) { private config: AppConfig) {
} }
getUnconfirmedPromotions(fraction?: string) { getUnconfirmedPromotions(fraction?: string) {
return this.http.get(this.config.apiPromotionPath + '?inProgress=true&fractFilter=' + fraction) return this.httpGateway.get(this.config.apiPromotionPath + '?inProgress=true&fractFilter=' + fraction)
.map(res => res.json()); .map(res => res.json());
} }
@ -26,21 +26,21 @@ export class PromotionService {
} }
getSquadPromotions(squadId: string) { getSquadPromotions(squadId: string) {
return this.http.get(this.config.apiPromotionPath + '?squadId=' + squadId) return this.httpGateway.get(this.config.apiPromotionPath + '?squadId=' + squadId)
.map(res => res.json()); .map(res => res.json());
} }
requestPromotion(promotion: Promotion) { requestPromotion(promotion: Promotion) {
return this.http.post(this.config.apiPromotionPath, promotion); return this.httpGateway.post(this.config.apiPromotionPath, promotion);
} }
updatePromotion(promotion) { updatePromotion(promotion) {
return this.http.patch(this.config.apiPromotionPath + '/' + promotion._id, promotion) return this.httpGateway.patch(this.config.apiPromotionPath + '/' + promotion._id, promotion)
.map(res => res.json()); .map(res => res.json());
} }
deletePromotion(promotionId) { deletePromotion(promotionId) {
return this.http.delete(this.config.apiPromotionPath + promotionId); return this.httpGateway.delete(this.config.apiPromotionPath + promotionId);
} }
} }

View File

@ -4,7 +4,7 @@ import {RequestMethod, RequestOptions, URLSearchParams} 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 {HttpClient} from '../http-client'; import {HttpGateway} from '../http-client';
@Injectable() @Injectable()
export class RankService { export class RankService {
@ -13,7 +13,7 @@ export class RankService {
rankStore = new Store<Rank>(); rankStore = new Store<Rank>();
constructor(private http: HttpClient, constructor(private httpGateway: HttpGateway,
private config: AppConfig) { private config: AppConfig) {
this.ranks$ = this.rankStore.items$; this.ranks$ = this.rankStore.items$;
} }
@ -25,7 +25,7 @@ export class RankService {
searchParams.append('fractFilter', fractionFilter); searchParams.append('fractFilter', fractionFilter);
} }
this.http.get(this.config.apiRankPath, searchParams) this.httpGateway.get(this.config.apiRankPath, searchParams)
.map(res => res.json()) .map(res => res.json())
.do((ranks) => { .do((ranks) => {
this.rankStore.dispatch({type: LOAD, data: ranks}); this.rankStore.dispatch({type: LOAD, data: ranks});
@ -36,7 +36,7 @@ export class RankService {
} }
getRank(id: number | string): Observable<Rank> { getRank(id: number | string): Observable<Rank> {
return this.http.get(this.config.apiRankPath + id) return this.httpGateway.get(this.config.apiRankPath + id)
.map(res => res.json()); .map(res => res.json());
} }
@ -77,7 +77,7 @@ export class RankService {
method: requestMethod method: requestMethod
}); });
return this.http.request(requestUrl, options) return this.httpGateway.request(requestUrl, options)
.map(res => res.json()) .map(res => res.json())
.do(savedRank => { .do(savedRank => {
const action = {type: accessType, data: savedRank}; const action = {type: accessType, data: savedRank};
@ -89,7 +89,7 @@ export class RankService {
} }
deleteRank(rank: Rank) { deleteRank(rank: Rank) {
return this.http.delete(this.config.apiRankPath + rank._id) return this.httpGateway.delete(this.config.apiRankPath + rank._id)
.do(res => { .do(res => {
this.rankStore.dispatch({type: REMOVE, data: rank}); this.rankStore.dispatch({type: REMOVE, data: rank});
}); });

View File

@ -4,7 +4,7 @@ import {RequestMethod, RequestOptions, URLSearchParams} 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 {HttpClient} from '../http-client'; import {HttpGateway} from '../http-client';
@Injectable() @Injectable()
export class SquadService { export class SquadService {
@ -13,7 +13,7 @@ export class SquadService {
squadStore = new Store<Squad>(); squadStore = new Store<Squad>();
constructor(private http: HttpClient, constructor(private httpGateway: HttpGateway,
private config: AppConfig) { private config: AppConfig) {
this.squads$ = this.squadStore.items$; this.squads$ = this.squadStore.items$;
} }
@ -23,7 +23,7 @@ export class SquadService {
searchParams.append('q', query); searchParams.append('q', query);
searchParams.append('fractFilter', fractionFilter); searchParams.append('fractFilter', fractionFilter);
this.http.get(this.config.apiSquadPath, searchParams) this.httpGateway.get(this.config.apiSquadPath, searchParams)
.map(res => res.json()) .map(res => res.json())
.do((squads) => { .do((squads) => {
this.squadStore.dispatch({type: LOAD, data: squads}); this.squadStore.dispatch({type: LOAD, data: squads});
@ -34,7 +34,7 @@ export class SquadService {
} }
getSquad(id: number | string): Observable<Squad> { getSquad(id: number | string): Observable<Squad> {
return this.http.get(this.config.apiSquadPath + id) return this.httpGateway.get(this.config.apiSquadPath + id)
.map(res => res.json()); .map(res => res.json());
} }
@ -74,7 +74,7 @@ export class SquadService {
method: requestMethod method: requestMethod
}); });
return this.http.request(requestUrl, options) return this.httpGateway.request(requestUrl, options)
.map(res => res.json()) .map(res => res.json())
.do(savedSquad => { .do(savedSquad => {
const action = {type: accessType, data: savedSquad}; const action = {type: accessType, data: savedSquad};
@ -83,7 +83,7 @@ export class SquadService {
} }
deleteSquad(squad: Squad) { deleteSquad(squad: Squad) {
return this.http.delete(this.config.apiSquadPath + squad._id) return this.httpGateway.delete(this.config.apiSquadPath + squad._id)
.do(res => { .do(res => {
this.squadStore.dispatch({type: REMOVE, data: squad}); this.squadStore.dispatch({type: REMOVE, data: squad});
}); });

View File

@ -4,7 +4,7 @@ import {URLSearchParams} 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 {HttpClient} from '../http-client'; import {HttpGateway} from '../http-client';
@Injectable() @Injectable()
export class UserService { export class UserService {
@ -15,7 +15,7 @@ export class UserService {
totalCount = 0; totalCount = 0;
constructor(private http: HttpClient, constructor(private httpGateway: HttpGateway,
private config: AppConfig) { private config: AppConfig) {
this.users$ = this.userStore.items$; this.users$ = this.userStore.items$;
} }
@ -39,7 +39,7 @@ export class UserService {
searchParams.append('limit', limit); searchParams.append('limit', limit);
searchParams.append('offset', offset); searchParams.append('offset', offset);
this.http.get(this.config.apiUserPath, searchParams) this.httpGateway.get(this.config.apiUserPath, searchParams)
.do((res) => { .do((res) => {
const headerCount = parseInt(res.headers.get('x-total-count'), 10); const headerCount = parseInt(res.headers.get('x-total-count'), 10);
if (headerCount) { if (headerCount) {
@ -54,12 +54,12 @@ export class UserService {
} }
getUser(_id: number | string): Observable<User> { getUser(_id: number | string): Observable<User> {
return this.http.get(this.config.apiUserPath + _id) return this.httpGateway.get(this.config.apiUserPath + _id)
.map(res => res.json()); .map(res => res.json());
} }
submitUser(user) { submitUser(user) {
return this.http.post(this.config.apiUserPath, user) return this.httpGateway.post(this.config.apiUserPath, user)
.map(res => res.json()) .map(res => res.json())
.do(savedUser => { .do(savedUser => {
const action = {type: ADD, data: savedUser}; const action = {type: ADD, data: savedUser};
@ -68,7 +68,7 @@ export class UserService {
} }
updateUser(user) { updateUser(user) {
return this.http.put(this.config.apiUserPath + user._id, user) return this.httpGateway.put(this.config.apiUserPath + user._id, user)
.map(res => res.json()) .map(res => res.json())
.do(savedUser => { .do(savedUser => {
const action = {type: EDIT, data: savedUser}; const action = {type: EDIT, data: savedUser};
@ -77,7 +77,7 @@ export class UserService {
} }
deleteUser(user) { deleteUser(user) {
return this.http.delete(this.config.apiUserPath + user._id) return this.httpGateway.delete(this.config.apiUserPath + user._id)
.do(res => { .do(res => {
this.userStore.dispatch({type: REMOVE, data: user}); this.userStore.dispatch({type: REMOVE, data: user});
}); });

View File

@ -4,7 +4,7 @@ import {Router} from '@angular/router';
import {CookieService} from 'ngx-cookie-service'; import {CookieService} from 'ngx-cookie-service';
@Injectable() @Injectable()
export class HttpClient { export class HttpGateway {
constructor(private router: Router, constructor(private router: Router,
private http: Http, private http: Http,

View File

@ -1,10 +1,10 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {Campaign} from '../../models/model-interfaces'; import {Campaign} from '../../models/model-interfaces';
import {AppConfig} from '../../app.config'; import {AppConfig} from '../../app.config';
import {HttpClient} from '../http-client';
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 {RequestMethod, RequestOptions} from '@angular/http';
import {HttpGateway} from '../http-client';
@Injectable() @Injectable()
export class CampaignService { export class CampaignService {
@ -13,24 +13,24 @@ export class CampaignService {
campaignStore = new Store<Campaign>(); campaignStore = new Store<Campaign>();
constructor(private http: HttpClient, constructor(private httpGateway: HttpGateway,
private config: AppConfig) { private config: AppConfig) {
this.campaigns$ = this.campaignStore.items$; this.campaigns$ = this.campaignStore.items$;
} }
getAllCampaigns() { getAllCampaigns() {
return this.http.get(this.config.apiCampaignPath) return this.httpGateway.get(this.config.apiCampaignPath)
.map(res => res.json()) .map(res => res.json())
.do((ranks) => this.campaignStore.dispatch({type: LOAD, data: ranks})); .do((ranks) => this.campaignStore.dispatch({type: LOAD, data: ranks}));
} }
getCampaign(id: string) { getCampaign(id: string) {
return this.http.get(`${this.config.apiCampaignPath}/${id}`) return this.httpGateway.get(`${this.config.apiCampaignPath}/${id}`)
.map(res => res.json()); .map(res => res.json());
} }
getCampaignByWarId(warId) { getCampaignByWarId(warId) {
return this.http.get(`${this.config.apiCampaignPath}/with/war/${warId}`) return this.httpGateway.get(`${this.config.apiCampaignPath}/with/war/${warId}`)
.map((res) => res.json()); .map((res) => res.json());
} }
@ -54,7 +54,7 @@ export class CampaignService {
method: requestMethod method: requestMethod
}); });
return this.http.request(requestUrl, options) return this.httpGateway.request(requestUrl, options)
.map(res => res.json()) .map(res => res.json())
.do(savedCampaign => { .do(savedCampaign => {
const action = {type: accessType, data: savedCampaign}; const action = {type: accessType, data: savedCampaign};
@ -63,7 +63,7 @@ export class CampaignService {
} }
deleteCampaign(campaign: Campaign) { deleteCampaign(campaign: Campaign) {
return this.http.delete(this.config.apiCampaignPath + '/' + campaign._id) return this.httpGateway.delete(this.config.apiCampaignPath + '/' + campaign._id)
.do(res => this.campaignStore.dispatch({type: REMOVE, data: campaign})); .do(res => this.campaignStore.dispatch({type: REMOVE, data: campaign}));
} }
} }

View File

@ -1,38 +1,38 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {AppConfig} from '../../app.config'; import {AppConfig} from '../../app.config';
import {HttpClient} from '../http-client';
import {URLSearchParams} from '@angular/http'; import {URLSearchParams} from '@angular/http';
import {HttpGateway} from '../http-client';
@Injectable() @Injectable()
export class LogsService { export class LogsService {
constructor(private http: HttpClient, constructor(private httpGateway: HttpGateway,
private config: AppConfig) { private config: AppConfig) {
} }
getFullLog(warId: string) { getFullLog(warId: string) {
return this.http.get(this.config.apiLogsPath + '/' + warId) return this.httpGateway.get(this.config.apiLogsPath + '/' + warId)
.map(res => res.json()); .map(res => res.json());
} }
getBudgetLogs(warId: string, fraction = '') { getBudgetLogs(warId: string, fraction = '') {
const params = new URLSearchParams(); const params = new URLSearchParams();
params.append('fraction', fraction); params.append('fraction', fraction);
return this.http.get(this.config.apiLogsPath + '/' + warId + '/budget', params) return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/budget', params)
.map(res => res.json()); .map(res => res.json());
} }
getRespawnLogs(warId: string, playerName = '') { getRespawnLogs(warId: string, playerName = '') {
const params = new URLSearchParams(); const params = new URLSearchParams();
params.append('player', playerName); params.append('player', playerName);
return this.http.get(this.config.apiLogsPath + '/' + warId + '/respawn', params) return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/respawn', params)
.map(res => res.json()); .map(res => res.json());
} }
getPointsLogs(warId: string, fraction = '') { getPointsLogs(warId: string, fraction = '') {
const params = new URLSearchParams(); const params = new URLSearchParams();
params.append('fraction', fraction); params.append('fraction', fraction);
return this.http.get(this.config.apiLogsPath + '/' + warId + '/points', params) return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/points', params)
.map(res => res.json()); .map(res => res.json());
} }
@ -43,7 +43,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.http.get(this.config.apiLogsPath + '/' + warId + '/revive', params) return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/revive', params)
.map(res => res.json()); .map(res => res.json());
} }
@ -54,7 +54,7 @@ export class LogsService {
params.append('fraction', fraction); params.append('fraction', fraction);
params.append('friendlyFire', friendlyFireOnly ? 'true' : ''); params.append('friendlyFire', friendlyFireOnly ? 'true' : '');
params.append('noFriendlyFire', notFriendlyFireOnly ? 'true' : ''); params.append('noFriendlyFire', notFriendlyFireOnly ? 'true' : '');
return this.http.get(this.config.apiLogsPath + '/' + warId + '/kills', params) return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/kills', params)
.map(res => res.json()); .map(res => res.json());
} }
@ -63,7 +63,7 @@ export class LogsService {
params.append('driver', driverName); params.append('driver', driverName);
params.append('passenger', passengerName); params.append('passenger', passengerName);
params.append('fraction', fraction); params.append('fraction', fraction);
return this.http.get(this.config.apiLogsPath + '/' + warId + '/transport', params) return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/transport', params)
.map(res => res.json()); .map(res => res.json());
} }
@ -73,8 +73,7 @@ export class LogsService {
params.append('fraction', fraction); params.append('fraction', fraction);
params.append('capture', captureOnly ? 'true' : ''); params.append('capture', captureOnly ? 'true' : '');
params.append('defend', defendOnly ? 'true' : ''); params.append('defend', defendOnly ? 'true' : '');
return this.http.get(this.config.apiLogsPath + '/' + warId + '/flag', params) return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/flag', params)
.map(res => res.json()); .map(res => res.json());
} }
} }

View File

@ -1,23 +1,21 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {AppConfig} from '../../app.config'; import {AppConfig} from '../../app.config';
import {HttpClient} from '../http-client'; import {HttpGateway} from '../http-client';
@Injectable() @Injectable()
export class PlayerService { export class PlayerService {
constructor(private http: HttpClient, constructor(private httpGateway: HttpGateway,
private config: AppConfig) { private config: AppConfig) {
} }
getCampaignPlayer(campaignId: string, playerName: string) { getCampaignPlayer(campaignId: string, playerName: string) {
return this.http.get(this.config.apiPlayersPath + '/single/' + campaignId + '/' + playerName) return this.httpGateway.get(this.config.apiPlayersPath + '/single/' + campaignId + '/' + playerName)
.map(res => res.json()); .map(res => res.json());
} }
getCampaignHighscore(campaignId: string) { getCampaignHighscore(campaignId: string) {
return this.http.get(this.config.apiPlayersPath + '/ranking/' + campaignId) return this.httpGateway.get(this.config.apiPlayersPath + '/ranking/' + campaignId)
.map(res => res.json()); .map(res => res.json());
} }
} }

View File

@ -1,9 +1,9 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {War} from '../../models/model-interfaces'; import {War} from '../../models/model-interfaces';
import {AppConfig} from '../../app.config'; import {AppConfig} from '../../app.config';
import {HttpClient} from '../http-client';
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 {HttpGateway} from '../http-client';
@Injectable() @Injectable()
export class WarService { export class WarService {
@ -12,7 +12,7 @@ export class WarService {
warStore = new Store<War>(); warStore = new Store<War>();
constructor(private http: HttpClient, constructor(private httpGateway: HttpGateway,
private config: AppConfig) { private config: AppConfig) {
this.wars$ = this.warStore.items$; this.wars$ = this.warStore.items$;
} }
@ -22,13 +22,13 @@ export class WarService {
if (campaignId) { if (campaignId) {
targetUrl += `?campaignId=${campaignId}` targetUrl += `?campaignId=${campaignId}`
} }
return this.http.get(targetUrl) return this.httpGateway.get(targetUrl)
.map(res => res.json()) .map(res => res.json())
.do((wars) => this.warStore.dispatch({type: LOAD, data: wars})); .do((wars) => this.warStore.dispatch({type: LOAD, data: wars}));
} }
getWar(warId: string) { getWar(warId: string) {
return this.http.get(this.config.apiWarPath + '/' + warId) return this.httpGateway.get(this.config.apiWarPath + '/' + warId)
.map(res => res.json()); .map(res => res.json());
} }
@ -45,19 +45,19 @@ export class WarService {
body.append('log', logFile, logFile.name); body.append('log', logFile, logFile.name);
} }
return this.http.post(this.config.apiWarPath, body) return this.httpGateway.post(this.config.apiWarPath, body)
.map(res => res.json()) .map(res => res.json())
.do((newWar) => this.warStore.dispatch({type: ADD, data: newWar})); .do((newWar) => this.warStore.dispatch({type: ADD, data: newWar}));
} }
updateWar(war: War) { updateWar(war: War) {
return this.http.patch(this.config.apiWarPath + '/' + war._id, war) return this.httpGateway.patch(this.config.apiWarPath + '/' + war._id, war)
.map(res => res.json()) .map(res => res.json())
.do((updatedWar) => this.warStore.dispatch({type: EDIT, data: updatedWar})); .do((updatedWar) => this.warStore.dispatch({type: EDIT, data: updatedWar}));
} }
deleteWar(war: War) { deleteWar(war: War) {
return this.http.delete(this.config.apiWarPath + '/' + war._id) return this.httpGateway.delete(this.config.apiWarPath + '/' + war._id)
.do((emptyRes) => this.warStore.dispatch({type: REMOVE, data: war})); .do((emptyRes) => this.warStore.dispatch({type: REMOVE, data: war}));
} }
} }

View File

@ -46,11 +46,12 @@ export class StatisticComponent implements OnInit {
const id = idFetchPattern.exec(url)[1]; const id = idFetchPattern.exec(url)[1];
if (id === 'all') { if (id === 'all') {
this.switchCampaign({_id: id}); this.switchCampaign({_id: id});
} } else {
const filteredCampaigns = this.campaigns.filter(c => c._id === id); const filteredCampaigns = this.campaigns.filter(c => c._id === id);
if (filteredCampaigns.length === 1) { if (filteredCampaigns.length === 1) {
this.switchCampaign(filteredCampaigns[0]); this.switchCampaign(filteredCampaigns[0]);
} }
}
} else if (url.includes('right:war')) { } else if (url.includes('right:war')) {
const id = idFetchPattern.exec(url)[1]; const id = idFetchPattern.exec(url)[1];
console.log(id) console.log(id)