Refactoring
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
//import { environment } from 'src/environments/environment';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ApiService {
|
||||
constructor(
|
||||
|
||||
@@ -3,11 +3,12 @@ import { HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { ApiService } from './api.service';
|
||||
import { Application, ApplicationList, ApplicationListConfig, ApplicationListFilters } from 'src/app/core/models';
|
||||
import { Application, ApplicationList, ApplicationListConfig, ApplicationListFilters } from '@models';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ApplicationsService {
|
||||
private _apiVersion = '/v1';
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
@@ -22,7 +23,7 @@ export class ApplicationsService {
|
||||
};
|
||||
return this.apiService
|
||||
.get(
|
||||
'/applications' + ((config.type === 'feed') ? '/feed' : ''),
|
||||
`${this._apiVersion}/applications` + ((config.type === 'feed') ? '/feed' : ''),
|
||||
new HttpParams({ fromObject: <{
|
||||
[param: string]: string | number | boolean | readonly (string | number | boolean)[];
|
||||
}>params })
|
||||
@@ -30,22 +31,22 @@ export class ApplicationsService {
|
||||
}
|
||||
|
||||
get(slug: string): Observable<Application> {
|
||||
return this.apiService.get(`/applications/${slug}`)
|
||||
return this.apiService.get(`${this._apiVersion}/applications/${slug}`)
|
||||
.pipe(map(data => data.application));
|
||||
}
|
||||
|
||||
destroy(slug: string): Observable<boolean> {
|
||||
return this.apiService.delete(`/applications/${slug}`).pipe(map(data => data.deleted));
|
||||
return this.apiService.delete(`${this._apiVersion}/applications/${slug}`).pipe(map(data => data.deleted));
|
||||
}
|
||||
|
||||
save(application: Application): Observable<Application> {
|
||||
if (application.slug) {
|
||||
// If we're updating an existing application
|
||||
return this.apiService.put(`/applications/${application.slug}`, { application: application })
|
||||
return this.apiService.put(`${this._apiVersion}/applications/${application.slug}`, { application: application })
|
||||
.pipe(map(data => data.application));
|
||||
} else {
|
||||
// Otherwise, create a new application
|
||||
return this.apiService.post('/applications/', { application: application })
|
||||
return this.apiService.post(`${this._apiVersion}/applications/`, { application: application })
|
||||
.pipe(map(data => data.application));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@ import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ApiService } from './api.service';
|
||||
import { Article, ArticleList, ArticleListConfig, ArticleListFilters, ArticlePageData } from 'src/app/core/models';
|
||||
import { Article, ArticleList, ArticleListConfig, ArticleListFilters, ArticlePageData } from '@models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ArticlesService {
|
||||
private _apiVersion = '/v2';
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
@@ -18,7 +19,7 @@ export class ArticlesService {
|
||||
Object.assign(params, config.filters);
|
||||
return this.apiService
|
||||
.get(
|
||||
'/articles' + ((config.type === 'feed') ? '/feed' : ''),
|
||||
`${this._apiVersion}/articles` + ((config.type === 'feed') ? '/feed' : ''),
|
||||
new HttpParams({ fromObject: <{
|
||||
[param: string]: string | number | boolean | readonly (string | number | boolean)[];
|
||||
}>params })
|
||||
@@ -26,49 +27,49 @@ export class ArticlesService {
|
||||
}
|
||||
|
||||
get(slug: string): Observable<ArticlePageData> {
|
||||
/*return this.apiService.get('/articles/' + slug).pipe(map(data => {
|
||||
/*return this.apiService.get(`${this._apiVersion}/articles/${slug}`).pipe(map(data => {
|
||||
data.article.tagList = data.article.tagNameTagTagLists;
|
||||
delete data.article.tagNameTagTagLists;
|
||||
return data;
|
||||
}));*/
|
||||
return this.apiService.get(`/articles/${slug}`);
|
||||
return this.apiService.get(`${this._apiVersion}/articles/${slug}`);
|
||||
}
|
||||
|
||||
getAll(): Observable<Array<Article>> {
|
||||
return this.apiService.get('/articles').pipe(map(data => data.articles));
|
||||
return this.apiService.get(`${this._apiVersion}/articles`).pipe(map(data => data.articles));
|
||||
}
|
||||
|
||||
create(article: Article): Observable<Article> {
|
||||
return this.apiService.post('/articles/', { article: article }).pipe(map(data => data.article));
|
||||
return this.apiService.post(`${this._apiVersion}/articles/`, { article: article }).pipe(map(data => data.article));
|
||||
}
|
||||
|
||||
update(article: Article): Observable<Article> {
|
||||
return this.apiService.put(`/articles/${article.slug}`, { article: article }).pipe(map(data => data.article));
|
||||
return this.apiService.put(`${this._apiVersion}/articles/${article.slug}`, { article: article }).pipe(map(data => data.article));
|
||||
}
|
||||
|
||||
destroy(slug: string): Observable<boolean> {
|
||||
return this.apiService.delete(`/products/${slug}`).pipe(map(data => data.deleted));
|
||||
return this.apiService.delete(`${this._apiVersion}/articles/${slug}`).pipe(map(data => data.deleted));
|
||||
}
|
||||
|
||||
save(article: Article): Observable<Article> {
|
||||
// If we're updating an existing article
|
||||
if (article.slug) {
|
||||
return this.apiService.put('/articles/' + article.slug, { article: article })
|
||||
return this.apiService.put(`${this._apiVersion}/articles/${article.slug}`, { article: article })
|
||||
.pipe(map(data => data.article));
|
||||
|
||||
// Otherwise, create a new article
|
||||
} else {
|
||||
return this.apiService.post('/articles/', { article: article })
|
||||
return this.apiService.post(`${this._apiVersion}/articles/`, { article: article })
|
||||
.pipe(map(data => data.article));
|
||||
}
|
||||
}
|
||||
|
||||
favorite(slug: string): Observable<Article> {
|
||||
return this.apiService.post('/articles/' + slug + '/favorite');
|
||||
return this.apiService.post(`${this._apiVersion}/articles/${slug}/favorite`);
|
||||
}
|
||||
|
||||
unfavorite(slug: string): Observable<Article> {
|
||||
return this.apiService.delete('/articles/' + slug + '/favorite');
|
||||
return this.apiService.delete(`${this._apiVersion}/articles/${slug}/favorite`);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ApiService } from '../api.service';
|
||||
import {
|
||||
HWActivityStat, HWClan, HWClanList, HWClanListConfig,
|
||||
HWClanListFilters, HWClanPageData, HWGuildClan,
|
||||
HWMember
|
||||
} from '@models';
|
||||
|
||||
import guildData from 'src/files-data/hw-guild-data.json'; // page Membres
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class HWClanService {
|
||||
private apiVersion = '/v3';
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
|
||||
private _resetActivity(): HWActivityStat {
|
||||
const activity: HWActivityStat = { activity: 0, prestige: 0, titanite: 0, war: 0, adventure: 0, gifts: 0, score: 0, scoreGifts: 0, warGifts: 0, rewards: 0 };
|
||||
return activity;
|
||||
}
|
||||
|
||||
query(config: HWClanListConfig): Observable<HWClanList> {
|
||||
// Convert any filters over to Angular's URLSearchParams
|
||||
const params: HWClanListFilters = {} as HWClanListFilters;
|
||||
Object.assign(params, config.filters);
|
||||
return this.apiService
|
||||
.get(
|
||||
`${this.apiVersion}/clans`,
|
||||
new HttpParams({ fromObject: <{
|
||||
[param: string]: string | number | boolean | readonly (string | number | boolean)[];
|
||||
}>params })
|
||||
);
|
||||
}
|
||||
|
||||
get(id: string): Observable<HWClanPageData> {
|
||||
return this.apiService.get(`${this.apiVersion}/clans/${id}`);
|
||||
}
|
||||
|
||||
getAll(): Observable<Array<HWClan>> {
|
||||
return this.apiService.get(`${this.apiVersion}/clans`).pipe(map(data => data.clans));
|
||||
}
|
||||
|
||||
create(clan: HWClan): Observable<HWClan> {
|
||||
return this.apiService.post(`${this.apiVersion}/clans/`, { clan: clan }).pipe(map(data => data.clan));
|
||||
}
|
||||
|
||||
update(clan: HWClan): Observable<HWClan> {
|
||||
return this.apiService.put(`${this.apiVersion}/clans/${clan.id}`, { clan: clan }).pipe(map(data => data.clan));
|
||||
}
|
||||
|
||||
destroy(id: string): Observable<boolean> {
|
||||
return this.apiService.delete(`${this.apiVersion}/clans/${id}`).pipe(map(data => data.deleted));
|
||||
}
|
||||
|
||||
save(clan: HWClan): Observable<HWClan> {
|
||||
// If we're updating an existing clan
|
||||
if (clan.id) {
|
||||
return this.apiService.put(`${this.apiVersion}/clans/${clan.id}`, { clan: clan }).pipe(map(data => data.clan));
|
||||
// Otherwise, create a new clan
|
||||
} else {
|
||||
return this.apiService.post(`${this.apiVersion}/clans/`, { clan: clan }).pipe(map(data => data.clan));
|
||||
}
|
||||
}
|
||||
|
||||
loadClan(): HWGuildClan {
|
||||
const guildClan: HWGuildClan = {} as HWGuildClan;
|
||||
Object.assign(guildClan, guildData.clan);
|
||||
guildClan.sumAverages = this._resetActivity();
|
||||
guildClan.sumTotal = this._resetActivity();
|
||||
guildClan.todayAverages = this._resetActivity();
|
||||
guildClan.todayTotal = this._resetActivity();
|
||||
|
||||
return guildClan;
|
||||
}
|
||||
|
||||
loadClanStats(clan: HWGuildClan, members: HWMember[]): HWGuildClan {
|
||||
members.map((member: HWMember) => {
|
||||
clan.sumTotal.adventure += member.adventureSum;
|
||||
clan.sumTotal.gifts += member.clanGiftsSum;
|
||||
clan.sumTotal.war += member.clanWarSum;
|
||||
clan.todayTotal.activity += member.stat.todayActivity;
|
||||
clan.todayTotal.prestige += member.stat.todayPrestige;
|
||||
clan.todayTotal.titanite += member.stat.todayDungeonActivity;
|
||||
clan.todayTotal.score += (member.stat.todayDungeonActivity + member.stat.todayActivity + member.stat.todayPrestige);
|
||||
clan.sumTotal.activity += member.stat.activitySum;
|
||||
clan.sumTotal.prestige += member.stat.prestigeSum;
|
||||
clan.sumTotal.titanite += member.stat.dungeonActivitySum;
|
||||
clan.sumTotal.score += member.score;
|
||||
clan.sumTotal.warGifts += member.warGifts;
|
||||
});
|
||||
clan.sumTotal.scoreGifts = (clan.giftsCount - Math.floor(clan.sumTotal.warGifts));
|
||||
clan.todayAverages.activity = (clan.todayTotal.activity / members.length);
|
||||
clan.todayAverages.prestige = (clan.todayTotal.prestige / members.length);
|
||||
clan.todayAverages.titanite = (clan.todayTotal.titanite / members.length);
|
||||
clan.todayAverages.score = (clan.todayTotal.score / members.length);
|
||||
clan.sumAverages.activity = (clan.sumTotal.activity / members.length);
|
||||
clan.sumAverages.prestige = (clan.sumTotal.prestige / members.length);
|
||||
clan.sumAverages.titanite = (clan.sumTotal.titanite / members.length);
|
||||
if (clan.league === '3') {
|
||||
clan.sumAverages.war = (clan.sumTotal.war / 10);
|
||||
} else if (clan.league === '2') {
|
||||
clan.sumAverages.war = (clan.sumTotal.war / 15);
|
||||
} else if (clan.league === '1') {
|
||||
clan.sumAverages.war = (clan.sumTotal.war / 20);
|
||||
}
|
||||
clan.sumAverages.adventure = (clan.sumTotal.adventure / members.length);
|
||||
clan.sumAverages.gifts = (clan.sumTotal.gifts / members.length);
|
||||
clan.sumAverages.score = (clan.sumTotal.score / members.length);
|
||||
clan.sumAverages.scoreGifts = (clan.sumTotal.scoreGifts / members.length);
|
||||
clan.sumAverages.warGifts = (clan.sumTotal.warGifts / members.length);
|
||||
members.map((data) => {
|
||||
data.scoreGifts = ((data.score / clan.sumTotal.score) * clan.sumTotal.scoreGifts);
|
||||
data.rewards = Math.floor((data.scoreGifts + data.warGifts));
|
||||
clan.sumTotal.rewards += data.rewards;
|
||||
return data;
|
||||
});
|
||||
clan.sumAverages.rewards = (clan.sumTotal.rewards / members.length);
|
||||
|
||||
return clan;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ApiService, UtilitiesService } from '@services';
|
||||
import {
|
||||
HWGuildClan, HWWeekStat,
|
||||
HWMember, HWMemberList, HWMemberListConfig,
|
||||
HWMemberListFilters, HWMemberPageData, HWMemberStat
|
||||
} from '@models';
|
||||
|
||||
import guildData from 'src/files-data/hw-guild-data.json'; // page Membres
|
||||
import guildStatistics from 'src/files-data/hw-guild-statistics.json'; // page Overview -> Statistics
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class HWMemberService {
|
||||
private apiVersion = '/v3';
|
||||
constructor(
|
||||
private _apiService: ApiService,
|
||||
private _utilitiesService: UtilitiesService
|
||||
) { }
|
||||
|
||||
query(config: HWMemberListConfig): Observable<HWMemberList> {
|
||||
// Convert any filters over to Angular's URLSearchParams
|
||||
const params: HWMemberListFilters = {} as HWMemberListFilters;
|
||||
Object.assign(params, config.filters);
|
||||
return this._apiService
|
||||
.get(
|
||||
`${this.apiVersion}/members`,
|
||||
new HttpParams({ fromObject: <{
|
||||
[param: string]: string | number | boolean | readonly (string | number | boolean)[];
|
||||
}>params })
|
||||
);
|
||||
}
|
||||
|
||||
get(id: string): Observable<HWMemberPageData> {
|
||||
return this._apiService.get(`${this.apiVersion}/members/${id}`);
|
||||
}
|
||||
|
||||
getAll(): Observable<Array<HWMember>> {
|
||||
return this._apiService.get(`${this.apiVersion}/members`).pipe(map(data => data.members));
|
||||
}
|
||||
|
||||
create(member: HWMember): Observable<HWMember> {
|
||||
return this._apiService.post(`${this.apiVersion}/members/`, { member: member }).pipe(map(data => data.member));
|
||||
}
|
||||
|
||||
update(member: HWMember): Observable<HWMember> {
|
||||
return this._apiService.put(`${this.apiVersion}/members/${member.id}`, { member: member }).pipe(map(data => data.member));
|
||||
}
|
||||
|
||||
destroy(id: string): Observable<boolean> {
|
||||
return this._apiService.delete(`${this.apiVersion}/members/${id}`).pipe(map(data => data.deleted));
|
||||
}
|
||||
|
||||
save(member: HWMember): Observable<HWMember> {
|
||||
// If we're updating an existing member
|
||||
if (member.id) {
|
||||
return this._apiService.put(`${this.apiVersion}/members/${member.id}`, { member: member }).pipe(map(data => data.member));
|
||||
// Otherwise, create a new member
|
||||
} else {
|
||||
return this._apiService.post(`${this.apiVersion}/members/`, { member: member }).pipe(map(data => data.member));
|
||||
}
|
||||
}
|
||||
|
||||
loadMembers(clan: HWGuildClan): HWMember[] {
|
||||
const guildMembers: HWMember[] = [];
|
||||
const now = new Date();
|
||||
const oneDayInSec = (24 * 60 * 60);
|
||||
const daysToKick = parseInt(guildData.clan.daysToKick);
|
||||
for (const data of Object.entries(guildData.clan.members)) {
|
||||
const member: HWMember = {} as HWMember;
|
||||
Object.assign(member, data[1]);
|
||||
if (guildData.clan.warriors.indexOf(parseInt(member.id)) !== -1) {
|
||||
member.champion = true;
|
||||
} else {
|
||||
member.champion = false;
|
||||
}
|
||||
member.heroes = { power: 0, teams: []};
|
||||
member.titans = { power: 0, teams: []};
|
||||
guildMembers.push(member);
|
||||
}
|
||||
guildMembers.map((data: HWMember) => {
|
||||
const last = new Date((parseInt(data.lastLoginTime) * 1000));
|
||||
const exp = new Date(last.getTime() + ((daysToKick * oneDayInSec) * 1000));
|
||||
const diff = Math.floor(((exp.getTime() - now.getTime()) / 1000));
|
||||
const daysLeft = Math.floor((diff / oneDayInSec));
|
||||
let timeLeft = diff;
|
||||
if (daysLeft >= 1) {
|
||||
timeLeft = (diff - (daysLeft * oneDayInSec));
|
||||
}
|
||||
data.inactivity = {
|
||||
daysLeft: daysLeft,
|
||||
timeLeft: timeLeft,
|
||||
dropDelay: `${daysLeft}d, ${this._utilitiesService.secondsToDuration(timeLeft)}`,
|
||||
dropDate: Math.floor((exp.getTime() / 1000))
|
||||
};
|
||||
data.raids = [];
|
||||
data.raidsInfo = {
|
||||
variationAvg: 0,
|
||||
variationSum: 0
|
||||
};
|
||||
data.stat = {} as HWMemberStat;
|
||||
let index = guildData.membersStat.findIndex(stat => stat.userId === data.id);
|
||||
if (index !== -1) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
|
||||
const { userId, ...memberStatWithoutUserId } = guildData.membersStat[index] as any;
|
||||
Object.assign(data.stat, memberStatWithoutUserId);
|
||||
}
|
||||
index = guildStatistics.stat.findIndex(stat => stat.id === data.id);
|
||||
if (index !== -1) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
|
||||
const { id, ...weekStatSource } = guildStatistics.stat[index] as any;
|
||||
const stat: HWWeekStat = {} as HWWeekStat;
|
||||
Object.assign(stat, weekStatSource);
|
||||
data.weekStat = stat;
|
||||
data.adventureSum = guildStatistics.stat[index].adventureStat.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
||||
data.clanGiftsSum = guildStatistics.stat[index].clanGifts.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
||||
data.clanWarSum = guildStatistics.stat[index].clanWarStat.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
||||
} else {
|
||||
data.weekStat = {} as HWWeekStat;
|
||||
data.adventureSum = 0;
|
||||
data.clanGiftsSum = 0;
|
||||
data.clanWarSum = 0;
|
||||
}
|
||||
|
||||
data.score = (data.stat.dungeonActivitySum + data.stat.activitySum + data.stat.prestigeSum);
|
||||
data.warGifts = (((clan.giftsCount / 2) * ((data.clanWarSum * 10) / 100)) / 20);
|
||||
data.scoreGifts = 0;
|
||||
data.rewards = 0;
|
||||
return data;
|
||||
});
|
||||
|
||||
return guildMembers;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
export * from './hwclan.service';
|
||||
export * from './hwmember.service';
|
||||
@@ -1,60 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ApiService } from './api.service';
|
||||
import {
|
||||
HWClan, HWClanList, HWClanListConfig, HWClanListFilters, HWClanPageData
|
||||
} from 'src/app/core/models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class HWClanService {
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
|
||||
query(config: HWClanListConfig): Observable<HWClanList> {
|
||||
// Convert any filters over to Angular's URLSearchParams
|
||||
const params: HWClanListFilters = {} as HWClanListFilters;
|
||||
Object.assign(params, config.filters);
|
||||
return this.apiService
|
||||
.get(
|
||||
'/clans',
|
||||
new HttpParams({ fromObject: <{
|
||||
[param: string]: string | number | boolean | readonly (string | number | boolean)[];
|
||||
}>params })
|
||||
);
|
||||
}
|
||||
|
||||
get(id: string): Observable<HWClanPageData> {
|
||||
return this.apiService.get(`/clans/${id}`);
|
||||
}
|
||||
|
||||
getAll(): Observable<Array<HWClan>> {
|
||||
return this.apiService.get('/clans').pipe(map(data => data.clans));
|
||||
}
|
||||
|
||||
create(clan: HWClan): Observable<HWClan> {
|
||||
return this.apiService.post('/clans/', { clan: clan }).pipe(map(data => data.clan));
|
||||
}
|
||||
|
||||
update(clan: HWClan): Observable<HWClan> {
|
||||
return this.apiService.put(`/clans/${clan.id}`, { clan: clan }).pipe(map(data => data.clan));
|
||||
}
|
||||
|
||||
destroy(id: string): Observable<boolean> {
|
||||
return this.apiService.delete(`/clans/${id}`).pipe(map(data => data.deleted));
|
||||
}
|
||||
|
||||
save(clan: HWClan): Observable<HWClan> {
|
||||
// If we're updating an existing clan
|
||||
if (clan.id) {
|
||||
return this.apiService.put(`/clans/${clan.id}`, { clan: clan }).pipe(map(data => data.clan));
|
||||
// Otherwise, create a new clan
|
||||
} else {
|
||||
return this.apiService.post('/clans/', { clan: clan }).pipe(map(data => data.clan));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ApiService } from './api.service';
|
||||
import {
|
||||
HWClan, HWClanList, HWClanListConfig, HWClanListFilters, HWClanPageData
|
||||
} from 'src/app/core/models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class HWClanService {
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
|
||||
query(config: HWClanListConfig): Observable<HWClanList> {
|
||||
// Convert any filters over to Angular's URLSearchParams
|
||||
const params: HWClanListFilters = {} as HWClanListFilters;
|
||||
Object.assign(params, config.filters);
|
||||
return this.apiService
|
||||
.get(
|
||||
'/clans',
|
||||
new HttpParams({ fromObject: <{
|
||||
[param: string]: string | number | boolean | readonly (string | number | boolean)[];
|
||||
}>params })
|
||||
);
|
||||
}
|
||||
|
||||
get(id: string): Observable<HWClanPageData> {
|
||||
return this.apiService.get(`/clans/${id}`);
|
||||
}
|
||||
|
||||
getAll(): Observable<Array<HWClan>> {
|
||||
return this.apiService.get('/clans').pipe(map(data => data.clans));
|
||||
}
|
||||
|
||||
create(clan: HWClan): Observable<HWClan> {
|
||||
return this.apiService.post('/clans/', { clan: clan }).pipe(map(data => data.clan));
|
||||
}
|
||||
|
||||
update(clan: HWClan): Observable<HWClan> {
|
||||
return this.apiService.put(`/clans/${clan.id}`, { clan: clan }).pipe(map(data => data.clan));
|
||||
}
|
||||
|
||||
destroy(id: string): Observable<boolean> {
|
||||
return this.apiService.delete(`/clans/${id}`).pipe(map(data => data.deleted));
|
||||
}
|
||||
|
||||
save(clan: HWClan): Observable<HWClan> {
|
||||
// If we're updating an existing clan
|
||||
if (clan.id) {
|
||||
return this.apiService.put(`/clans/${clan.id}`, { clan: clan }).pipe(map(data => data.clan));
|
||||
// Otherwise, create a new clan
|
||||
} else {
|
||||
return this.apiService.post('/clans/', { clan: clan }).pipe(map(data => data.clan));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +1,12 @@
|
||||
export * from './aeronefs.service';
|
||||
export * from './api.service';
|
||||
export * from './applications.service';
|
||||
export * from './articles.service';
|
||||
export * from './calculator.service';
|
||||
export * from './canopies.service';
|
||||
export * from './dropzones.service';
|
||||
export * from './jumps.service';
|
||||
export * from './jump-table.service';
|
||||
export * from './jwt.service';
|
||||
export * from './pages.service';
|
||||
export * from './products.service';
|
||||
export * from './profiles.service';
|
||||
export * from './qcm.service';
|
||||
export * from './user.service';
|
||||
export * from './utilities.service';
|
||||
|
||||
export * from './skydive/';
|
||||
export * from './herowars/';
|
||||
@@ -3,28 +3,29 @@ import { Observable } from 'rxjs';
|
||||
import { take } from 'rxjs/operators';
|
||||
|
||||
import { ApiService } from './api.service';
|
||||
import { AeronefsPageData, CanopiesPageData, DropZonesPageData, JumpsPageData } from 'src/app/core/models';
|
||||
import { AeronefsPageData, CanopiesPageData, DropZonesPageData, JumpsPageData } from '@models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PagesService {
|
||||
private apiVersion = '/v1';
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
|
||||
getAeronefsPage(): Observable<AeronefsPageData> {
|
||||
return this.apiService.get(`/pages/aeronefs`).pipe(take(1));
|
||||
return this.apiService.get(`${this.apiVersion}/pages/aeronefs`).pipe(take(1));
|
||||
}
|
||||
|
||||
getCanopiesPage(): Observable<CanopiesPageData> {
|
||||
return this.apiService.get(`/pages/canopies`).pipe(take(1));
|
||||
return this.apiService.get(`${this.apiVersion}/pages/canopies`).pipe(take(1));
|
||||
}
|
||||
|
||||
getDropZonesPage(): Observable<DropZonesPageData> {
|
||||
return this.apiService.get(`/pages/dropzones`).pipe(take(1));
|
||||
return this.apiService.get(`${this.apiVersion}/pages/dropzones`).pipe(take(1));
|
||||
}
|
||||
|
||||
getJumpsPage(): Observable<JumpsPageData> {
|
||||
return this.apiService.get(`/pages/jumps`).pipe(take(1));
|
||||
return this.apiService.get(`${this.apiVersion}/pages/jumps`).pipe(take(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@ import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ApiService } from './api.service';
|
||||
import { Product, ProductList, ProductListConfig, ProductListFilters, ProductPageData, ProductsPageData } from 'src/app/core/models';
|
||||
import { Product, ProductList, ProductListConfig, ProductListFilters, ProductPageData, ProductsPageData } from '@models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ProductsService {
|
||||
private apiVersion = '/v2';
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
@@ -18,7 +19,7 @@ export class ProductsService {
|
||||
Object.assign(params, config.filters);
|
||||
return this.apiService
|
||||
.get(
|
||||
'/products' + ((config.type === 'feed') ? '/feed' : ''),
|
||||
`${this.apiVersion}/products` + ((config.type === 'feed') ? '/feed' : ''),
|
||||
new HttpParams({ fromObject: <{
|
||||
[param: string]: string | number | boolean | readonly (string | number | boolean)[];
|
||||
}>params })
|
||||
@@ -26,41 +27,41 @@ export class ProductsService {
|
||||
}
|
||||
|
||||
get(slug: string): Observable<ProductsPageData> {
|
||||
return this.apiService.get(`/product/${slug}`);
|
||||
return this.apiService.get(`${this.apiVersion}/product/${slug}`);
|
||||
}
|
||||
|
||||
getProductBySlug(slug: string): Observable<ProductPageData> {
|
||||
return this.apiService.get(`/product/${slug}`);
|
||||
return this.apiService.get(`${this.apiVersion}/product/${slug}`);
|
||||
}
|
||||
|
||||
getAll(): Observable<Array<Product>> {
|
||||
return this.apiService.get('/products').pipe(map(data => data.products));
|
||||
return this.apiService.get(`${this.apiVersion}/products`).pipe(map(data => data.products));
|
||||
}
|
||||
|
||||
getAllByCategory(category: string): Observable<ProductsPageData> {
|
||||
return this.apiService.get(`/products/${category}`); //.pipe(map(data => data.products));
|
||||
return this.apiService.get(`${this.apiVersion}/products/${category}`); //.pipe(map(data => data.products));
|
||||
}
|
||||
|
||||
create(product: Product): Observable<Product> {
|
||||
return this.apiService.post('/products/', { product: product }).pipe(map(data => data.product));
|
||||
return this.apiService.post(`${this.apiVersion}/products/`, { product: product }).pipe(map(data => data.product));
|
||||
}
|
||||
|
||||
update(product: Product): Observable<Product> {
|
||||
return this.apiService.put(`/products/${product.slug}`, { product: product }).pipe(map(data => data.product));
|
||||
return this.apiService.put(`${this.apiVersion}/products/${product.slug}`, { product: product }).pipe(map(data => data.product));
|
||||
}
|
||||
|
||||
destroy(slug: string): Observable<boolean> {
|
||||
return this.apiService.delete(`/products/${slug}`).pipe(map(data => data.deleted));
|
||||
return this.apiService.delete(`${this.apiVersion}/products/${slug}`).pipe(map(data => data.deleted));
|
||||
}
|
||||
|
||||
save(product: Product): Observable<Product> {
|
||||
// If we're updating an existing product
|
||||
if (product.slug) {
|
||||
return this.apiService.put(`/products/${product.slug}`, { product: product }).pipe(map(data => data.product));
|
||||
return this.apiService.put(`${this.apiVersion}/products/${product.slug}`, { product: product }).pipe(map(data => data.product));
|
||||
|
||||
// Otherwise, create a new product
|
||||
} else {
|
||||
return this.apiService.post('/products/', { product: product }).pipe(map(data => data.product));
|
||||
return this.apiService.post(`${this.apiVersion}/products/`, { product: product }).pipe(map(data => data.product));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { ApiService } from 'src/app/core/services';
|
||||
import { Profile } from 'src/app/core/models';
|
||||
import { ApiService } from '@services';
|
||||
import { Profile } from '@models';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ProfilesService {
|
||||
private _apiVersion = '/v2';
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
|
||||
get(username: string): Observable<Profile> {
|
||||
return this.apiService.get('/profiles/' + username)
|
||||
return this.apiService.get(`${this._apiVersion}/profiles/${username}`)
|
||||
.pipe(map((data: { profile: Profile }) => data.profile));
|
||||
}
|
||||
|
||||
follow(username: string): Observable<Profile> {
|
||||
return this.apiService.post('/profiles/' + username + '/follow');
|
||||
return this.apiService.post(`${this._apiVersion}/profiles/${username}/follow`);
|
||||
}
|
||||
|
||||
unfollow(username: string): Observable<Profile> {
|
||||
return this.apiService.delete('/profiles/' + username + '/follow');
|
||||
return this.apiService.delete(`${this._apiVersion}/profiles/${username}/follow`);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-4
@@ -2,22 +2,23 @@ import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ApiService } from './api.service';
|
||||
import { AeronefByImat, AeronefByYear } from 'src/app/core/models';
|
||||
import { ApiService } from '../api.service';
|
||||
import { AeronefByImat, AeronefByYear } from '@models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AeronefsService {
|
||||
private _apiVersion = '/v1';
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
|
||||
getAllByImat(): Observable<Array<AeronefByImat>> {
|
||||
return this.apiService.get('/aeronefs/allByImat')
|
||||
return this.apiService.get(`${this._apiVersion}/aeronefs/allByImat`)
|
||||
.pipe(map(data => data.aeronefs));
|
||||
}
|
||||
|
||||
getAllByImatByYear(): Observable<Array<AeronefByYear>> {
|
||||
return this.apiService.get('/aeronefs/allByImatByYear')
|
||||
return this.apiService.get(`${this._apiVersion}/aeronefs/allByImatByYear`)
|
||||
.pipe(map(data => data.aeronefs));
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { CalculatorResult, WeightSizeRange, weightSizes } from 'src/app/core/models';
|
||||
import { UtilitiesService } from 'src/app/core/services';
|
||||
import { CalculatorResult, WeightSizeRange, weightSizes } from '@models';
|
||||
import { UtilitiesService } from '@services';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CalculatorService {
|
||||
+7
-6
@@ -2,32 +2,33 @@ import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ApiService } from './api.service';
|
||||
import { CanopyBySize, CanopyByYear, CanopyModelBySize, CanopyModelByYear } from 'src/app/core/models';
|
||||
import { ApiService } from '../api.service';
|
||||
import { CanopyBySize, CanopyByYear, CanopyModelBySize, CanopyModelByYear } from '@models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CanopiesService {
|
||||
private _apiVersion = '/v1';
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
|
||||
getAllBySize(): Observable<Array<CanopyBySize>> {
|
||||
return this.apiService.get('/canopies/allBySize')
|
||||
return this.apiService.get(`${this._apiVersion}/canopies/allBySize`)
|
||||
.pipe(map(data => data.canopies));
|
||||
}
|
||||
|
||||
getAllBySizeByYear(): Observable<Array<CanopyByYear>> {
|
||||
return this.apiService.get('/canopies/allBySizeByYear')
|
||||
return this.apiService.get(`${this._apiVersion}/canopies/allBySizeByYear`)
|
||||
.pipe(map(data => data.canopies));
|
||||
}
|
||||
|
||||
getAllBySizeByModel(): Observable<Array<CanopyModelBySize>> {
|
||||
return this.apiService.get('/canopies/allBySizeByModel')
|
||||
return this.apiService.get(`${this._apiVersion}/canopies/allBySizeByModel`)
|
||||
.pipe(map(data => data.canopies));
|
||||
}
|
||||
|
||||
getAllBySizeByModelByYear(): Observable<Array<CanopyModelByYear>> {
|
||||
return this.apiService.get('/canopies/allBySizeByModelByYear')
|
||||
return this.apiService.get(`${this._apiVersion}/canopies/allBySizeByModelByYear`)
|
||||
.pipe(map(data => data.canopies));
|
||||
}
|
||||
|
||||
+5
-4
@@ -2,22 +2,23 @@ import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ApiService } from './api.service';
|
||||
import { DropZoneByOaci, DropZoneByYear } from 'src/app/core/models';
|
||||
import { ApiService } from '../api.service';
|
||||
import { DropZoneByOaci, DropZoneByYear } from '@models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class DropZonesService {
|
||||
private _apiVersion = '/v1';
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
|
||||
getAllByOaci(): Observable<Array<DropZoneByOaci>> {
|
||||
return this.apiService.get('/dropzones/allByOaci')
|
||||
return this.apiService.get(`${this._apiVersion}/dropzones/allByOaci`)
|
||||
.pipe(map(data => data.dropzones));
|
||||
}
|
||||
|
||||
getAllByOaciByYear(): Observable<Array<DropZoneByYear>> {
|
||||
return this.apiService.get('/dropzones/allByOaciByYear')
|
||||
return this.apiService.get(`${this._apiVersion}/dropzones/allByOaciByYear`)
|
||||
.pipe(map(data => data.dropzones));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
export * from './aeronefs.service';
|
||||
export * from './calculator.service';
|
||||
export * from './canopies.service';
|
||||
export * from './dropzones.service';
|
||||
export * from './jumps.service';
|
||||
export * from './jump-table.service';
|
||||
export * from './qcm.service';
|
||||
+20
-19
@@ -3,15 +3,16 @@ import { HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ApiService } from './api.service';
|
||||
import { ApiService } from '../api.service';
|
||||
import {
|
||||
Jump, JumpByCategorie, JumpByDate, JumpByDay, JumpByModule, JumpFile,
|
||||
JumpList, JumpListConfig, JumpListFilters, JumpPageData,
|
||||
X2Data, SkydiverIdJumps
|
||||
} from 'src/app/core/models';
|
||||
} from '@models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class JumpsService {
|
||||
private _apiVersion = '/v1';
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
@@ -50,7 +51,7 @@ export class JumpsService {
|
||||
Object.assign(params, config.filters);
|
||||
return this.apiService
|
||||
.get(
|
||||
'/jumps' + ((config.type === 'feed') ? '/feed' : ''),
|
||||
`${this._apiVersion}/jumps` + ((config.type === 'feed') ? '/feed' : ''),
|
||||
new HttpParams({ fromObject: <{
|
||||
[param: string]: string | number | boolean | readonly (string | number | boolean)[];
|
||||
}>params })
|
||||
@@ -62,82 +63,82 @@ export class JumpsService {
|
||||
.pipe(map(data => {
|
||||
return { jump: data.jump, prevJump: data.prevJump, nextJump: data.nextJump };
|
||||
})); */
|
||||
return this.apiService.get(`/jumps/${slug}`);
|
||||
return this.apiService.get(`${this._apiVersion}/jumps/${slug}`);
|
||||
}
|
||||
|
||||
getAll(): Observable<Array<Jump>> {
|
||||
return this.apiService.get('/jumps').pipe(map(data => data.jumps));
|
||||
return this.apiService.get(`${this._apiVersion}/jumps`).pipe(map(data => data.jumps));
|
||||
}
|
||||
|
||||
getAllByDate(): Observable<Array<JumpByDate>> {
|
||||
return this.apiService.get('/jumps/allByDate').pipe(map(data => data.jumps));
|
||||
return this.apiService.get(`${this._apiVersion}/jumps/allByDate`).pipe(map(data => data.jumps));
|
||||
}
|
||||
|
||||
getAllByCategorie(): Observable<Array<JumpByCategorie>> {
|
||||
return this.apiService.get('/jumps/allByCategorie').pipe(map(data => data.jumps));
|
||||
return this.apiService.get(`${this._apiVersion}/jumps/allByCategorie`).pipe(map(data => data.jumps));
|
||||
}
|
||||
|
||||
getAllByDay(config: JumpListConfig): Observable<Array<JumpByDay>> {
|
||||
const params: JumpListFilters = {} as JumpListFilters;
|
||||
Object.assign(params, config.filters);
|
||||
return this.apiService.get('/jumps/allByDay', new HttpParams({ fromObject: <{
|
||||
return this.apiService.get(`${this._apiVersion}/jumps/allByDay`, new HttpParams({ fromObject: <{
|
||||
[param: string]: string | number | boolean | readonly (string | number | boolean)[];
|
||||
}>params }))
|
||||
.pipe(map(data => data.days));
|
||||
}
|
||||
|
||||
getAllByModule(): Observable<Array<JumpByModule>> {
|
||||
return this.apiService.get('/jumps/allByModule').pipe(map(data => data.jumps));
|
||||
return this.apiService.get(`${this._apiVersion}/jumps/allByModule`).pipe(map(data => data.jumps));
|
||||
}
|
||||
|
||||
getAllFromSkydiverIdApi(config: JumpListConfig): Observable<SkydiverIdJumps> {
|
||||
const params: JumpListFilters = {} as JumpListFilters;
|
||||
Object.assign(params, config.filters);
|
||||
return this.apiService.get('/jumps/allFromSkydiverIdApi', new HttpParams({ fromObject: <{
|
||||
return this.apiService.get(`${this._apiVersion}/jumps/allFromSkydiverIdApi`, new HttpParams({ fromObject: <{
|
||||
[param: string]: string | number | boolean | readonly (string | number | boolean)[];
|
||||
}>params }))
|
||||
.pipe(map(data => data.jumps));
|
||||
}
|
||||
|
||||
getLastJump(): Observable<Jump> {
|
||||
return this.apiService.get('/jumps/last').pipe(map(data => data.jump));
|
||||
return this.apiService.get(`${this._apiVersion}/jumps/last`).pipe(map(data => data.jump));
|
||||
}
|
||||
|
||||
create(jump: Jump): Observable<Jump> {
|
||||
return this.apiService.post('/jumps/', { jump: jump }).pipe(map(data => data.jump));
|
||||
return this.apiService.post(`${this._apiVersion}/jumps/`, { jump: jump }).pipe(map(data => data.jump));
|
||||
}
|
||||
|
||||
update(jump: Jump): Observable<Jump> {
|
||||
return this.apiService.put(`/jumps/${jump.slug}`, { jump: jump }).pipe(map(data => data.jump));
|
||||
return this.apiService.put(`${this._apiVersion}/jumps/${jump.slug}`, { jump: jump }).pipe(map(data => data.jump));
|
||||
}
|
||||
|
||||
destroy(slug: string): Observable<boolean> {
|
||||
return this.apiService.delete(`/jumps/${slug}`).pipe(map(data => data.deleted));
|
||||
return this.apiService.delete(`${this._apiVersion}/jumps/${slug}`).pipe(map(data => data.deleted));
|
||||
}
|
||||
|
||||
save(jump: Jump): Observable<Jump> {
|
||||
// If we're updating an existing jump
|
||||
if (jump.slug) {
|
||||
return this.apiService.put(`/jumps/${jump.slug}`, { jump: jump }).pipe(map(data => data.jump));
|
||||
return this.apiService.put(`${this._apiVersion}/jumps/${jump.slug}`, { jump: jump }).pipe(map(data => data.jump));
|
||||
|
||||
// Otherwise, create a new jump
|
||||
} else {
|
||||
return this.apiService.post('/jumps/', { jump: jump }).pipe(map(data => data.jump));
|
||||
return this.apiService.post(`${this._apiVersion}/jumps/`, { jump: jump }).pipe(map(data => data.jump));
|
||||
}
|
||||
}
|
||||
|
||||
saveX2Data(slug: string, file: JumpFile, data: X2Data): Observable<Jump> {
|
||||
return this.apiService.post(`/jumps/data/${slug}`, { file: file, data: data })
|
||||
return this.apiService.post(`${this._apiVersion}/jumps/data/${slug}`, { file: file, data: data })
|
||||
.pipe(map(data => data.jump));
|
||||
}
|
||||
|
||||
saveFile(slug: string, file: JumpFile): Observable<JumpFile> {
|
||||
return this.apiService.post(`/jumps/file/${slug}`, { file: file })
|
||||
return this.apiService.post(`${this._apiVersion}/jumps/file/${slug}`, { file: file })
|
||||
.pipe(map(data => data.file));
|
||||
}
|
||||
|
||||
saveKml(slug: string, file: JumpFile): Observable<JumpFile> {
|
||||
return this.apiService.post(`/jumps/kml/${slug}`, { file: file })
|
||||
return this.apiService.post(`${this._apiVersion}/jumps/kml/${slug}`, { file: file })
|
||||
.pipe(map(data => data.file));
|
||||
}
|
||||
|
||||
@@ -2,27 +2,27 @@ import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ApiService } from './api.service';
|
||||
import { Qcm, QcmCategory, QcmQuestion } from 'src/app/core/models';
|
||||
import { ApiService } from '../api.service';
|
||||
import { Qcm, QcmCategory, QcmQuestion } from '@models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class QcmService {
|
||||
|
||||
private _apiVersion = '/v1';
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
|
||||
get(type: string): Observable<Qcm> {
|
||||
return this.apiService.get(`/qcm/type/${type}`).pipe(map(data => data.qcm));
|
||||
return this.apiService.get(`${this._apiVersion}/qcm/type/${type}`).pipe(map(data => data.qcm));
|
||||
}
|
||||
|
||||
saveChoices(question: object): Observable<QcmQuestion> {
|
||||
return this.apiService.post('/qcm/choices', { question: question })
|
||||
return this.apiService.post(`${this._apiVersion}/qcm/choices`, { question: question })
|
||||
.pipe(map(data => data.question));
|
||||
}
|
||||
|
||||
saveQuestions(category: object): Observable<QcmCategory> {
|
||||
return this.apiService.post('/qcm/questions', { category: category })
|
||||
return this.apiService.post(`${this._apiVersion}/qcm/questions`, { category: category })
|
||||
.pipe(map(data => data.category));
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,8 @@ import { HttpClient } from "@angular/common/http";
|
||||
import { Observable, BehaviorSubject, ReplaySubject, Subscription } from 'rxjs';
|
||||
import { distinctUntilChanged, take, tap } from 'rxjs/operators';
|
||||
|
||||
import { User } from 'src/app/core/models';
|
||||
import { JwtService } from 'src/app/core/services';
|
||||
import { User } from '@models';
|
||||
import { JwtService } from '@services';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class UserService implements OnDestroy {
|
||||
@@ -17,6 +17,7 @@ export class UserService implements OnDestroy {
|
||||
public isAuthenticated = this.isAuthenticatedSubject.asObservable();
|
||||
|
||||
|
||||
private apiVersion = '/v2';
|
||||
constructor(
|
||||
private readonly http: HttpClient,
|
||||
private readonly jwtService: JwtService
|
||||
@@ -31,7 +32,7 @@ export class UserService implements OnDestroy {
|
||||
populate() {
|
||||
// If JWT detected, attempt to get & store user's info
|
||||
if (this.jwtService.getToken()) {
|
||||
const user$: Observable<{ user: User }> = this.http.get<{ user: User }>('/user').pipe(take(1));
|
||||
const user$: Observable<{ user: User }> = this.http.get<{ user: User }>(`${this.apiVersion}/user`).pipe(take(1));
|
||||
this._user = user$.subscribe({
|
||||
next: (data) => this.setAuth(data.user),
|
||||
error: () => this.purgeAuth()
|
||||
@@ -63,7 +64,7 @@ export class UserService implements OnDestroy {
|
||||
|
||||
attemptAuth(type: string, credentials?: { email: string; password: string; }): Observable<{ user: User }> {
|
||||
const route = (type === 'login') ? '/login' : '';
|
||||
const user$: Observable<{ user: User }> = this.http.post<{ user: User }>(`/user${route}`, { user: credentials });
|
||||
const user$: Observable<{ user: User }> = this.http.post<{ user: User }>(`${this.apiVersion}/user${route}`, { user: credentials });
|
||||
/*return user$.pipe(map(
|
||||
(data: any) => {
|
||||
this.setAuth(data.user);
|
||||
@@ -83,7 +84,7 @@ export class UserService implements OnDestroy {
|
||||
|
||||
// Update the user on the server (email, pass, etc)
|
||||
update(user: Partial<User>): Observable<{ user: User }> {
|
||||
return this.http.put<{ user: User }>("/user", { user }).pipe(
|
||||
return this.http.put<{ user: User }>(`${this.apiVersion}/user`, { user }).pipe(
|
||||
tap(({ user }) => {
|
||||
this.currentUserSubject.next(user);
|
||||
}),
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
|
||||
import { Chart } from 'chart.js';
|
||||
import { Configuration } from 'ng-chartist';
|
||||
|
||||
import { BarConfig, CircleConfig, DoughnutConfig, LineConfig } from 'src/app/core/models';
|
||||
import { BarConfig, CircleConfig, DoughnutConfig, LineConfig } from '@models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class UtilitiesService {
|
||||
|
||||
Reference in New Issue
Block a user