Skip to content

Commit

Permalink
chore: improved ngrx naming
Browse files Browse the repository at this point in the history
  • Loading branch information
yosvelquintero committed Aug 25, 2023
1 parent b488809 commit 2612f64
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 41 deletions.
12 changes: 6 additions & 6 deletions packages/core/state/src/lib/+state/account/account.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const userFindByTokenSuccess = createAction(
props<{ payload: IUser | null }>()
);

export const userFindByTokenError = createAction(
'[ACCOUNT] Find user by token request error',
export const userFindByTokenFail = createAction(
'[ACCOUNT] Find user by token request fail',
props<{ error: string }>()
);

Expand All @@ -32,8 +32,8 @@ export const userMutateSuccess = createAction(
props<{ payload: IUser | null }>()
);

export const userMutateError = createAction(
'[ACCOUNT] User mutate request error',
export const userMutateFail = createAction(
'[ACCOUNT] User mutate request fail',
props<{ error: string }>()
);

Expand All @@ -46,8 +46,8 @@ export const userDeleteSuccess = createAction(
'[ACCOUNT] User delete request success'
);

export const userDeleteError = createAction(
'[ACCOUNT] User delete request error',
export const userDeleteFail = createAction(
'[ACCOUNT] User delete request fail',
props<{ error: string }>()
);

Expand Down
9 changes: 6 additions & 3 deletions packages/core/state/src/lib/+state/account/account.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class AccountEffects {
});
}),
catchError((error: Error) =>
of(accountActions.userFindByTokenError({ error: error.message }))
of(accountActions.userFindByTokenFail({ error: error.message }))
)
)
)
Expand All @@ -57,7 +57,7 @@ export class AccountEffects {
});
}),
catchError((error: Error) =>
of(accountActions.userMutateError({ error: error.message }))
of(accountActions.userMutateFail({ error: error.message }))
)
)
)
Expand All @@ -67,7 +67,10 @@ export class AccountEffects {
handleNotificationErrors$ = createEffect(
() => {
return this.actions$.pipe(
ofType(accountActions.userFindByTokenError),
ofType(
accountActions.userFindByTokenFail,
accountActions.userMutateFail
),
tap(({ error }) => {
this.appFacade.addNotification({
content: error ?? 'unknown error',
Expand Down
6 changes: 3 additions & 3 deletions packages/core/state/src/lib/+state/account/account.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const reducer = createReducer<IAccountState>(
})
),
on(
accountActions.userFindByTokenError,
accountActions.userFindByTokenFail,
(state, { error }): IAccountState => ({
...state,
actionStatus: EActionStatus.FAILED,
Expand Down Expand Up @@ -64,7 +64,7 @@ const reducer = createReducer<IAccountState>(
})
),
on(
accountActions.userMutateError,
accountActions.userMutateFail,
(state, { error }): IAccountState => ({
...state,
actionStatus: EActionStatus.FAILED,
Expand All @@ -88,7 +88,7 @@ const reducer = createReducer<IAccountState>(
})
),
on(
accountActions.userDeleteError,
accountActions.userDeleteFail,
(state, { error }): IAccountState => ({
...state,
actionStatus: EActionStatus.FAILED,
Expand Down
20 changes: 10 additions & 10 deletions packages/core/state/src/lib/+state/authn/authn.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export const signUpRequest = createAction(

export const signUpSuccess = createAction('[AUTHN] Sign up request success');

export const signUpError = createAction(
'[AUTHN] Sign up request error',
export const signUpFail = createAction(
'[AUTHN] Sign up request fail',
props<{ error: string }>()
);

Expand All @@ -27,8 +27,8 @@ export const activateRequest = createAction(

export const activateSuccess = createAction('[AUTHN] Activate request success');

export const activateError = createAction(
'[AUTHN] Activate request error',
export const activateFail = createAction(
'[AUTHN] Activate request fail',
props<{ error: string }>()
);

Expand All @@ -42,8 +42,8 @@ export const signInSuccess = createAction(
props<{ payload: IAuthnStateData }>()
);

export const signInError = createAction(
'[AUTHN] Sign in request error',
export const signInFail = createAction(
'[AUTHN] Sign in request fail',
props<{ error: string }>()
);

Expand All @@ -56,8 +56,8 @@ export const passwordRecoverySuccess = createAction(
'[AUTHN] Password recovery request success'
);

export const passwordRecoveryError = createAction(
'[AUTHN] Password recovery request error',
export const passwordRecoveryFail = createAction(
'[AUTHN] Password recovery request fail',
props<{ error: string }>()
);

Expand All @@ -70,8 +70,8 @@ export const confirmPasswordSuccess = createAction(
'[AUTHN] Confirm password change request success'
);

export const confirmPasswordError = createAction(
'[AUTHN] Confirm password change request error',
export const confirmPasswordFail = createAction(
'[AUTHN] Confirm password change request fail',
props<{ error: string }>()
);

Expand Down
28 changes: 14 additions & 14 deletions packages/core/state/src/lib/+state/authn/authn.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export class AuthnEffects {
const { code, message } =
data?.identity?.user.Register?.details?.status || {};
if (code !== 200) {
return authnActions.signUpError({
return authnActions.signUpFail({
error: message ?? 'sign up failed',
});
}

return authnActions.signUpSuccess();
}),
catchError((error: Error) =>
of(authnActions.signUpError({ error: error.message }))
of(authnActions.signUpFail({ error: error.message }))
)
)
)
Expand Down Expand Up @@ -67,15 +67,15 @@ export class AuthnEffects {
const { code, message } =
data?.identity?.user?.Activate?.details?.operationStatus || {};
if (code !== 200) {
return authnActions.activateError({
return authnActions.activateFail({
error: message ?? 'activation failed',
});
}

return authnActions.activateSuccess();
}),
catchError((error: Error) =>
of(authnActions.activateError({ error: error.message }))
of(authnActions.activateFail({ error: error.message }))
)
)
)
Expand Down Expand Up @@ -124,7 +124,7 @@ export class AuthnEffects {
),
catchError((error: Error) => {
return of(
authnActions.signInError({
authnActions.signInFail({
error: error.message.includes('401')
? 'sign in failed'
: error.message,
Expand Down Expand Up @@ -166,15 +166,15 @@ export class AuthnEffects {
data?.identity?.user?.RequestPasswordChange?.details
?.operationStatus || {};
if (code !== 200) {
return authnActions.passwordRecoveryError({
return authnActions.passwordRecoveryFail({
error: message ?? 'password recovery failed',
});
}

return authnActions.passwordRecoverySuccess();
}),
catchError((error: Error) =>
of(authnActions.passwordRecoveryError({ error: error.message }))
of(authnActions.passwordRecoveryFail({ error: error.message }))
)
)
)
Expand Down Expand Up @@ -211,7 +211,7 @@ export class AuthnEffects {
data?.identity?.user?.ConfirmPasswordChange?.details
?.operationStatus || {};
if (code !== 200) {
return authnActions.confirmPasswordError({
return authnActions.confirmPasswordFail({
error: message ?? 'password recovery failed',
});
}
Expand All @@ -220,7 +220,7 @@ export class AuthnEffects {
}),
catchError((error: Error) =>
of(
authnActions.confirmPasswordError({
authnActions.confirmPasswordFail({
error: error.message,
})
)
Expand Down Expand Up @@ -277,11 +277,11 @@ export class AuthnEffects {
() => {
return this.actions$.pipe(
ofType(
authnActions.signUpError,
authnActions.activateError,
authnActions.signInError,
authnActions.passwordRecoveryError,
authnActions.confirmPasswordError
authnActions.signUpFail,
authnActions.activateFail,
authnActions.signInFail,
authnActions.passwordRecoveryFail,
authnActions.confirmPasswordFail
),
tap(({ error }) => {
this.appFacade.addNotification({
Expand Down
10 changes: 5 additions & 5 deletions packages/core/state/src/lib/+state/authn/authn.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const reducer = createReducer<IAuthnState>(
})
),
on(
authnActions.signUpError,
authnActions.signUpFail,
(state, { error }): IAuthnState => ({
...state,
actionStatus: EActionStatus.FAILED,
Expand All @@ -56,7 +56,7 @@ const reducer = createReducer<IAuthnState>(
})
),
on(
authnActions.activateError,
authnActions.activateFail,
(state, { error }): IAuthnState => ({
...state,
actionStatus: EActionStatus.FAILED,
Expand All @@ -82,7 +82,7 @@ const reducer = createReducer<IAuthnState>(
})
),
on(
authnActions.signInError,
authnActions.signInFail,
(state, { error }): IAuthnState => ({
...state,
isAuthenticated: false,
Expand All @@ -107,7 +107,7 @@ const reducer = createReducer<IAuthnState>(
})
),
on(
authnActions.passwordRecoveryError,
authnActions.passwordRecoveryFail,
(state, { error }): IAuthnState => ({
...state,
actionStatus: EActionStatus.FAILED,
Expand All @@ -131,7 +131,7 @@ const reducer = createReducer<IAuthnState>(
})
),
on(
authnActions.confirmPasswordError,
authnActions.confirmPasswordFail,
(state, { error }): IAuthnState => ({
...state,
actionStatus: EActionStatus.FAILED,
Expand Down

0 comments on commit 2612f64

Please sign in to comment.