@zeniai/client-epic-state 4.11.54 → 4.11.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,5 +3,6 @@ import { ActionsObservable, StateObservable } from 'redux-observable';
3
3
  import { fetchAllTenants, updateTenantsSuccess, updateTenantsFailure } from '../tenantReducer';
4
4
  import { ZeniAPI } from '../../../zeniAPI';
5
5
  import { RootState } from '../../../reducer';
6
- export declare type ActionType = ReturnType<typeof fetchAllTenants> | ReturnType<typeof updateTenantsSuccess> | ReturnType<typeof updateTenantsFailure>;
7
- export declare const fetchAllTenantsEpic: (actions$: ActionsObservable<ActionType>, _: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
6
+ import { updateCompanies } from '../../company/companyReducer';
7
+ export declare type ActionType = ReturnType<typeof fetchAllTenants> | ReturnType<typeof updateCompanies> | ReturnType<typeof updateTenantsSuccess> | ReturnType<typeof updateTenantsFailure>;
8
+ export declare const fetchAllTenantsEpic: (actions$: ActionsObservable<ActionType>, state: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -5,15 +5,36 @@ const rxjs_1 = require("rxjs");
5
5
  const operators_1 = require("rxjs/operators");
6
6
  const tenantReducer_1 = require("../tenantReducer");
7
7
  const responsePayload_1 = require("../../../responsePayload");
8
- const fetchAllTenantsEpic = (actions$, _, zeniAPI) => actions$.pipe((0, operators_1.filter)(tenantReducer_1.fetchAllTenants.match), (0, operators_1.switchMap)((action) => zeniAPI
8
+ const companyReducer_1 = require("../../company/companyReducer");
9
+ const fetchAllTenantsEpic = (actions$, state, zeniAPI) => actions$.pipe((0, operators_1.filter)(tenantReducer_1.fetchAllTenants.match), (0, operators_1.switchMap)((action) => zeniAPI
9
10
  .getJSON(`${zeniAPI.apiEndPoints.tenantMicroServiceBaseUrl}/1.0/users/${action.payload.userId}/tenants`, Object.assign({ 'zeni-user-id': action.payload.userId }, { 'zeni-tenant-id': '' }, action.payload.zeniSessionId != null
10
11
  ? { 'zeni-session-id': action.payload.zeniSessionId }
11
12
  : {}))
12
13
  .pipe((0, operators_1.mergeMap)((response) => {
14
+ const currentTenantId = state.value.tenantState.currentTenantId;
13
15
  if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
14
- const actions = [
15
- (0, tenantReducer_1.updateTenantsSuccess)(response.data),
16
- ];
16
+ let actions = [(0, tenantReducer_1.updateTenantsSuccess)(response.data)];
17
+ if (response.data.companies != null) {
18
+ let companiesPayload = response.data.companies;
19
+ if (currentTenantId != null) {
20
+ // filter out this tenant ID related company detail
21
+ // Find companyID for this tenant
22
+ const currentTenantPayload = response.data.tenants.find((tenant) => tenant.tenant_id === currentTenantId);
23
+ if (currentTenantPayload != null) {
24
+ companiesPayload = response.data.companies.filter((company) => company.company_id !== currentTenantPayload.company_id);
25
+ }
26
+ else {
27
+ console.warn('Selected tenant record not found in response', currentTenantId);
28
+ }
29
+ }
30
+ actions = [
31
+ (0, companyReducer_1.updateCompanies)({
32
+ payload: companiesPayload,
33
+ schema: {},
34
+ }),
35
+ ...actions,
36
+ ];
37
+ }
17
38
  return (0, rxjs_1.from)(actions);
18
39
  }
19
40
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "4.11.54",
3
+ "version": "4.11.55",
4
4
  "description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",