import 'rxjs/add/operator/switchMap'; import { ActionsObservable, Epic } from 'redux-observable'; import { ActionTypes, RoleActions } from '../actions/role'; import { TenantActionTypes, TenantRoleActions } from '../actions/tenant'; import { assign } from 'lodash'; import { Dezrez } from '@dezrez/typings-rezi'; import { IAction } from '@dezrez/core'; import { IState } from '../store'; import { tenantRoleService } from '../services/tenantService'; import Role = Dezrez.Core.DataContracts.External.Api.Role.Query.Get.RoleDataContract; import TenantRole = Dezrez.Core.DataContracts.External.Api.Role.Query.Get.Group.TenantRoleDataContract; import SetRentCommand = Dezrez.Core.DataContracts.External.Api.Lettings.Command.UpdateRentAmountDataContract; const requirementsEpic: Epic = (action$, store) => action$.ofType(TenantActionTypes.UPDATEREQUIREMENTS) .mergeMap((action: IAction) => { const tenant = store.getState().role.Tenant; const newValue: TenantRole = assign(tenant, { Requirements: action.payload } as TenantRole); return tenantRoleService.updateRequirements(tenant.Id, newValue.Requirements) .map((role: Role) => RoleActions.store(newValue)); }); const rentDetailsEpic: Epic = (action$, store) => action$.ofType(TenantActionTypes.SETRENT) .mergeMap((action: IAction) => { const payload: SetRentCommand = action.payload; const tenant = store.getState().role.Tenant; const newValue: TenantRole = assign(tenant, { RentAmount: payload.RentAmount, RentSchedule: payload.RentSchedule, PriceType : payload.PriceType } as TenantRole); return tenantRoleService.setRent(tenant.Id, action.payload) .map((role: Role) => RoleActions.store(newValue)); }); export default [ requirementsEpic, rentDetailsEpic ];