-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feature/SHIBUI-1031' into featur…
…e/SHIBUI-1031
- Loading branch information
Showing
12 changed files
with
149 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Action } from '@ngrx/store'; | ||
|
||
export enum ConfigurationActionTypes { | ||
LOAD_ROLE_REQUEST = '[Config] Load User Role Request', | ||
LOAD_ROLE_SUCCESS = '[Config] Load User Role Success', | ||
LOAD_ROLE_FAIL = '[Config] Load User Role Fail' | ||
} | ||
|
||
export class LoadRoleRequest implements Action { | ||
readonly type = ConfigurationActionTypes.LOAD_ROLE_REQUEST; | ||
|
||
constructor() {} | ||
} | ||
export class LoadRoleSuccess implements Action { | ||
readonly type = ConfigurationActionTypes.LOAD_ROLE_SUCCESS; | ||
|
||
constructor(public payload: string[]) { } | ||
} | ||
export class LoadRoleFail implements Action { | ||
readonly type = ConfigurationActionTypes.LOAD_ROLE_FAIL; | ||
|
||
constructor() { } | ||
} | ||
|
||
export type ConfigurationActionUnion = | ||
| LoadRoleRequest | ||
| LoadRoleSuccess | ||
| LoadRoleFail | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ConfigurationActionUnion, ConfigurationActionTypes } from '../action/configuration.action'; | ||
|
||
export interface ConfigState { | ||
roles: string[]; | ||
} | ||
|
||
export const initialState: ConfigState = { | ||
roles: [] | ||
}; | ||
|
||
export function reducer(state = initialState, action: ConfigurationActionUnion): ConfigState { | ||
switch (action.type) { | ||
case ConfigurationActionTypes.LOAD_ROLE_SUCCESS: { | ||
return { | ||
roles: [...action.payload] | ||
}; | ||
} | ||
default: { | ||
return state; | ||
} | ||
} | ||
} | ||
|
||
|
||
export const getRoles = (state: ConfigState) => state.roles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Admin } from './admin'; | ||
|
||
export class AdminEntity implements Admin { | ||
|
||
username: string; | ||
firstName: string; | ||
lastName: string; | ||
emailAddress: string; | ||
|
||
role: string; | ||
|
||
constructor( | ||
properties: Admin | ||
) { | ||
Object.assign(this, properties); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { User } from '../../../core/model/user'; | ||
|
||
export interface Admin extends User { | ||
export interface Admin { | ||
createdDate?: string; | ||
updatedDate?: string; | ||
resourceId: string; | ||
username: string; | ||
firstName: string; | ||
lastName: string; | ||
|
||
role: string; | ||
|
||
email: string; | ||
emailAddress: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,39 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Observable, of } from 'rxjs'; | ||
import { Admin } from '../model/admin'; | ||
|
||
let users = <Admin[]>[ | ||
{ | ||
resourceId: 'abc', | ||
role: 'SUPER_ADMIN', | ||
email: 'foo@bar.com', | ||
name: { | ||
first: 'Jane', | ||
last: 'Doe' | ||
} | ||
}, | ||
{ | ||
resourceId: 'def', | ||
role: 'DELEGATED_ADMIN', | ||
email: 'bar@baz.com', | ||
name: { | ||
first: 'John', | ||
last: 'Doe' | ||
} | ||
} | ||
]; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { map, catchError } from 'rxjs/operators'; | ||
import { AdminEntity } from '../model/admin-entity'; | ||
|
||
@Injectable() | ||
export class AdminService { | ||
|
||
constructor() { } | ||
private endpoint = '/admin/users'; | ||
private base = '/api'; | ||
|
||
constructor( | ||
private http: HttpClient | ||
) { } | ||
query(): Observable<Admin[]> { | ||
return of([ | ||
...users | ||
]); | ||
return this.http.get<Admin[]>( | ||
`${this.base}${this.endpoint}`, {} | ||
).pipe( | ||
map(users => users.map(u => new AdminEntity(u))) | ||
); | ||
} | ||
|
||
update(user: Admin): Observable<Admin> { | ||
return of({ | ||
...users.find(u => u.resourceId === user.resourceId), | ||
...user | ||
}); | ||
return this.http.put<Admin>( | ||
`${this.base}${this.endpoint}/${user.username}`, {...user} | ||
); | ||
} | ||
|
||
remove(userId: string): Observable<boolean> { | ||
users = users.filter(u => u.resourceId !== userId); | ||
return of(true); | ||
return this.http.delete<Admin>( | ||
`${this.base}${this.endpoint}/${userId}` | ||
).pipe( | ||
map(response => !!response), | ||
catchError(() => of(false)) | ||
); | ||
} | ||
} |