geo coding, user service, listing for business
This commit is contained in:
@@ -1,20 +1,25 @@
|
||||
import { Injectable, Signal, WritableSignal, computed, effect, signal } from '@angular/core';
|
||||
import { Component } from '@angular/core';
|
||||
import { jwtDecode } from 'jwt-decode';
|
||||
import { Observable, distinctUntilChanged, filter, from, map } from 'rxjs';
|
||||
import { Observable, distinctUntilChanged, filter, from, lastValueFrom, map } from 'rxjs';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { KeycloakService } from './keycloak.service';
|
||||
import { JwtToken, User } from '../../../../common-models/src/main.model';
|
||||
import { environment } from '../../environments/environment';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserService {
|
||||
|
||||
private apiBaseUrl = environment.apiBaseUrl;
|
||||
// -----------------------------
|
||||
// Keycloak services
|
||||
// -----------------------------
|
||||
private user$ = new Observable<User>();
|
||||
private user:User
|
||||
public $isLoggedIn : Signal<boolean>;
|
||||
constructor(public keycloak:KeycloakService){
|
||||
constructor(public keycloak:KeycloakService,private http: HttpClient){
|
||||
this.user$ = from(this.keycloak.getToken()).pipe(
|
||||
filter(t => !!t),
|
||||
distinctUntilChanged(),
|
||||
@@ -50,15 +55,12 @@ export class UserService {
|
||||
const token = await this.keycloak.getToken();
|
||||
this.user = this.map2User(token);
|
||||
}
|
||||
getUserName(){
|
||||
return this.user?.username
|
||||
}
|
||||
|
||||
|
||||
private map2User(jwt:string):User{
|
||||
const token = jwtDecode<JwtToken>(jwt);
|
||||
return {
|
||||
id:token.user_id,
|
||||
username:token.preferred_username,
|
||||
firstname:token.given_name,
|
||||
lastname:token.family_name,
|
||||
email:token.email
|
||||
@@ -91,4 +93,14 @@ export class UserService {
|
||||
register(url:string){
|
||||
this.keycloak.register({redirectUri:url});
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// Redis services
|
||||
// -----------------------------
|
||||
async save(user:User):Promise<User>{
|
||||
return await lastValueFrom(this.http.post<User>(`${this.apiBaseUrl}/bizmatch/user`,user));
|
||||
}
|
||||
async getById(id:string):Promise<User>{
|
||||
return await lastValueFrom(this.http.get<User>(`${this.apiBaseUrl}/bizmatch/user/${id}`));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user