Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return this.organizationService.getAllServiceLimits().pipe(
map(mapOfLimits =>
Object.keys(mapOfLimits).reduce((acc, organizationId) => {
acc.push(ServiceLimitsConverter.fromDto(organizationId, mapOfLimits[organizationId]));
return acc;
}, [])
),
map(serviceLimits => new ServiceLimitsAction.GetAllSuccess({allServiceLimits: serviceLimits})),
catchError(error => of(new ServiceLimitsAction.GetAllFailure({error: error})))
);
})
);
@Effect()
public getAllFailure$: Observable = this.actions$.pipe(
ofType(ServiceLimitsActionType.GET_ALL_FAILURE),
tap(action => console.error(action.payload.error)),
map(() => {
const message = this.i18n({
id: 'organization.serviceLimits.getAll.fail',
value: 'Could not read information about your service levels and subscriptions',
});
return new NotificationsAction.Error({message});
})
);
@Effect()
public getServiceLimits$: Observable = this.actions$.pipe(
ofType(ServiceLimitsActionType.GET_SERVICE_LIMITS),
mergeMap(action => {
return this.organizationService.getServiceLimits(action.payload.organizationId).pipe(
map(dto => ServiceLimitsConverter.fromDto(action.payload.organizationId, dto)),
@Effect()
loadAllCourses$ = this.actions$
.pipe(
ofType(CourseActionTypes.AllCoursesRequested),
withLatestFrom(this.store.pipe(select(allCoursesLoaded))),
filter(([action, allCoursesLoaded]) => !allCoursesLoaded),
mergeMap(() => this.coursesService.findAllCourses()),
map(courses => new AllCoursesLoaded({courses}))
);
@Effect()
loadLessonsPage$ = this.actions$
.pipe(
ofType(CourseActionTypes.LessonsPageRequested),
mergeMap(({payload}) =>
this.coursesService.findLessons(payload.courseId,
payload.page.pageIndex, payload.page.pageSize)
.pipe(
catchError(err => {
console.log('error loading a lessons page ', err);
this.store.dispatch(new LessonsPageCancelled());
return of([]);
})
)
),
map(lessons => new LessonsPageLoaded({lessons}))
);
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Action } from '@ngrx/store';
import { Observable, of } from 'rxjs';
import { catchError, map, mergeMap } from 'rxjs/operators';
import * as actions from '@app/store/actions/_index';
import * as actionTypes from '@app/store/action-types';
import * as services from '@app/services/_index';
@Injectable()
export class GetStateEffect {
@Effect() getState$: Observable = this.actions$.pipe(
ofType(actionTypes.GET_STATE),
mergeMap((action: actions.GetStateAction) =>
this.backendService.getState(action.payload).pipe(
map(body => new actions.GetStateSuccessAction(body.payload)),
catchError(e => of(new actions.GetStateFailAction({ error: e })))
)
)
);
constructor(
private actions$: Actions,
private backendService: services.BackendService
) {}
}
loadDishes$ = createEffect(() =>
this.actions$.pipe(
ofType(loadMenusActions.loadMenus),
map((action) => action.filter),
mergeMap((filter) =>
this.menuService.getDishes(filter).pipe(
map((result) => {
const content = result.content.map((d) => {
d.extras.map((e) => {
e.selected = false;
return e;
});
return d;
});
const resultAdapted = { pageable: result.pageable, content };
return loadMenusActions.loadMenusSuccess(resultAdapted);
}),
catchError((error) =>
of(loadMenusActions.loadMenusFail({ error: error })),
@Injectable()
export class LeaderEffects {
@Effect() $createLeader: Observable = this.$actions.pipe(
ofType(LeaderActionTypes.LEADER_CREATE),
mergeMap((action: CreateLeader) =>
this.leaderService.createLeader(action.payload).pipe(
map(data => new CreateLeaderSuccess(data)),
catchError(err => of(new CreateLeaderFail(err)))
)
)
);
@Effect() $loadLeader: Observable = this.$actions.pipe(
ofType(LeaderActionTypes.LEADER_LOAD),
mergeMap((action: LoadLeader) =>
this.leaderService.getLeader(action.payload).pipe(
map(data => new LoadLeaderSuccess(data)),
catchError(err => of(new LoadLeaderFail(err)))
)
)
);
@Effect() $updateLeader: Observable = this.$actions.pipe(
ofType(LeaderActionTypes.LEADER_UPDATE),
mergeMap((action: UpdateLeader) =>
this.leaderService.updateLeader(action.payload).pipe(
map(data => {
this.leaderService.gotoLeaderView(data);
return new UpdateLeaderSuccess(data);
}),
() =>
this.actions$.pipe(
ofType(RouterActions.routerNavigation),
tap(({ event, routerState }) => {
this.appService.scrollToTop(false);
}),
),
{ dispatch: false },
import { EMPTY } from 'rxjs';
import { AlarmsFacade } from './alarms.facade';
import { AuthFacade } from '../../../+state/auth.facade';
@Injectable()
export class AlarmsEffects {
@Effect()
loadAlarms$ = this.actions$.pipe(
ofType(AlarmsActionTypes.LoadAlarms),
map(() => new AlarmsLoaded([]))
);
@Effect()
persistOnAdditionAndDeletion$ = this.actions$.pipe(
ofType(AlarmsActionTypes.AddAlarms),
mergeMap(() => EMPTY)
);
@Effect()
persistAlarms$ = this.actions$.pipe(
ofType(AlarmsActionTypes.PersistAlarms),
withLatestFrom(this.authFacade.userId$, this.alarmsFacade.allAlarms$),
map(([, userId, alarms]) => {
return alarms.map(alarm => {
return { ...alarm, foreignKey: userId };
});
}),
mergeMap(() => EMPTY)
);
constructor(private actions$: Actions, private alarmsFacade: AlarmsFacade, private authFacade: AuthFacade) {
}),
map(removedTemplate => new templateActions.RemoveTemplateSuccess(removedTemplate)),
catchError((error: Error) => {
const message = isIso
? 'NOTIFICATIONS.ISO.DELETION_FAILED'
: 'NOTIFICATIONS.TEMPLATE.DELETION_FAILED';
this.dialogService.showNotificationsOnFail(error, message, notificationId);
return of(new templateActions.RemoveTemplateError(error));
}),
);
}),
);
@Effect({ dispatch: false })
removeTemplateSuccess$: Observable = this.actions$.pipe(
ofType(templateActions.TEMPLATE_REMOVE_SUCCESS),
map((action: templateActions.RemoveTemplateSuccess) => action.payload),
filter((template: BaseTemplateModel) => {
return this.router.isActive(`/templates/${getPath(template)}/${template.id}`, false);
}),
tap(() => {
this.router.navigate(['./templates'], {
queryParamsHandling: 'preserve',
});
}),
);
@Effect()
registerTemplate$: Observable = this.actions$.pipe(
ofType(templateActions.TEMPLATE_REGISTER),
switchMap((action: templateActions.RegisterTemplate) => {
const isIso = action.payload.entity === templateResourceType.iso;
import { map, take } from 'rxjs/operators';
import { ActionHistoryActions, ActionHistoryDump } from '../actions/action-history.actions';
import { InternalAppState } from '../app-state';
@Injectable()
export class ActionHistoryEffect {
constructor(
private actions$: Actions,
private store: Store,
) { }
@Effect({ dispatch: false }) dumpActionHistory$ = this.actions$.pipe(
ofType(ActionHistoryActions.DUMP),
map(() => {
this.store.select('actionHistory').pipe(
take(1))
.subscribe();
}));
}
@Effect()
public updatePart$: Observable = this.actions$.pipe(
ofType(SmartDocActionType.UPDATE_PART),
withLatestFrom(this.store$.select(selectViewSmartDocConfig)),
map(([action, smartDocConfig]) => {
const config = SmartDocEffects.modifyInnerSmartDoc(smartDocConfig, action.payload.partPath, innerSmartDoc => {
innerSmartDoc.parts.splice(action.payload.partIndex, 1, action.payload.part);
return innerSmartDoc;
});
return new ViewsAction.ChangeSmartDocConfig({config});
})
);
@Effect()
public removePart$: Observable = this.actions$.pipe(
ofType(SmartDocActionType.REMOVE_PART),
withLatestFrom(this.store$.select(selectViewSmartDocConfig)),
flatMap(([action, smartDocConfig]) => {
const config = SmartDocEffects.modifyInnerSmartDoc(smartDocConfig, action.payload.partPath, innerSmartDoc => {
innerSmartDoc.parts.splice(action.payload.partIndex, 1);
return innerSmartDoc;
});
const actions: Action[] = [new ViewsAction.ChangeSmartDocConfig({config})];
if (action.payload.last) {
const part = SmartDocUtils.createEmptyTextPart();
actions.push(new SmartDocAction.AddPart({partPath: action.payload.partPath, part}));
}
return actions;
})
);