Get tenant details
This commit is contained in:
parent
9ce0ec27ca
commit
773171f4af
@ -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';
|
||||
|
||||
@ -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);
|
||||
|
||||
1
src/lib/tenants/types/index.ts
Normal file
1
src/lib/tenants/types/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './tenant';
|
||||
7
src/lib/tenants/types/tenant.ts
Normal file
7
src/lib/tenants/types/tenant.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export type TenantDetails = Record<string, unknown>;
|
||||
|
||||
export interface Tenant<TD extends TenantDetails = TenantDetails> {
|
||||
tenantId: string;
|
||||
displayName: string;
|
||||
details: TD;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user