casino/frontend/src/app/service/user.service.ts
2025-03-06 12:54:23 +01:00

26 lines
793 B
TypeScript

import { inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { catchError, EMPTY, Observable } from 'rxjs';
import { User } from '../model/User';
@Injectable({
providedIn: 'root',
})
export class UserService {
private http: HttpClient = inject(HttpClient);
public getUser(id: string): Observable<User | null> {
return this.http.get<User | null>(`/backend/user/${id}`).pipe(catchError(() => EMPTY));
}
public getCurrentUser(): Observable<User | null> {
return this.http.get<User | null>('/backend/user').pipe(catchError(() => EMPTY));
}
public createUser(id: string, username: string): Observable<User> {
return this.http.post<User>('/backend/user', {
authentikId: id,
username: username,
});
}
}