refactor(tenant-management): rename actions and service functions

pull/1612/head
TheDiaval 6 years ago
parent 19fc0b6c1f
commit 46d2b7ed00

@ -1,27 +1,27 @@
import { TenantManagement } from '../models/tenant-management';
import { ABP } from '@abp/ng.core';
export class TenantManagementGet {
static readonly type = '[TenantManagement] Get';
export class GetTenant {
static readonly type = '[TenantManagement] Get Tenant';
constructor(public payload?: ABP.PageQueryParams) {}
}
export class TenantManagementGetById {
static readonly type = '[TenantManagement] Get By Id';
export class GetTenantById {
static readonly type = '[TenantManagement] Get Tenant By Id';
constructor(public payload: string) {}
}
export class TenantManagementAdd {
static readonly type = '[TenantManagement] Add';
export class CreateTenant {
static readonly type = '[TenantManagement] Create Tenant';
constructor(public payload: TenantManagement.AddRequest) {}
}
export class TenantManagementUpdate {
static readonly type = '[TenantManagement] Update';
export class UpdateTenant {
static readonly type = '[TenantManagement] Update Tenant';
constructor(public payload: TenantManagement.UpdateRequest) {}
}
export class TenantManagementDelete {
static readonly type = '[TenantManagement] Delete';
export class DeleteTenant {
static readonly type = '[TenantManagement] Delete Tenant';
constructor(public payload: string) {}
}

@ -6,11 +6,11 @@ import { Select, Store } from '@ngxs/store';
import { Observable, Subject } from 'rxjs';
import { debounceTime, finalize, pluck, switchMap, take } from 'rxjs/operators';
import {
TenantManagementAdd,
TenantManagementDelete,
TenantManagementGet,
TenantManagementGetById,
TenantManagementUpdate,
CreateTenant,
DeleteTenant,
GetTenant,
GetTenantById,
UpdateTenant,
} from '../../actions/tenant-management.actions';
import { TenantManagementService } from '../../services/tenant-management.service';
import { TenantManagementState } from '../../states/tenant-management.state';
@ -103,7 +103,7 @@ export class TenantsComponent {
onEditConnectionString(id: string) {
this.store
.dispatch(new TenantManagementGetById(id))
.dispatch(new GetTenantById(id))
.pipe(
pluck('TenantManagementState', 'selectedItem'),
switchMap(selected => {
@ -127,7 +127,7 @@ export class TenantsComponent {
onEditTenant(id: string) {
this.store
.dispatch(new TenantManagementGetById(id))
.dispatch(new GetTenantById(id))
.pipe(pluck('TenantManagementState', 'selectedItem'))
.subscribe(selected => {
this.selected = selected;
@ -167,8 +167,8 @@ export class TenantsComponent {
this.store
.dispatch(
this.selected.id
? new TenantManagementUpdate({ ...this.tenantForm.value, id: this.selected.id })
: new TenantManagementAdd(this.tenantForm.value),
? new UpdateTenant({ ...this.tenantForm.value, id: this.selected.id })
: new CreateTenant(this.tenantForm.value),
)
.subscribe(() => {
this.isModalVisible = false;
@ -182,7 +182,7 @@ export class TenantsComponent {
})
.subscribe((status: Toaster.Status) => {
if (status === Toaster.Status.confirm) {
this.store.dispatch(new TenantManagementDelete(id));
this.store.dispatch(new DeleteTenant(id));
}
});
}
@ -197,7 +197,7 @@ export class TenantsComponent {
get() {
this.loading = true;
this.store
.dispatch(new TenantManagementGet(this.pageQuery))
.dispatch(new GetTenant(this.pageQuery))
.pipe(finalize(() => (this.loading = false)))
.subscribe();
}

@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { Resolve } from '@angular/router';
import { Store } from '@ngxs/store';
import { TenantManagementGet } from '../actions/tenant-management.actions';
import { GetTenant } from '../actions/tenant-management.actions';
import { TenantManagement } from '../models/tenant-management';
import { TenantManagementState } from '../states/tenant-management.state';
@ -11,8 +11,6 @@ export class TenantsResolver implements Resolve<TenantManagement.State> {
resolve() {
const data = this.store.selectSnapshot(TenantManagementState.get);
return data && data.length
? null
: this.store.dispatch(new TenantManagementGet());
return data && data.length ? null : this.store.dispatch(new GetTenant());
}
}

@ -9,7 +9,7 @@ import { TenantManagement } from '../models/tenant-management';
export class TenantManagementService {
constructor(private rest: RestService) {}
get(params = {} as ABP.PageQueryParams): Observable<TenantManagement.Response> {
getTenant(params = {} as ABP.PageQueryParams): Observable<TenantManagement.Response> {
const request: Rest.Request<null> = {
method: 'GET',
url: '/api/multi-tenancy/tenants',
@ -19,7 +19,7 @@ export class TenantManagementService {
return this.rest.request<null, TenantManagement.Response>(request);
}
getById(id: string): Observable<ABP.BasicItem> {
getTenantById(id: string): Observable<ABP.BasicItem> {
const request: Rest.Request<null> = {
method: 'GET',
url: `/api/multi-tenancy/tenants/${id}`,
@ -28,7 +28,7 @@ export class TenantManagementService {
return this.rest.request<null, ABP.BasicItem>(request);
}
delete(id: string): Observable<null> {
deleteTenant(id: string): Observable<null> {
const request: Rest.Request<null> = {
method: 'DELETE',
url: `/api/multi-tenancy/tenants/${id}`,
@ -37,7 +37,7 @@ export class TenantManagementService {
return this.rest.request<null, null>(request);
}
add(body: TenantManagement.AddRequest): Observable<ABP.BasicItem> {
createTenant(body: TenantManagement.AddRequest): Observable<ABP.BasicItem> {
const request: Rest.Request<TenantManagement.AddRequest> = {
method: 'POST',
url: `/api/multi-tenancy/tenants`,
@ -47,7 +47,7 @@ export class TenantManagementService {
return this.rest.request<TenantManagement.AddRequest, ABP.BasicItem>(request);
}
update(body: TenantManagement.UpdateRequest): Observable<ABP.BasicItem> {
updateTenant(body: TenantManagement.UpdateRequest): Observable<ABP.BasicItem> {
const url = `/api/multi-tenancy/tenants/${body.id}`;
delete body.id;

@ -1,11 +1,11 @@
import { Action, Selector, State, StateContext } from '@ngxs/store';
import { switchMap, tap } from 'rxjs/operators';
import {
TenantManagementAdd,
TenantManagementDelete,
TenantManagementGet,
TenantManagementGetById,
TenantManagementUpdate,
CreateTenant,
DeleteTenant,
GetTenant,
GetTenantById,
UpdateTenant,
} from '../actions/tenant-management.actions';
import { TenantManagement } from '../models/tenant-management';
import { TenantManagementService } from '../services/tenant-management.service';
@ -28,9 +28,9 @@ export class TenantManagementState {
constructor(private tenantManagementService: TenantManagementService) {}
@Action(TenantManagementGet)
get({ patchState }: StateContext<TenantManagement.State>, { payload }: TenantManagementGet) {
return this.tenantManagementService.get(payload).pipe(
@Action(GetTenant)
get({ patchState }: StateContext<TenantManagement.State>, { payload }: GetTenant) {
return this.tenantManagementService.getTenant(payload).pipe(
tap(result =>
patchState({
result,
@ -39,9 +39,9 @@ export class TenantManagementState {
);
}
@Action(TenantManagementGetById)
getById({ patchState }: StateContext<TenantManagement.State>, { payload }: TenantManagementGetById) {
return this.tenantManagementService.getById(payload).pipe(
@Action(GetTenantById)
getById({ patchState }: StateContext<TenantManagement.State>, { payload }: GetTenantById) {
return this.tenantManagementService.getTenantById(payload).pipe(
tap(selectedItem =>
patchState({
selectedItem,
@ -50,21 +50,21 @@ export class TenantManagementState {
);
}
@Action(TenantManagementDelete)
delete({ dispatch }: StateContext<TenantManagement.State>, { payload }: TenantManagementDelete) {
return this.tenantManagementService.delete(payload).pipe(switchMap(() => dispatch(new TenantManagementGet())));
@Action(DeleteTenant)
delete({ dispatch }: StateContext<TenantManagement.State>, { payload }: DeleteTenant) {
return this.tenantManagementService.deleteTenant(payload).pipe(switchMap(() => dispatch(new GetTenant())));
}
@Action(TenantManagementAdd)
add({ dispatch }: StateContext<TenantManagement.State>, { payload }: TenantManagementAdd) {
return this.tenantManagementService.add(payload).pipe(switchMap(() => dispatch(new TenantManagementGet())));
@Action(CreateTenant)
add({ dispatch }: StateContext<TenantManagement.State>, { payload }: CreateTenant) {
return this.tenantManagementService.createTenant(payload).pipe(switchMap(() => dispatch(new GetTenant())));
}
@Action(TenantManagementUpdate)
update({ dispatch, getState }: StateContext<TenantManagement.State>, { payload }: TenantManagementUpdate) {
return dispatch(new TenantManagementGetById(payload.id)).pipe(
switchMap(() => this.tenantManagementService.update({ ...getState().selectedItem, ...payload })),
switchMap(() => dispatch(new TenantManagementGet())),
@Action(UpdateTenant)
update({ dispatch, getState }: StateContext<TenantManagement.State>, { payload }: UpdateTenant) {
return dispatch(new GetTenantById(payload.id)).pipe(
switchMap(() => this.tenantManagementService.updateTenant({ ...getState().selectedItem, ...payload })),
switchMap(() => dispatch(new GetTenant())),
);
}
}

Loading…
Cancel
Save