src/app/pages/services/config.service.ts
Config Service
Methods |
constructor(http: HttpClient, toastService: ToastService)
|
|||||||||
|
Defined in src/app/pages/services/config.service.ts:14
|
|||||||||
|
Parameters :
|
| Async getConfigByProjectIdClientId | ||||||
getConfigByProjectIdClientId(projectId, clientId)
|
||||||
|
Defined in src/app/pages/services/config.service.ts:49
|
||||||
|
Parameters :
Returns :
{}
|
| Private getConfigByProjectIdClientIdObservable | ||||||
getConfigByProjectIdClientIdObservable(projectId, clientId)
|
||||||
|
Defined in src/app/pages/services/config.service.ts:45
|
||||||
|
Parameters :
Returns :
Observable<Config>
|
| Async getGlobalConfigByClientId | ||||
getGlobalConfigByClientId(clientId)
|
||||
|
Defined in src/app/pages/services/config.service.ts:22
|
||||
|
Parameters :
Returns :
{}
|
| Private getGlobalConfigByClientIdObservable | ||||
getGlobalConfigByClientIdObservable(clientId)
|
||||
|
Defined in src/app/pages/services/config.service.ts:18
|
||||
|
Parameters :
Returns :
Observable<Config>
|
| postConfigByProjectIdAndClientId | ||||||||
postConfigByProjectIdAndClientId(projectId, clientId, payload)
|
||||||||
|
Defined in src/app/pages/services/config.service.ts:84
|
||||||||
|
Parameters :
Returns :
any
|
| postConfigByProjectIdAndClientIdAndUserId | ||||||||||
postConfigByProjectIdAndClientIdAndUserId(projectId, clientId, userId, payload)
|
||||||||||
|
Defined in src/app/pages/services/config.service.ts:92
|
||||||||||
|
Parameters :
Returns :
any
|
| postGlobalConfigByClientId | ||||||
postGlobalConfigByClientId(clientId, payload)
|
||||||
|
Defined in src/app/pages/services/config.service.ts:76
|
||||||
|
Parameters :
Returns :
any
|
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {Config} from '@app/pages/models/config';
import {ToastService} from '@app/shared/services/toast.service';
import {Observable} from 'rxjs';
import {environment} from "@environments/environment";
/**
* Config Service
*/
@Injectable({
providedIn: 'root'
})
export class ConfigService {
constructor(private http: HttpClient, private toastService: ToastService) { }
private getGlobalConfigByClientIdObservable(clientId): Observable<Config> {
return this.http.get<Config>(`${environment.backendUrl}/global/config/${clientId}`);
}
async getGlobalConfigByClientId(clientId) {
return await this.getGlobalConfigByClientIdObservable(clientId).toPromise()
.then((data: any) => {
const {config, defaults} = data;
config.forEach(c => {
if (defaults) {
const defaultValues = defaults.filter(d => d.name === c.name && d.scope === 'global');
if (defaultValues.length > 0) {
c.default = defaultValues[0].value;
}
}
});
this.toastService.showSuccess(`Configurations of Application: ${clientId} loaded.`);
return config;
})
.catch(e => {
this.toastService.showError(e);
console.log(e);
})
.finally(() => {});
}
private getConfigByProjectIdClientIdObservable(projectId, clientId): Observable<Config> {
return this.http.get<Config>(`/api/projects/${projectId}/config/${clientId}`);
}
async getConfigByProjectIdClientId(projectId, clientId) {
return await this.getConfigByProjectIdClientIdObservable(projectId, clientId).toPromise()
.then((data: any) => {
const {config, defaults} = data;
config.forEach(c => {
if (defaults) {
const defaultValues = defaults.filter(d => d.name === c.name && d.scope === 'global');
if (defaultValues.length > 0) {
c.default = defaultValues[0].value;
}
}
});
this.toastService.showSuccess(`Configurations of Project: ${projectId} - Application: ${clientId} loaded.`);
return config;
})
.catch(e => {
this.toastService.showError(e);
console.log(e);
})
.finally();
}
// private getConfigByProjectIdClientIdUserIdObservable(projectId, clientId, userId) {}
// getConfigByProjectIdClientIdUserId(projectId, clientId, userId) {}
postGlobalConfigByClientId(clientId, payload) {
return this.http.post(`/api/global/config/${clientId}`, payload, {
headers: {
'Content-Type': 'application/json'
}
});
}
postConfigByProjectIdAndClientId(projectId, clientId, payload) {
return this.http.post(`/api/projects/${projectId}/config/${clientId}`, payload, {
headers: {
'Content-Type': 'application/json'
}
});
}
postConfigByProjectIdAndClientIdAndUserId(projectId, clientId, userId, payload) {
return this.http.post(`/api/projects/${projectId}/users/${userId}/config/${clientId}`, payload, {
headers: {
'Content-Type': 'application/json'
}
});
}
}