From 5d7c4e75072148e99ef87fa65e1100388cc92a7d Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Tue, 28 Jul 2020 15:16:23 +0300 Subject: [PATCH] feat(core): create multi-tenancy.service --- .../packages/core/src/lib/services/index.ts | 1 + .../src/lib/services/multi-tenancy.service.ts | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 npm/ng-packs/packages/core/src/lib/services/multi-tenancy.service.ts diff --git a/npm/ng-packs/packages/core/src/lib/services/index.ts b/npm/ng-packs/packages/core/src/lib/services/index.ts index e5e5286710..c084fd4808 100644 --- a/npm/ng-packs/packages/core/src/lib/services/index.ts +++ b/npm/ng-packs/packages/core/src/lib/services/index.ts @@ -6,6 +6,7 @@ export * from './dom-insertion.service'; export * from './lazy-load.service'; export * from './list.service'; export * from './localization.service'; +export * from './multi-tenancy.service'; export * from './profile-state.service'; export * from './profile.service'; export * from './rest.service'; diff --git a/npm/ng-packs/packages/core/src/lib/services/multi-tenancy.service.ts b/npm/ng-packs/packages/core/src/lib/services/multi-tenancy.service.ts new file mode 100644 index 0000000000..3a66a99311 --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/services/multi-tenancy.service.ts @@ -0,0 +1,45 @@ +import { Injectable } from '@angular/core'; +import { Store } from '@ngxs/store'; +import { Observable } from 'rxjs'; +import { SetTenant } from '../actions/session.actions'; +import { ABP } from '../models/common'; +import { FindTenantResultDto } from '../models/find-tenant-result-dto'; +import { RestService } from './rest.service'; + +@Injectable({ providedIn: 'root' }) +export class MultiTenancyService { + private _domainTenant: ABP.BasicItem = null; + + set domainTenant(value: ABP.BasicItem) { + this._domainTenant = value; + this.store.dispatch(new SetTenant(value)); + } + + get domainTenant() { + return this._domainTenant; + } + + isTenantBoxVisible = true; + + apiName = 'abp'; + + constructor(private restService: RestService, private store: Store) {} + + findTenantByName(name: string, headers: ABP.Dictionary): Observable { + return this.restService.request( + { + url: `/api/abp/multi-tenancy/tenants/by-name/${name}`, + method: 'GET', + headers, + }, + { apiName: this.apiName }, + ); + } + + findTenantById(id: string, headers: ABP.Dictionary): Observable { + return this.restService.request( + { url: `/api/abp/multi-tenancy/tenants/by-id/${id}`, method: 'GET', headers }, + { apiName: this.apiName }, + ); + } +}