ing
This commit is contained in:
parent
82bd4ef887
commit
48d7216e77
|
@ -6,6 +6,8 @@ import { Observable } from 'rxjs/Observable';
|
|||
import { Location } from '@angular/common';
|
||||
|
||||
import 'rxjs/add/operator/do';
|
||||
import 'rxjs/add/operator/map';
|
||||
import 'rxjs/add/operator/catch';
|
||||
import 'rxjs/add/operator/timeout';
|
||||
import 'rxjs/add/observable/throw';
|
||||
|
||||
|
@ -20,7 +22,6 @@ export class RESTService {
|
|||
@Inject(HttpClient) private _httpClient: HttpClient,
|
||||
) {
|
||||
this.httpHeaders = new HttpHeaders()
|
||||
.set('Accept', 'application/json')
|
||||
.set('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
|
@ -32,12 +33,12 @@ export class RESTService {
|
|||
const headers: HttpHeaders = this.httpHeaders;
|
||||
|
||||
return this._httpClient
|
||||
.get<T>(Location.joinWithSlash(this._baseURL, entry), {
|
||||
.get(Location.joinWithSlash(this._baseURL, entry), {
|
||||
headers: headers,
|
||||
params: params,
|
||||
responseType: 'json',
|
||||
})
|
||||
.map(response => response)
|
||||
.map((response: string) => <T>JSON.parse(response))
|
||||
.catch((error: HttpErrorResponse) => Observable.throw(ErrorResponse.restError(error)));
|
||||
}
|
||||
|
||||
|
@ -45,12 +46,12 @@ export class RESTService {
|
|||
const headers: HttpHeaders = this.httpHeaders;
|
||||
|
||||
return this._httpClient
|
||||
.post<T>(Location.joinWithSlash(this._baseURL, entry), body, {
|
||||
.post(Location.joinWithSlash(this._baseURL, entry), body, {
|
||||
headers: headers,
|
||||
params: params,
|
||||
responseType: 'json',
|
||||
})
|
||||
.map(response => response)
|
||||
.map((response: string) => <T>JSON.parse(response))
|
||||
.catch((error: HttpErrorResponse) => Observable.throw(ErrorResponse.restError(error)));
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import { Observable } from 'rxjs/Observable';
|
|||
import 'rxjs/add/operator/map';
|
||||
|
||||
import { RESTService } from 'packages/commons/service/rest.service';
|
||||
import { DomainMember } from 'packages/domain/model';
|
||||
|
||||
import { Member } from '../model';
|
||||
|
||||
|
@ -16,16 +17,16 @@ export class MemberService {
|
|||
|
||||
}
|
||||
|
||||
public signin(email: string, password: string): Observable<Member> {
|
||||
public signin(email: string, password: string): Observable<DomainMember> {
|
||||
const body = {
|
||||
signinId: email,
|
||||
signinPw: password,
|
||||
};
|
||||
|
||||
return this.restService.post('/account/signin', body);
|
||||
return this.restService.post<DomainMember>('/account/signin', body);
|
||||
}
|
||||
|
||||
public signup(member: Member): Observable<Member> {
|
||||
return this.restService.post('/account/signup', member);
|
||||
return this.restService.post<Member>('/account/signup', member);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Action } from '@ngrx/store';
|
|||
|
||||
import { ErrorResponse } from 'packages/commons/service/error-response';
|
||||
|
||||
import { DomainMember } from 'packages/domain/model';
|
||||
import { Member } from '../../model';
|
||||
|
||||
export enum ActionType {
|
||||
|
@ -23,7 +24,7 @@ export class Signin implements Action {
|
|||
export class SigninSuccess implements Action {
|
||||
readonly type = ActionType.SigninSuccess;
|
||||
|
||||
constructor(public payload: Member) {}
|
||||
constructor(public payload: DomainMember) {}
|
||||
}
|
||||
|
||||
export class SigninFailure implements Action {
|
||||
|
|
|
@ -16,6 +16,8 @@ import 'rxjs/add/operator/take';
|
|||
|
||||
import { ErrorResponse } from 'packages/commons/service/error-response';
|
||||
|
||||
import { DomainMember } from 'packages/domain/model';
|
||||
|
||||
import { Member } from '../../model';
|
||||
import { MemberService } from '../../service/member.service';
|
||||
|
||||
|
@ -40,8 +42,8 @@ export class Effects {
|
|||
.ofType(ActionType.Signin)
|
||||
.map((action: Signin) => action.payload)
|
||||
.switchMap(payload => this.memberService.signin(payload.email, payload.password))
|
||||
.map(member => {
|
||||
return new SigninSuccess(member);
|
||||
.map((domainMember: DomainMember) => {
|
||||
return new SigninSuccess(domainMember);
|
||||
})
|
||||
.catch((error: ErrorResponse) => {
|
||||
return of(new SigninFailure(error));
|
||||
|
|
|
@ -29,7 +29,8 @@ export function reducer(state = initialState, action: Actions): State {
|
|||
isSignin: true,
|
||||
error: null,
|
||||
isPending: false,
|
||||
member: action.payload,
|
||||
member: action.payload.member,
|
||||
domain: action.payload.domain,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -40,6 +41,7 @@ export function reducer(state = initialState, action: Actions): State {
|
|||
error: action.payload,
|
||||
isPending: false,
|
||||
member: null,
|
||||
domain: null,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -58,6 +60,7 @@ export function reducer(state = initialState, action: Actions): State {
|
|||
error: null,
|
||||
isPending: false,
|
||||
member: null,
|
||||
domain: null,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user