@zeniai/client-epic-state 4.19.15 → 4.19.16
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.
|
@@ -9,48 +9,53 @@ const expenseAutomationViewReducer_1 = require("../../../view/expenseAutomationV
|
|
|
9
9
|
const zeniDayJS_1 = require("../../../zeniDayJS");
|
|
10
10
|
const companyReducer_1 = require("../../company/companyReducer");
|
|
11
11
|
const tenantReducer_1 = require("../tenantReducer");
|
|
12
|
-
const fetchAllTenantsEpic = (actions$, state, zeniAPI) =>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (currentTenantId != null) {
|
|
29
|
-
// filter out this tenant ID related company detail
|
|
30
|
-
// Find companyID for this tenant
|
|
31
|
-
const currentTenantPayload = response.data.tenants.find((tenant) => tenant.tenant_id === currentTenantId);
|
|
32
|
-
if (currentTenantPayload != null) {
|
|
33
|
-
companiesPayload = response.data.companies.filter((company) => company.company_id !== currentTenantPayload.company_id);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
console.warn('Selected tenant record not found in response', currentTenantId);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
actions = [
|
|
40
|
-
(0, companyReducer_1.updateCompanies)({
|
|
41
|
-
payload: companiesPayload,
|
|
42
|
-
schema: {},
|
|
12
|
+
const fetchAllTenantsEpic = (actions$, state, zeniAPI) => {
|
|
13
|
+
const queryParam = {
|
|
14
|
+
is_include_companies_in_response: false,
|
|
15
|
+
};
|
|
16
|
+
return actions$.pipe((0, operators_1.filter)(tenantReducer_1.fetchAllTenants.match), (0, operators_1.switchMap)((action) => zeniAPI
|
|
17
|
+
.getJSON(`${zeniAPI.apiEndPoints.tenantMicroServiceBaseUrl}/1.0/users/${action.payload.userId}/tenants?query=${encodeURIComponent(JSON.stringify(queryParam))}`, Object.assign({ 'zeni-user-id': action.payload.userId }, { 'zeni-tenant-id': '' }, action.payload.zeniSessionId != null
|
|
18
|
+
? { 'zeni-session-id': action.payload.zeniSessionId }
|
|
19
|
+
: {}))
|
|
20
|
+
.pipe((0, operators_1.mergeMap)((response) => {
|
|
21
|
+
const currentTenantId = state.value.tenantState.currentTenantId;
|
|
22
|
+
if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
|
|
23
|
+
const defaultSelectedPeriodsForTenants = (0, exports.getDefaultSelectedPeriodsForTenants)(response.data);
|
|
24
|
+
let actions = [
|
|
25
|
+
(0, tenantReducer_1.updateTenantsSuccess)(response.data),
|
|
26
|
+
(0, expenseAutomationViewReducer_1.initializeSelectedPeriodForTenants)({
|
|
27
|
+
selectedPeriodByTenantId: defaultSelectedPeriodsForTenants,
|
|
43
28
|
}),
|
|
44
|
-
...actions,
|
|
45
29
|
];
|
|
30
|
+
if (response.data.companies != null) {
|
|
31
|
+
let companiesPayload = response.data.companies;
|
|
32
|
+
if (currentTenantId != null) {
|
|
33
|
+
// filter out this tenant ID related company detail
|
|
34
|
+
// Find companyID for this tenant
|
|
35
|
+
const currentTenantPayload = response.data.tenants.find((tenant) => tenant.tenant_id === currentTenantId);
|
|
36
|
+
if (currentTenantPayload != null) {
|
|
37
|
+
companiesPayload = response.data.companies.filter((company) => company.company_id !== currentTenantPayload.company_id);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
console.warn('Selected tenant record not found in response', currentTenantId);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
actions = [
|
|
44
|
+
(0, companyReducer_1.updateCompanies)({
|
|
45
|
+
payload: companiesPayload,
|
|
46
|
+
schema: {},
|
|
47
|
+
}),
|
|
48
|
+
...actions,
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
return (0, rxjs_1.from)(actions);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return (0, rxjs_1.of)((0, tenantReducer_1.updateTenantsFailure)(response.status));
|
|
46
55
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return (0, rxjs_1.of)((0, tenantReducer_1.updateTenantsFailure)(response.status));
|
|
51
|
-
}
|
|
52
|
-
}), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, tenantReducer_1.updateTenantsFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected error', 'Fetch All Tenants REST API call errored out' +
|
|
53
|
-
JSON.stringify(error))))))));
|
|
56
|
+
}), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, tenantReducer_1.updateTenantsFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected error', 'Fetch All Tenants REST API call errored out' +
|
|
57
|
+
JSON.stringify(error))))))));
|
|
58
|
+
};
|
|
54
59
|
exports.fetchAllTenantsEpic = fetchAllTenantsEpic;
|
|
55
60
|
exports.defaultMonthYearPeriod = {
|
|
56
61
|
month: (0, timePeriod_1.toMonth)((0, zeniDayJS_1.dateNow)().get('month') + 1),
|