From 38d18b32fd49ee2ccffaca4599060332900b3fbb Mon Sep 17 00:00:00 2001 From: TheDiaval Date: Fri, 9 Aug 2019 15:04:07 +0300 Subject: [PATCH] refactor(identity): rename actions and service functions --- .../src/lib/actions/identity.actions.ts | 26 +++--- .../lib/components/roles/roles.component.ts | 18 ++-- .../lib/components/users/users.component.ts | 24 +++--- .../src/lib/resolvers/roles.resolver.ts | 4 +- .../src/lib/resolvers/users.resolver.ts | 4 +- .../src/lib/services/identity.service.ts | 4 +- .../identity/src/lib/states/identity.state.ts | 82 +++++++++---------- 7 files changed, 78 insertions(+), 84 deletions(-) diff --git a/npm/ng-packs/packages/identity/src/lib/actions/identity.actions.ts b/npm/ng-packs/packages/identity/src/lib/actions/identity.actions.ts index 03a99aab83..3c24b58136 100644 --- a/npm/ng-packs/packages/identity/src/lib/actions/identity.actions.ts +++ b/npm/ng-packs/packages/identity/src/lib/actions/identity.actions.ts @@ -1,57 +1,57 @@ import { Identity } from '../models/identity'; import { ABP } from '@abp/ng.core'; -export class IdentityGetRoles { +export class GetRoles { static readonly type = '[Identity] Get Roles'; constructor(public payload?: ABP.PageQueryParams) {} } -export class IdentityGetRoleById { +export class GetRoleById { static readonly type = '[Identity] Get Role By Id'; constructor(public payload: string) {} } -export class IdentityDeleteRole { +export class DeleteRole { static readonly type = '[Identity] Delete Role'; constructor(public payload: string) {} } -export class IdentityAddRole { - static readonly type = '[Identity] Add Role'; +export class CreateRole { + static readonly type = '[Identity] Create Role'; constructor(public payload: Identity.RoleSaveRequest) {} } -export class IdentityUpdateRole { +export class UpdateRole { static readonly type = '[Identity] Update Role'; constructor(public payload: Identity.RoleItem) {} } -export class IdentityGetUsers { +export class GetUsers { static readonly type = '[Identity] Get Users'; constructor(public payload?: ABP.PageQueryParams) {} } -export class IdentityGetUserById { +export class GetUserById { static readonly type = '[Identity] Get User By Id'; constructor(public payload: string) {} } -export class IdentityDeleteUser { +export class DeleteUser { static readonly type = '[Identity] Delete User'; constructor(public payload: string) {} } -export class IdentityAddUser { - static readonly type = '[Identity] Add User'; +export class CreateUser { + static readonly type = '[Identity] Create User'; constructor(public payload: Identity.UserSaveRequest) {} } -export class IdentityUpdateUser { +export class UpdateUser { static readonly type = '[Identity] Update User'; constructor(public payload: Identity.UserSaveRequest & { id: string }) {} } -export class IdentityGetUserRoles { +export class GetUserRoles { static readonly type = '[Identity] Get User Roles'; constructor(public payload: string) {} } diff --git a/npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.ts b/npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.ts index 2b6d72f4ff..6ee14134af 100644 --- a/npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.ts +++ b/npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.ts @@ -5,13 +5,7 @@ import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms' import { Select, Store } from '@ngxs/store'; import { Observable } from 'rxjs'; import { finalize, pluck } from 'rxjs/operators'; -import { - IdentityAddRole, - IdentityDeleteRole, - IdentityGetRoleById, - IdentityGetRoles, - IdentityUpdateRole, -} from '../../actions/identity.actions'; +import { CreateRole, DeleteRole, GetRoleById, GetRoles, UpdateRole } from '../../actions/identity.actions'; import { Identity } from '../../models/identity'; import { IdentityState } from '../../states/identity.state'; @@ -75,7 +69,7 @@ export class RolesComponent { onEdit(id: string) { this.store - .dispatch(new IdentityGetRoleById(id)) + .dispatch(new GetRoleById(id)) .pipe(pluck('IdentityState', 'selectedRole')) .subscribe(selectedRole => { this.selected = selectedRole; @@ -89,8 +83,8 @@ export class RolesComponent { this.store .dispatch( this.selected.id - ? new IdentityUpdateRole({ ...this.form.value, id: this.selected.id }) - : new IdentityAddRole(this.form.value), + ? new UpdateRole({ ...this.form.value, id: this.selected.id }) + : new CreateRole(this.form.value), ) .subscribe(() => { this.isModalVisible = false; @@ -104,7 +98,7 @@ export class RolesComponent { }) .subscribe((status: Toaster.Status) => { if (status === Toaster.Status.confirm) { - this.store.dispatch(new IdentityDeleteRole(id)); + this.store.dispatch(new DeleteRole(id)); } }); } @@ -119,7 +113,7 @@ export class RolesComponent { get() { this.loading = true; this.store - .dispatch(new IdentityGetRoles(this.pageQuery)) + .dispatch(new GetRoles(this.pageQuery)) .pipe(finalize(() => (this.loading = false))) .subscribe(); } diff --git a/npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts b/npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts index ed63c8acb5..cfecf8a7af 100644 --- a/npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts +++ b/npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts @@ -7,12 +7,12 @@ import { Observable } from 'rxjs'; import { finalize, pluck, switchMap, take } from 'rxjs/operators'; import snq from 'snq'; import { - IdentityAddUser, - IdentityDeleteUser, - IdentityGetUserById, - IdentityGetUserRoles, - IdentityGetUsers, - IdentityUpdateUser, + CreateUser, + DeleteUser, + GetUserById, + GetUserRoles, + GetUsers, + UpdateUser, } from '../../actions/identity.actions'; import { Identity } from '../../models/identity'; import { IdentityState } from '../../states/identity.state'; @@ -99,9 +99,9 @@ export class UsersComponent { onEdit(id: string) { this.store - .dispatch(new IdentityGetUserById(id)) + .dispatch(new GetUserById(id)) .pipe( - switchMap(() => this.store.dispatch(new IdentityGetUserRoles(id))), + switchMap(() => this.store.dispatch(new GetUserRoles(id))), pluck('IdentityState'), take(1), ) @@ -124,12 +124,12 @@ export class UsersComponent { this.store .dispatch( this.selected.id - ? new IdentityUpdateUser({ + ? new UpdateUser({ ...this.form.value, id: this.selected.id, roleNames: mappedRoleNames, }) - : new IdentityAddUser({ + : new CreateUser({ ...this.form.value, roleNames: mappedRoleNames, }), @@ -146,7 +146,7 @@ export class UsersComponent { }) .subscribe((status: Toaster.Status) => { if (status === Toaster.Status.confirm) { - this.store.dispatch(new IdentityDeleteUser(id)); + this.store.dispatch(new DeleteUser(id)); } }); } @@ -161,7 +161,7 @@ export class UsersComponent { get() { this.loading = true; this.store - .dispatch(new IdentityGetUsers(this.pageQuery)) + .dispatch(new GetUsers(this.pageQuery)) .pipe(finalize(() => (this.loading = false))) .subscribe(); } diff --git a/npm/ng-packs/packages/identity/src/lib/resolvers/roles.resolver.ts b/npm/ng-packs/packages/identity/src/lib/resolvers/roles.resolver.ts index 1d9416d28c..8e7a556989 100644 --- a/npm/ng-packs/packages/identity/src/lib/resolvers/roles.resolver.ts +++ b/npm/ng-packs/packages/identity/src/lib/resolvers/roles.resolver.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { Resolve } from '@angular/router'; import { Store } from '@ngxs/store'; -import { IdentityGetRoles } from '../actions/identity.actions'; +import { GetRoles } from '../actions/identity.actions'; import { Identity } from '../models/identity'; import { IdentityState } from '../states/identity.state'; @@ -11,6 +11,6 @@ export class RoleResolver implements Resolve { resolve() { const roles = this.store.selectSnapshot(IdentityState.getRoles); - return roles && roles.length ? null : this.store.dispatch(new IdentityGetRoles()); + return roles && roles.length ? null : this.store.dispatch(new GetRoles()); } } diff --git a/npm/ng-packs/packages/identity/src/lib/resolvers/users.resolver.ts b/npm/ng-packs/packages/identity/src/lib/resolvers/users.resolver.ts index 3dc7a39372..66fe2d2c0c 100644 --- a/npm/ng-packs/packages/identity/src/lib/resolvers/users.resolver.ts +++ b/npm/ng-packs/packages/identity/src/lib/resolvers/users.resolver.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { Resolve } from '@angular/router'; import { Store } from '@ngxs/store'; -import { IdentityGetUsers } from '../actions/identity.actions'; +import { GetUsers } from '../actions/identity.actions'; import { Identity } from '../models/identity'; import { IdentityState } from '../states/identity.state'; @@ -11,6 +11,6 @@ export class UserResolver implements Resolve { resolve() { const users = this.store.selectSnapshot(IdentityState.getUsers); - return users && users.length ? null : this.store.dispatch(new IdentityGetUsers()); + return users && users.length ? null : this.store.dispatch(new GetUsers()); } } diff --git a/npm/ng-packs/packages/identity/src/lib/services/identity.service.ts b/npm/ng-packs/packages/identity/src/lib/services/identity.service.ts index 78292fd02a..8499a3c069 100644 --- a/npm/ng-packs/packages/identity/src/lib/services/identity.service.ts +++ b/npm/ng-packs/packages/identity/src/lib/services/identity.service.ts @@ -37,7 +37,7 @@ export class IdentityService { return this.rest.request(request); } - addRole(body: Identity.RoleSaveRequest): Observable { + createRole(body: Identity.RoleSaveRequest): Observable { const request: Rest.Request = { method: 'POST', url: '/api/identity/roles', @@ -97,7 +97,7 @@ export class IdentityService { return this.rest.request(request); } - addUser(body: Identity.UserSaveRequest): Observable { + createUser(body: Identity.UserSaveRequest): Observable { const request: Rest.Request = { method: 'POST', url: '/api/identity/users', diff --git a/npm/ng-packs/packages/identity/src/lib/states/identity.state.ts b/npm/ng-packs/packages/identity/src/lib/states/identity.state.ts index 33b7d5cafe..3576637094 100644 --- a/npm/ng-packs/packages/identity/src/lib/states/identity.state.ts +++ b/npm/ng-packs/packages/identity/src/lib/states/identity.state.ts @@ -1,17 +1,17 @@ import { Action, Selector, State, StateContext } from '@ngxs/store'; import { switchMap, tap, pluck } from 'rxjs/operators'; import { - IdentityAddRole, - IdentityAddUser, - IdentityDeleteRole, - IdentityDeleteUser, - IdentityGetRoleById, - IdentityGetRoles, - IdentityGetUserById, - IdentityGetUsers, - IdentityUpdateRole, - IdentityUpdateUser, - IdentityGetUserRoles, + CreateRole, + CreateUser, + DeleteRole, + DeleteUser, + GetRoleById, + GetRoles, + GetUserById, + GetUsers, + UpdateRole, + UpdateUser, + GetUserRoles, } from '../actions/identity.actions'; import { Identity } from '../models/identity'; import { IdentityService } from '../services/identity.service'; @@ -43,8 +43,8 @@ export class IdentityState { constructor(private identityService: IdentityService) {} - @Action(IdentityGetRoles) - getRoles({ patchState }: StateContext, { payload }: IdentityGetRoles) { + @Action(GetRoles) + getRoles({ patchState }: StateContext, { payload }: GetRoles) { return this.identityService.getRoles(payload).pipe( tap(roles => patchState({ @@ -54,8 +54,8 @@ export class IdentityState { ); } - @Action(IdentityGetRoleById) - getRole({ patchState }: StateContext, { payload }: IdentityGetRoleById) { + @Action(GetRoleById) + getRole({ patchState }: StateContext, { payload }: GetRoleById) { return this.identityService.getRoleById(payload).pipe( tap(selectedRole => patchState({ @@ -65,26 +65,26 @@ export class IdentityState { ); } - @Action(IdentityDeleteRole) - deleteRole({ dispatch }: StateContext, { payload }: IdentityGetRoleById) { - return this.identityService.deleteRole(payload).pipe(switchMap(() => dispatch(new IdentityGetRoles()))); + @Action(DeleteRole) + deleteRole({ dispatch }: StateContext, { payload }: GetRoleById) { + return this.identityService.deleteRole(payload).pipe(switchMap(() => dispatch(new GetRoles()))); } - @Action(IdentityAddRole) - addRole({ dispatch }: StateContext, { payload }: IdentityAddRole) { - return this.identityService.addRole(payload).pipe(switchMap(() => dispatch(new IdentityGetRoles()))); + @Action(CreateRole) + addRole({ dispatch }: StateContext, { payload }: CreateRole) { + return this.identityService.createRole(payload).pipe(switchMap(() => dispatch(new GetRoles()))); } - @Action(IdentityUpdateRole) - updateRole({ getState, dispatch }: StateContext, { payload }: IdentityUpdateRole) { - return dispatch(new IdentityGetRoleById(payload.id)).pipe( + @Action(UpdateRole) + updateRole({ getState, dispatch }: StateContext, { payload }: UpdateRole) { + return dispatch(new GetRoleById(payload.id)).pipe( switchMap(() => this.identityService.updateRole({ ...getState().selectedRole, ...payload })), - switchMap(() => dispatch(new IdentityGetRoles())), + switchMap(() => dispatch(new GetRoles())), ); } - @Action(IdentityGetUsers) - getUsers({ patchState }: StateContext, { payload }: IdentityGetUsers) { + @Action(GetUsers) + getUsers({ patchState }: StateContext, { payload }: GetUsers) { return this.identityService.getUsers(payload).pipe( tap(users => patchState({ @@ -94,8 +94,8 @@ export class IdentityState { ); } - @Action(IdentityGetUserById) - getUser({ patchState }: StateContext, { payload }: IdentityGetUserById) { + @Action(GetUserById) + getUser({ patchState }: StateContext, { payload }: GetUserById) { return this.identityService.getUserById(payload).pipe( tap(selectedUser => patchState({ @@ -105,26 +105,26 @@ export class IdentityState { ); } - @Action(IdentityDeleteUser) - deleteUser({ dispatch }: StateContext, { payload }: IdentityGetUserById) { - return this.identityService.deleteUser(payload).pipe(switchMap(() => dispatch(new IdentityGetUsers()))); + @Action(DeleteUser) + deleteUser({ dispatch }: StateContext, { payload }: GetUserById) { + return this.identityService.deleteUser(payload).pipe(switchMap(() => dispatch(new GetUsers()))); } - @Action(IdentityAddUser) - addUser({ dispatch }: StateContext, { payload }: IdentityAddUser) { - return this.identityService.addUser(payload).pipe(switchMap(() => dispatch(new IdentityGetUsers()))); + @Action(CreateUser) + addUser({ dispatch }: StateContext, { payload }: CreateUser) { + return this.identityService.createUser(payload).pipe(switchMap(() => dispatch(new GetUsers()))); } - @Action(IdentityUpdateUser) - updateUser({ getState, dispatch }: StateContext, { payload }: IdentityUpdateUser) { - return dispatch(new IdentityGetUserById(payload.id)).pipe( + @Action(UpdateUser) + updateUser({ getState, dispatch }: StateContext, { payload }: UpdateUser) { + return dispatch(new GetUserById(payload.id)).pipe( switchMap(() => this.identityService.updateUser({ ...getState().selectedUser, ...payload })), - switchMap(() => dispatch(new IdentityGetUsers())), + switchMap(() => dispatch(new GetUsers())), ); } - @Action(IdentityGetUserRoles) - getUserRoles({ patchState }: StateContext, { payload }: IdentityGetUserRoles) { + @Action(GetUserRoles) + getUserRoles({ patchState }: StateContext, { payload }: GetUserRoles) { return this.identityService.getUserRoles(payload).pipe( pluck('items'), tap(selectedUserRoles =>