feat: register pages routes guards.

feat: retrieve all organizations details to authenticated user.
feat: redux organization reducers and actions.
This commit is contained in:
Ahmed Bouhuolia
2020-10-11 00:08:51 +02:00
parent 8622320eef
commit 507690fedf
22 changed files with 348 additions and 66 deletions

View File

@@ -1,6 +1,6 @@
import { Service, Inject } from 'typedi';
import { ServiceError } from 'exceptions';
import { ITenant } from 'interfaces';
import { ISystemService, ISystemUser, ITenant } from 'interfaces';
import {
EventDispatcher,
EventDispatcherInterface,
@@ -38,7 +38,7 @@ export default class OrganizationService {
* @param {srting} organizationId
* @return {Promise<void>}
*/
async build(organizationId: string): Promise<void> {
public async build(organizationId: string): Promise<void> {
const tenant = await this.getTenantByOrgIdOrThrowError(organizationId);
this.throwIfTenantInitizalized(tenant);
@@ -69,7 +69,7 @@ export default class OrganizationService {
* @param {number} organizationId
* @return {Promise<void>}
*/
async seed(organizationId: string): Promise<void> {
public async seed(organizationId: string): Promise<void> {
const tenant = await this.getTenantByOrgIdOrThrowError(organizationId);
this.throwIfTenantSeeded(tenant);
@@ -91,6 +91,20 @@ export default class OrganizationService {
}
}
/**
* Listing all associated organizations to the given user.
* @param {ISystemUser} user -
* @return {Promise<void>}
*/
public async listOrganizations(user: ISystemUser): Promise<ITenant[]> {
this.logger.info('[organization] trying to list all organizations.', { user });
const { tenantRepository } = this.sysRepositories;
const tenant = await tenantRepository.getByIdWithSubscriptions(user.tenantId);
return [tenant];
}
/**
* Throws error in case the given tenant is undefined.
* @param {ITenant} tenant