diff --git a/package-lock.json b/package-lock.json index 2c24e58..9489a45 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2256,9 +2256,8 @@ "dev": true }, "@ucap/ng-store-organization": { - "version": "file:dist/store-organization/ucap-ng-store-organization-0.0.2.tgz", - "integrity": "sha512-cCCFQNvIG3FJEdxd8VkYvsKHM0tEL5ySKUvA5YS+5i0kksZJYvE2lgz7wD1rHqfg5ea57HnvrdHfFjukusJK0A==", - "dev": true + "version": "file:dist/store-organization/ucap-ng-store-organization-0.0.3.tgz", + "integrity": "sha512-qakDmEzWloikSk/Sczs2i/dL54ZAIEqkjx2x4jcn0dMKkCF2KseCphNXTfaLpAcMuGVR5ZAy2bQjy90NbbHeOg==" }, "@ucap/ng-ui": { "version": "file:dist/ui/ucap-ng-ui-0.0.3.tgz", @@ -2277,7 +2276,8 @@ }, "@ucap/ng-ui-skin-default": { "version": "file:dist/ui-skin-default/ucap-ng-ui-skin-default-0.0.1.tgz", - "integrity": "sha512-vtgJBOsJj/S2GjP02PpBz9ebGikNtzdsC7JQc5HKkCZRC6JKkzZmWzcaFGlLPsh9dcWEeZuNhwnAZfmPXgz6Aw==" + "integrity": "sha512-vtgJBOsJj/S2GjP02PpBz9ebGikNtzdsC7JQc5HKkCZRC6JKkzZmWzcaFGlLPsh9dcWEeZuNhwnAZfmPXgz6Aw==", + "dev": true }, "@ucap/ng-web-storage": { "version": "file:dist/web-storage/ucap-ng-web-storage-0.0.1.tgz", diff --git a/package.json b/package.json index a599a45..ada8c03 100644 --- a/package.json +++ b/package.json @@ -165,7 +165,7 @@ "@ucap/ng-store-authentication": "file:dist/store-authentication/ucap-ng-store-authentication-0.0.2.tgz", "@ucap/ng-store-chat": "file:dist/store-chat/ucap-ng-store-chat-0.0.3.tgz", "@ucap/ng-store-group": "file:dist/store-group/ucap-ng-store-group-0.0.3.tgz", - "@ucap/ng-store-organization": "file:dist/store-organization/ucap-ng-store-organization-0.0.2.tgz", + "@ucap/ng-store-organization": "file:dist/store-organization/ucap-ng-store-organization-0.0.3.tgz", "@ucap/ng-ui": "file:dist/ui/ucap-ng-ui-0.0.3.tgz", "@ucap/ng-ui-authentication": "file:dist/ui-authentication/ucap-ng-ui-authentication-0.0.1.tgz", "@ucap/ng-ui-organization": "file:dist/ui-organization/ucap-ng-ui-organization-0.0.1.tgz", diff --git a/projects/store-organization/ng-package.json b/projects/store-organization/ng-package.json index e310c66..410ff50 100644 --- a/projects/store-organization/ng-package.json +++ b/projects/store-organization/ng-package.json @@ -6,6 +6,7 @@ "umdModuleIds": { "@ngrx/store": "@ngrx/store", "@ngrx/effects": "@ngrx/effects", + "@ucap/ng-api-external": "@ucap/ng-api-external", "@ucap/ng-protocol-query": "@ucap/ng-protocol-query" } } diff --git a/projects/store-organization/package.json b/projects/store-organization/package.json index 02f0c94..ab90280 100644 --- a/projects/store-organization/package.json +++ b/projects/store-organization/package.json @@ -1,14 +1,15 @@ { "name": "@ucap/ng-store-organization", - "version": "0.0.2", + "version": "0.0.3", "publishConfig": { "registry": "http://10.81.13.221:8081/nexus/repository/npm-ucap/" }, "peerDependencies": { - "@angular/common": "^9.0.2", - "@angular/core": "^9.0.2", + "@angular/common": "^9.0.0", + "@angular/core": "^9.0.0", "@ucap/core": "~0.0.1", "@ucap/protocol-query": "~0.0.1", + "@ucap/ng-api-external": "~0.0.1", "@ucap/ng-protocol-query": "~0.0.1", "tslib": "^1.10.0" } diff --git a/projects/store-organization/src/lib/store/company/actions.ts b/projects/store-organization/src/lib/store/company/actions.ts new file mode 100644 index 0000000..672cb6a --- /dev/null +++ b/projects/store-organization/src/lib/store/company/actions.ts @@ -0,0 +1,25 @@ +import { createAction, props } from '@ngrx/store'; + +import { CompanyListRequest, CompanyListResponse } from '@ucap/api-external'; + +/** + * retrieve company list + */ +export const companies = createAction( + '[ucap::organization::company] companies', + props<{ req: CompanyListRequest }>() +); +/** + * Success of companies request + */ +export const companiesSuccess = createAction( + '[ucap::organization::company] companies Success', + props<{ res: CompanyListResponse }>() +); +/** + * Failure of companies request + */ +export const companiesFailure = createAction( + '[ucap::organization::company] companies Failure', + props<{ error: any }>() +); diff --git a/projects/store-organization/src/lib/store/company/effects.ts b/projects/store-organization/src/lib/store/company/effects.ts new file mode 100644 index 0000000..5902f63 --- /dev/null +++ b/projects/store-organization/src/lib/store/company/effects.ts @@ -0,0 +1,33 @@ +import { of } from 'rxjs'; +import { catchError, map, switchMap } from 'rxjs/operators'; + +import { Injectable } from '@angular/core'; + +import { Store } from '@ngrx/store'; +import { Actions, ofType, createEffect } from '@ngrx/effects'; + +import { ExternalApiService } from '@ucap/ng-api-external'; + +import { companies, companiesSuccess, companiesFailure } from './actions'; + +@Injectable() +export class Effects { + companies$ = createEffect(() => { + return this.actions$.pipe( + ofType(companies), + map(action => action.req), + switchMap(req => + this.externalApiService.companyList(req).pipe( + map(res => companiesSuccess({ res })), + catchError(error => of(companiesFailure({ error }))) + ) + ) + ); + }); + + constructor( + private actions$: Actions, + private store: Store, + private externalApiService: ExternalApiService + ) {} +} diff --git a/projects/store-organization/src/lib/store/company/reducers.ts b/projects/store-organization/src/lib/store/company/reducers.ts new file mode 100644 index 0000000..02d04a7 --- /dev/null +++ b/projects/store-organization/src/lib/store/company/reducers.ts @@ -0,0 +1,15 @@ +import { createReducer, on } from '@ngrx/store'; + +import { companiesSuccess } from './actions'; +import { initialState } from './state'; + +export const reducer = createReducer( + initialState, + + on(companiesSuccess, (state, action) => { + return { + ...state, + companyList: action.res.companyList + }; + }) +); diff --git a/projects/store-organization/src/lib/store/company/state.ts b/projects/store-organization/src/lib/store/company/state.ts new file mode 100644 index 0000000..0d7bfe2 --- /dev/null +++ b/projects/store-organization/src/lib/store/company/state.ts @@ -0,0 +1,17 @@ +import { Selector, createSelector } from '@ngrx/store'; +import { DeptInfo, UserInfoSS } from '@ucap/protocol-query'; +import { Company } from '@ucap/api-external'; + +export interface State { + companyList: Company[] | null; +} + +export const initialState: State = { + companyList: null +}; + +export function selectors(selector: Selector) { + return { + companyList: createSelector(selector, (state: State) => state.companyList) + }; +} diff --git a/projects/store-organization/src/lib/store/effects.ts b/projects/store-organization/src/lib/store/effects.ts index 4c78648..b907a48 100644 --- a/projects/store-organization/src/lib/store/effects.ts +++ b/projects/store-organization/src/lib/store/effects.ts @@ -1,6 +1,11 @@ import { Type } from '@angular/core'; import { Effects as CommonEffects } from './common/effects'; +import { Effects as CompanyEffects } from './company/effects'; import { Effects as DepartmentEffects } from './department/effects'; -export const effects: Type[] = [CommonEffects, DepartmentEffects]; +export const effects: Type[] = [ + CommonEffects, + CompanyEffects, + DepartmentEffects +]; diff --git a/projects/store-organization/src/lib/store/reducers.ts b/projects/store-organization/src/lib/store/reducers.ts index fcffd12..c865310 100644 --- a/projects/store-organization/src/lib/store/reducers.ts +++ b/projects/store-organization/src/lib/store/reducers.ts @@ -1,11 +1,13 @@ import { combineReducers, Action } from '@ngrx/store'; import { reducer as CommonReducer } from './common/reducers'; +import { reducer as CompanyReducer } from './company/reducers'; import { reducer as DepartmentReducer } from './department/reducers'; export function reducers(state: any | undefined, action: Action) { return combineReducers({ common: CommonReducer, + company: CompanyReducer, department: DepartmentReducer })(state, action); } diff --git a/projects/store-organization/src/lib/store/state.ts b/projects/store-organization/src/lib/store/state.ts index c837585..e1d59f8 100644 --- a/projects/store-organization/src/lib/store/state.ts +++ b/projects/store-organization/src/lib/store/state.ts @@ -1,12 +1,14 @@ import { createFeatureSelector, createSelector } from '@ngrx/store'; import * as CommonState from './common/state'; +import * as CompanyState from './company/state'; import * as DepartmentState from './department/state'; export const KEY_FEATURE = 'organization'; export interface State { common: CommonState.State; + company: CompanyState.State; department: DepartmentState.State; } @@ -16,6 +18,10 @@ export const CommonSelector = CommonState.selectors( createSelector(Selector, (state: State) => state.common) ); +export const CompanySelector = CompanyState.selectors( + createSelector(Selector, (state: State) => state.company) +); + export const DepartmentSelector = DepartmentState.selectors( createSelector(Selector, (state: State) => state.department) ); diff --git a/projects/store-organization/src/public-api.ts b/projects/store-organization/src/public-api.ts index c2b1ce9..4286565 100644 --- a/projects/store-organization/src/public-api.ts +++ b/projects/store-organization/src/public-api.ts @@ -3,11 +3,12 @@ */ import * as CommonActions from './lib/store/common/actions'; +import * as CompanyActions from './lib/store/company/actions'; import * as DepartmentActions from './lib/store/department/actions'; export * from './lib/config/module-config'; -export { CommonActions, DepartmentActions }; +export { CommonActions, CompanyActions, DepartmentActions }; export * from './lib/store/state';