This commit is contained in:
Timo Bejan 2023-06-26 23:15:35 +02:00
parent 75356e2328
commit 0ae0fa819e
6 changed files with 15 additions and 9 deletions

View File

@ -12,6 +12,7 @@ export class ApiPathInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> { intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
if (!req.url.startsWith('/assets')) { if (!req.url.startsWith('/assets')) {
const apiUrl = `${this.#config.API_URL}${req.url}`; const apiUrl = `${this.#config.API_URL}${req.url}`;
console.log('API URL: ', apiUrl);
return next.handle(req.clone({ url: apiUrl })); return next.handle(req.clone({ url: apiUrl }));
} }

View File

@ -28,6 +28,7 @@ export abstract class GenericService<I> {
[ROOT_CHANGES_KEY, new Date(Date.now() - LAST_CHECKED_OFFSET).toISOString()], [ROOT_CHANGES_KEY, new Date(Date.now() - LAST_CHECKED_OFFSET).toISOString()],
]); ]);
protected abstract readonly _defaultModelPath: string; protected abstract readonly _defaultModelPath: string;
protected readonly _serviceName: string = 'redaction-gateway-v1';
get<T = I[]>(): Observable<T>; get<T = I[]>(): Observable<T>;
get<T extends I[]>(): Observable<T>; get<T extends I[]>(): Observable<T>;
@ -41,7 +42,7 @@ export abstract class GenericService<I> {
getAll<R = I[]>(modelPath?: string, queryParams?: List<QueryParam>): Observable<R>; getAll<R = I[]>(modelPath?: string, queryParams?: List<QueryParam>): Observable<R>;
getAll<R = I[]>(modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<R> { getAll<R = I[]>(modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<R> {
this._updateLastChanged(); this._updateLastChanged();
return this._http.get<R>(`/${encodeURI(modelPath)}`, { return this._http.get<R>(`/${this._serviceName}/${encodeURI(modelPath)}`, {
headers: HeadersConfiguration.getHeaders({ contentType: false }), headers: HeadersConfiguration.getHeaders({ contentType: false }),
observe: 'body', observe: 'body',
params: this._queryParams(queryParams), params: this._queryParams(queryParams),
@ -54,10 +55,10 @@ export abstract class GenericService<I> {
} }
delete(body: unknown, modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<unknown> { delete(body: unknown, modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<unknown> {
let path = `/${encodeURI(modelPath)}`; let path = `/${this._serviceName}/${encodeURI(modelPath)}`;
if (typeof body === 'string') { if (typeof body === 'string') {
path += `/${encodeURIComponent(body)}`; path += `/${this._serviceName}/${encodeURIComponent(body)}`;
} }
return this._http.delete(path, { return this._http.delete(path, {
@ -77,7 +78,7 @@ export abstract class GenericService<I> {
const headers = HeadersConfiguration.getHeaders({ contentType: false }); const headers = HeadersConfiguration.getHeaders({ contentType: false });
return this._http.post<R>(`/${encodeURI(modelPath)}`, formParams, { return this._http.post<R>(`/${this._serviceName}/${encodeURI(modelPath)}`, formParams, {
headers, headers,
observe: 'events', observe: 'events',
reportProgress: true, reportProgress: true,
@ -93,7 +94,7 @@ export abstract class GenericService<I> {
} }
protected _post<R = I>(body: unknown, modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<R> { protected _post<R = I>(body: unknown, modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<R> {
return this._http.post<R>(`/${encodeURI(modelPath)}`, body, { return this._http.post<R>(`/${this._serviceName}/${encodeURI(modelPath)}`, body, {
params: this._queryParams(queryParams), params: this._queryParams(queryParams),
headers: HeadersConfiguration.getHeaders(), headers: HeadersConfiguration.getHeaders(),
observe: 'body', observe: 'body',
@ -101,7 +102,7 @@ export abstract class GenericService<I> {
} }
protected _put<R = I>(body: unknown, modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<R> { protected _put<R = I>(body: unknown, modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<R> {
return this._http.put<R>(`/${encodeURI(modelPath)}`, body, { return this._http.put<R>(`/${this._serviceName}/${encodeURI(modelPath)}`, body, {
params: this._queryParams(queryParams), params: this._queryParams(queryParams),
headers: HeadersConfiguration.getHeaders(), headers: HeadersConfiguration.getHeaders(),
observe: 'body', observe: 'body',
@ -111,7 +112,7 @@ export abstract class GenericService<I> {
protected _getOne<R = I>(path: List, modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<R> { protected _getOne<R = I>(path: List, modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<R> {
const entityPath = path.map(item => encodeURIComponent(item)).join('/'); const entityPath = path.map(item => encodeURIComponent(item)).join('/');
return this._http.get<R>(`/${encodeURI(modelPath)}/${entityPath}`, { return this._http.get<R>(`/${this._serviceName}/${encodeURI(modelPath)}/${entityPath}`, {
headers: HeadersConfiguration.getHeaders({ contentType: false }), headers: HeadersConfiguration.getHeaders({ contentType: false }),
params: this._queryParams(queryParams), params: this._queryParams(queryParams),
observe: 'body', observe: 'body',

View File

@ -13,6 +13,7 @@ const KEYS = {
@Injectable() @Injectable()
export abstract class IqserUserPreferenceService extends GenericService<UserAttributes> { export abstract class IqserUserPreferenceService extends GenericService<UserAttributes> {
protected abstract readonly _devFeaturesEnabledKey: string; protected abstract readonly _devFeaturesEnabledKey: string;
protected readonly _serviceName: string = 'tenant-user-management';
#userAttributes: UserAttributes = {}; #userAttributes: UserAttributes = {};
get userAttributes(): UserAttributes { get userAttributes(): UserAttributes {

View File

@ -9,12 +9,13 @@ export abstract class StatsService<E, I = E> {
protected abstract readonly _primaryKey: string; protected abstract readonly _primaryKey: string;
protected abstract readonly _entityClass: new (entityInterface: I, ...args: unknown[]) => E; protected abstract readonly _entityClass: new (entityInterface: I, ...args: unknown[]) => E;
protected abstract readonly _defaultModelPath: string; protected abstract readonly _defaultModelPath: string;
protected readonly _serviceName: string = 'redaction-gateway-v1';
readonly #http = inject(HttpClient); readonly #http = inject(HttpClient);
readonly #map = new Map<string, BehaviorSubject<E>>(); readonly #map = new Map<string, BehaviorSubject<E>>();
getFor(ids: string[]): Observable<E[]> { getFor(ids: string[]): Observable<E[]> {
const request = this.#http.post<I[]>(`/${encodeURI(this._defaultModelPath)}`, ids, { const request = this.#http.post<I[]>(`/${this._serviceName}/${encodeURI(this._defaultModelPath)}`, ids, {
headers: HeadersConfiguration.getHeaders(), headers: HeadersConfiguration.getHeaders(),
observe: 'body', observe: 'body',
}); });

View File

@ -32,6 +32,7 @@ const STORED_TENANTS_KEY = 'red-stored-tenants';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class TenantsService { export class TenantsService {
protected readonly _serviceName: string = 'tenant-user-management';
readonly tenants = signal<IBaseTenant[] | undefined>(undefined); readonly tenants = signal<IBaseTenant[] | undefined>(undefined);
readonly hasMultiple = computed(() => { readonly hasMultiple = computed(() => {
const tenants = this.tenants(); const tenants = this.tenants();
@ -60,7 +61,7 @@ export class TenantsService {
async loadTenants() { async loadTenants() {
this.#logger.info('[TENANTS] Loading tenants...'); this.#logger.info('[TENANTS] Loading tenants...');
const tenants = await firstValueFrom(this.#http.get<IBaseTenant[]>('/tenants/simple')); const tenants = await firstValueFrom(this.#http.get<IBaseTenant[]>(`/${this._serviceName}/tenants/simple`));
this.tenants.set(tenants); this.tenants.set(tenants);
const tenant = this.getTenantFromRoute(); const tenant = this.getTenantFromRoute();

View File

@ -36,6 +36,7 @@ export abstract class IqserUserService<
protected readonly _permissionsService = inject(IqserPermissionsService, { optional: true }); protected readonly _permissionsService = inject(IqserPermissionsService, { optional: true });
protected readonly _rolesService = inject(IqserRolesService, { optional: true }); protected readonly _rolesService = inject(IqserRolesService, { optional: true });
protected readonly _baseHref = inject(BASE_HREF); protected readonly _baseHref = inject(BASE_HREF);
protected readonly _serviceName: string = 'tenant-user-management';
constructor() { constructor() {
super(); super();