src/app/core/profile/profile.service.ts
Properties |
|
Methods |
constructor(authService: AuthService, http: AuthHttp)
|
||||||||||||
Defined in src/app/core/profile/profile.service.ts:17
|
||||||||||||
Parameters :
|
checkNickname | ||||||||
checkNickname(name: string)
|
||||||||
Defined in src/app/core/profile/profile.service.ts:47
|
||||||||
Parameters :
Returns :
any
|
getLocalProfile |
getLocalProfile()
|
Defined in src/app/core/profile/profile.service.ts:43
|
Returns :
any
|
getProfile | ||||||||
getProfile(user: User)
|
||||||||
Defined in src/app/core/profile/profile.service.ts:34
|
||||||||
Parameters :
Returns :
Observable<Profile>
|
Private updateLocalProfile | ||||||||
updateLocalProfile(user: User)
|
||||||||
Defined in src/app/core/profile/profile.service.ts:51
|
||||||||
Parameters :
Returns :
void
|
updateProfile | ||||||||
updateProfile(profile: UpdateProfileData)
|
||||||||
Defined in src/app/core/profile/profile.service.ts:26
|
||||||||
Parameters :
Returns :
any
|
getProfileSubscription |
getProfileSubscription:
|
Type : Subscription
|
Defined in src/app/core/profile/profile.service.ts:13
|
Private profile |
profile:
|
Type : Profile
|
Default value : new EmptyProfile(this.authService.getUser())
|
Defined in src/app/core/profile/profile.service.ts:15
|
profileState |
profileState:
|
Default value : this.profileSubject.asObservable()
|
Defined in src/app/core/profile/profile.service.ts:17
|
Private profileSubject |
profileSubject:
|
Default value : new Subject<Profile>()
|
Defined in src/app/core/profile/profile.service.ts:16
|
import {Injectable} from "@angular/core";
import {EmptyProfile, UpdateProfileData, ProfileImpl} from "./profile.data";
import {AuthService} from "../auth/auth.service";
import {Subject, Subscription, Observable} from "rxjs";
import {AuthHttp} from "../auth/auth-http.service";
import {User} from "../models/auth/user.model";
import {Profile} from "../models/profile/profile.model";
@Injectable()
export class ProfileService {
getProfileSubscription: Subscription;
private profile: Profile = new EmptyProfile(this.authService.getUser());
private profileSubject = new Subject<Profile>();
profileState = this.profileSubject.asObservable();
constructor(private authService: AuthService, private http: AuthHttp) {
if (authService.isLoggedIn()) {
this.updateLocalProfile(authService.getUser());
}
this.authService.userState.subscribe(user => this.updateLocalProfile(user))
}
updateProfile(profile: UpdateProfileData) {
return this.http.post('/api/v1/profile/update', JSON.stringify(profile)).map(rs => {
this.profile = new ProfileImpl(this.authService.getUser()).setFields(profile);
this.profileSubject.next(this.profile);
return rs.json()
})
}
getProfile(user: User): Observable<Profile> {
return this.http.get('/api/v1/profile').map(rs => {
this.profile = rs.json();
this.profile.user = user;
this.profileSubject.next(this.profile);
return rs.json();
})
}
getLocalProfile() {
return this.profile;
}
checkNickname(name: string) {
return this.http.get('/api/v1/profile/check/nickname/' + name)
}
private updateLocalProfile(user: User) {
if (this.getProfileSubscription) {
this.getProfileSubscription.unsubscribe()
}
this.getProfileSubscription = this.getProfile(user).subscribe()
}
}