Get tenant details

This commit is contained in:
Adina Țeudan 2024-01-31 11:40:09 +02:00
parent 9ce0ec27ca
commit 773171f4af
4 changed files with 19 additions and 1 deletions

View File

@ -3,3 +3,4 @@ export * from './services';
export * from './tenants.module';
export * from './tenant-select/tenant-select.component';
export * from './services/keycloak-status.service';
export * from './types';

View File

@ -2,6 +2,9 @@ import { inject, Injectable, signal } from '@angular/core';
import dayjs from 'dayjs';
import { NGXLogger } from 'ngx-logger';
import { List } from '../../utils';
import { GenericService } from '../../services';
import { Tenant } from '../types';
import { Observable } from 'rxjs';
export interface IStoredTenantId {
readonly tenantId: string;
@ -13,7 +16,7 @@ export type StoredTenantIds = List<IStoredTenantId>;
const STORED_TENANTS_KEY = 'red-stored-tenants';
@Injectable({ providedIn: 'root' })
export class TenantsService {
export class TenantsService extends GenericService<Tenant> {
readonly #logger = inject(NGXLogger);
readonly #storageReference: Storage = {
length: localStorage.length,
@ -24,6 +27,8 @@ export class TenantsService {
key: localStorage.key.bind(localStorage),
};
readonly #activeTenantId = signal('');
protected readonly _defaultModelPath = 'tenants';
protected readonly _serviceName: string = 'tenant-user-management';
get activeTenantId() {
@ -96,6 +101,10 @@ export class TenantsService {
this.#logger.info('[TENANTS] Stored tenants at logout: ', storedTenants);
}
getActiveTenant<TD extends Record<string, unknown>>(): Observable<Tenant<TD>> {
return this._getOne([this.activeTenantId]);
}
#setActiveTenantId(tenantId: string) {
this.#logger.info('[TENANTS] Set current tenant id: ', tenantId);
this.#activeTenantId.set(tenantId);

View File

@ -0,0 +1 @@
export * from './tenant';

View File

@ -0,0 +1,7 @@
export type TenantDetails = Record<string, unknown>;
export interface Tenant<TD extends TenantDetails = TenantDetails> {
tenantId: string;
displayName: string;
details: TD;
}