Skip to content

Commit 2803642

Browse files
author
Abigail Cabascango
committed
refactor: TTA-164 create utils for effects
1 parent 3dc8359 commit 2803642

File tree

4 files changed

+80
-2
lines changed

4 files changed

+80
-2
lines changed

angular.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,13 @@
178178
},
179179
"defaultProject": "time-tracker",
180180
"cli": {
181-
"analytics": false
181+
"analytics": false,
182+
"defaultCollection":
183+
"@ngrx/schematics"
182184
},
183185
"schematics": {
184186
"@schematics/angular:component": {
185187
"styleext": "scss"
186188
}
187189
}
188-
}
190+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Action, createAction, props } from '@ngrx/store';
2+
3+
import { User } from '../users/models/users';
4+
import { Activity, ActivityStatus } from '../shared/models/activity.model';
5+
6+
export const LOAD_ACTIVITIES = '[ActivityManagement] LOAD_ACTIVITIES';
7+
export const LOAD_ACTIVITIES_SUCCESS = '[ActivityManagement] LOAD_ACTIVITIES_SUCCESS';
8+
export const LOAD_ACTIVITIES_FAIL = '[ActivityManagement] LOAD_ACTIVITIES_FAIL';
9+
export const CREATE_ACTIVITY = '[ActivityManagement] CREATE_ACTIVITY';
10+
export const CREATE_ACTIVITY_SUCCESS = '[ActivityManagement] CREATE_ACTIVITY_SUCCESS';
11+
export const CREATE_ACTIVITY_FAIL = '[ActivityManagement] CREATE_ACTIVITY_FAIL';
12+
export const ARCHIVE_ACTIVITY = '[ActivityManagement] ARCHIVE_ACTIVITY';
13+
export const ARCHIVE_ACTIVITY_SUCCESS = '[ActivityManagement] ARCHIVE_ACTIVITY_SUCCESS';
14+
export const ARCHIVE_ACTIVITY_FAIL = '[ActivityManagement] ARCHIVE_ACTIVITY_FAIL';
15+
export const UPDATE_ACTIVITY = '[ActivityManagement] UPDATE_ACTIVITY';
16+
export const UPDATE_ACTIVITY_SUCCESS = '[ActivityManagement] UPDATE_ACTIVITY_SUCCESS';
17+
export const UPDATE_ACTIVITY_FAIL = '[ActivityManagement] UPDATE_ACTIVITY_FAIL';
18+
export const UNARCHIVE_ACTIVITY = '[ActivityManagement] UNARCHIVE_ACTIVITY';
19+
export const UNARCHIVE_ACTIVITY_SUCCESS = '[ActivityManagement] UNARCHIVE_ACTIVITY_SUCCESS';
20+
export const UNARCHIVE_ACTIVITY_FAIL = '[ActivityManagement] UNARCHIVE_ACTIVITY_FAIL';
21+
export const SET_ACTIVITY_ID_TO_EDIT = '[ActivityManagement] SET_ACTIVITY_ID_TO_EDIT';
22+
export const RESET_ACTIVITY_ID_TO_EDIT = '[ActivityManagement] RESET_ACTIVITY_ID_TO_EDIT';
23+
export const DEFAULT_ACTIVITY = '[ActivityManagement] DEFAULT_ACTIVITY';
24+
25+
export class Load implements Action{
26+
public readonly type = LOAD_ACTIVITIES;
27+
}
28+
export const actionsBaseActionssSuccess = createAction(
29+
'[BaseActions] Actions BaseActionss Success',
30+
props<{ data: any }>()
31+
);
32+
33+
export const actionsBaseActionssFailure = createAction(
34+
'[BaseActions] Actions BaseActionss Failure',
35+
props<{ error: any }>()
36+
);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Functions } from './functions';
2+
3+
describe('Functions', () => {
4+
it('should create an instance', () => {
5+
expect(new Functions()).toBeTruthy();
6+
});
7+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ofType } from '@ngrx/effects';
2+
import { Action } from '@ngrx/store';
3+
import { Observable, of } from 'rxjs';
4+
import { ToastrService } from 'ngx-toastr';
5+
import { catchError, map, mergeMap } from 'rxjs/operators';
6+
7+
import { INFO_SAVED_SUCCESSFULLY } from '../messages';
8+
9+
10+
export class Functions {
11+
constructor(
12+
private toastrService: ToastrService
13+
) { }
14+
15+
getValue2<Actions>(value: Action) {
16+
const actions: Action;
17+
ofType(actions.ActivityManagementActionTypes.UPDATE_ACTIVITY),
18+
map((action: actions.UpdateActivity) => action.payload),
19+
mergeMap((activity) =>
20+
this.activityService.updateActivity(activity).pipe(
21+
map((activityData) => {
22+
this.toastrService.success(INFO_SAVED_SUCCESSFULLY);
23+
return new actions.UpdateActivitySuccess(activityData);
24+
}),
25+
catchError((error) => {
26+
this.toastrService.error(error.error.message);
27+
return of(new actions.UpdateActivityFail(error));
28+
})
29+
)
30+
)
31+
return value;
32+
}
33+
}

0 commit comments

Comments
 (0)