Browse Source

refactor(identity): rename actions and service functions

pull/1612/head
TheDiaval 7 years ago
parent
commit
38d18b32fd
  1. 26
      npm/ng-packs/packages/identity/src/lib/actions/identity.actions.ts
  2. 18
      npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.ts
  3. 24
      npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts
  4. 4
      npm/ng-packs/packages/identity/src/lib/resolvers/roles.resolver.ts
  5. 4
      npm/ng-packs/packages/identity/src/lib/resolvers/users.resolver.ts
  6. 4
      npm/ng-packs/packages/identity/src/lib/services/identity.service.ts
  7. 82
      npm/ng-packs/packages/identity/src/lib/states/identity.state.ts

26
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) {}
}

18
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();
}

24
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();
}

4
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<Identity.State> {
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());
}
}

4
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<Identity.State> {
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());
}
}

4
npm/ng-packs/packages/identity/src/lib/services/identity.service.ts

@ -37,7 +37,7 @@ export class IdentityService {
return this.rest.request<null, Identity.RoleItem>(request);
}
addRole(body: Identity.RoleSaveRequest): Observable<Identity.RoleItem> {
createRole(body: Identity.RoleSaveRequest): Observable<Identity.RoleItem> {
const request: Rest.Request<Identity.RoleSaveRequest> = {
method: 'POST',
url: '/api/identity/roles',
@ -97,7 +97,7 @@ export class IdentityService {
return this.rest.request<null, null>(request);
}
addUser(body: Identity.UserSaveRequest): Observable<Identity.UserItem> {
createUser(body: Identity.UserSaveRequest): Observable<Identity.UserItem> {
const request: Rest.Request<Identity.UserSaveRequest> = {
method: 'POST',
url: '/api/identity/users',

82
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<Identity.State>, { payload }: IdentityGetRoles) {
@Action(GetRoles)
getRoles({ patchState }: StateContext<Identity.State>, { payload }: GetRoles) {
return this.identityService.getRoles(payload).pipe(
tap(roles =>
patchState({
@ -54,8 +54,8 @@ export class IdentityState {
);
}
@Action(IdentityGetRoleById)
getRole({ patchState }: StateContext<Identity.State>, { payload }: IdentityGetRoleById) {
@Action(GetRoleById)
getRole({ patchState }: StateContext<Identity.State>, { payload }: GetRoleById) {
return this.identityService.getRoleById(payload).pipe(
tap(selectedRole =>
patchState({
@ -65,26 +65,26 @@ export class IdentityState {
);
}
@Action(IdentityDeleteRole)
deleteRole({ dispatch }: StateContext<Identity.State>, { payload }: IdentityGetRoleById) {
return this.identityService.deleteRole(payload).pipe(switchMap(() => dispatch(new IdentityGetRoles())));
@Action(DeleteRole)
deleteRole({ dispatch }: StateContext<Identity.State>, { payload }: GetRoleById) {
return this.identityService.deleteRole(payload).pipe(switchMap(() => dispatch(new GetRoles())));
}
@Action(IdentityAddRole)
addRole({ dispatch }: StateContext<Identity.State>, { payload }: IdentityAddRole) {
return this.identityService.addRole(payload).pipe(switchMap(() => dispatch(new IdentityGetRoles())));
@Action(CreateRole)
addRole({ dispatch }: StateContext<Identity.State>, { payload }: CreateRole) {
return this.identityService.createRole(payload).pipe(switchMap(() => dispatch(new GetRoles())));
}
@Action(IdentityUpdateRole)
updateRole({ getState, dispatch }: StateContext<Identity.State>, { payload }: IdentityUpdateRole) {
return dispatch(new IdentityGetRoleById(payload.id)).pipe(
@Action(UpdateRole)
updateRole({ getState, dispatch }: StateContext<Identity.State>, { 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<Identity.State>, { payload }: IdentityGetUsers) {
@Action(GetUsers)
getUsers({ patchState }: StateContext<Identity.State>, { payload }: GetUsers) {
return this.identityService.getUsers(payload).pipe(
tap(users =>
patchState({
@ -94,8 +94,8 @@ export class IdentityState {
);
}
@Action(IdentityGetUserById)
getUser({ patchState }: StateContext<Identity.State>, { payload }: IdentityGetUserById) {
@Action(GetUserById)
getUser({ patchState }: StateContext<Identity.State>, { payload }: GetUserById) {
return this.identityService.getUserById(payload).pipe(
tap(selectedUser =>
patchState({
@ -105,26 +105,26 @@ export class IdentityState {
);
}
@Action(IdentityDeleteUser)
deleteUser({ dispatch }: StateContext<Identity.State>, { payload }: IdentityGetUserById) {
return this.identityService.deleteUser(payload).pipe(switchMap(() => dispatch(new IdentityGetUsers())));
@Action(DeleteUser)
deleteUser({ dispatch }: StateContext<Identity.State>, { payload }: GetUserById) {
return this.identityService.deleteUser(payload).pipe(switchMap(() => dispatch(new GetUsers())));
}
@Action(IdentityAddUser)
addUser({ dispatch }: StateContext<Identity.State>, { payload }: IdentityAddUser) {
return this.identityService.addUser(payload).pipe(switchMap(() => dispatch(new IdentityGetUsers())));
@Action(CreateUser)
addUser({ dispatch }: StateContext<Identity.State>, { payload }: CreateUser) {
return this.identityService.createUser(payload).pipe(switchMap(() => dispatch(new GetUsers())));
}
@Action(IdentityUpdateUser)
updateUser({ getState, dispatch }: StateContext<Identity.State>, { payload }: IdentityUpdateUser) {
return dispatch(new IdentityGetUserById(payload.id)).pipe(
@Action(UpdateUser)
updateUser({ getState, dispatch }: StateContext<Identity.State>, { 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<Identity.State>, { payload }: IdentityGetUserRoles) {
@Action(GetUserRoles)
getUserRoles({ patchState }: StateContext<Identity.State>, { payload }: GetUserRoles) {
return this.identityService.getUserRoles(payload).pipe(
pluck('items'),
tap(selectedUserRoles =>

Loading…
Cancel
Save