This repository has been archived on 2025-06-18. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
casino/frontend/src/app/service/user.service.ts
Jan-Marlon Leibl ee07abb189
All checks were successful
CI / Get Changed Files (pull_request) Successful in 11s
CI / Docker backend validation (pull_request) Successful in 14s
CI / Docker frontend validation (pull_request) Successful in 45s
CI / oxlint (pull_request) Successful in 33s
CI / eslint (pull_request) Successful in 46s
CI / Checkstyle Main (pull_request) Successful in 1m2s
CI / prettier (pull_request) Successful in 24s
CI / test-build (pull_request) Successful in 35s
style(user.service.ts): fix whitespace in user service file
2025-05-07 18:02:35 +02:00

33 lines
955 B
TypeScript

import { inject, Injectable } from '@angular/core';
import { AuthService } from '@service/auth.service';
import { User } from '../model/User';
@Injectable({
providedIn: 'root',
})
export class UserService {
private authService = inject(AuthService);
/**
* Updates the user's balance locally for immediate UI feedback
* This should be called before a server-side balance change is made
* The server update will be reflected when AuthService.loadCurrentUser() is called
*/
public updateLocalBalance(amount: number): void {
const currentUser = this.authService.currentUserValue;
if (currentUser) {
const updatedUser: User = {
...currentUser,
balance: currentUser.balance + amount,
};
this.authService.userSubject.next(updatedUser);
}
}
/**
* Refreshes the current user's data from the server
*/
public refreshCurrentUser(): void {
this.authService.loadCurrentUser();
}
}