BugFix: #90,#86 + Restrictions on seller

This commit is contained in:
2024-08-26 17:38:38 +02:00
parent f66badbfb1
commit 8157dcc376
11 changed files with 62 additions and 370 deletions

View File

@@ -4,6 +4,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import { KeycloakService } from 'keycloak-angular';
import { StripeService } from 'ngx-stripe';
import { switchMap } from 'rxjs';
import { User } from '../../../../../bizmatch-server/src/models/db.model';
import { Checkout, KeycloakUser } from '../../../../../bizmatch-server/src/models/main.model';
import { environment } from '../../../environments/environment';
import { UserService } from '../../services/user.service';
@@ -21,6 +22,7 @@ export class PricingComponent {
private apiBaseUrl = environment.apiBaseUrl;
private id: string | undefined = this.activatedRoute.snapshot.params['id'] as string | undefined;
keycloakUser: KeycloakUser;
user: User;
constructor(public keycloakService: KeycloakService, private http: HttpClient, private stripeService: StripeService, private activatedRoute: ActivatedRoute, private userService: UserService, private router: Router) {}
async ngOnInit() {
@@ -29,14 +31,20 @@ export class PricingComponent {
if (this.id) {
this.checkout({ priceId: atob(this.id), email: this.keycloakUser.email, name: `${this.keycloakUser.firstName} ${this.keycloakUser.lastName}` });
}
if (this.keycloakUser && !this.id) {
this.user = await this.userService.getByMail(this.keycloakUser.email);
if (this.user.subscriptionId) {
this.router.navigate([`/account`]);
}
}
}
async register(priceId?: string) {
if (this.keycloakUser) {
if (!priceId) {
const user = await this.userService.getByMail(this.keycloakUser.email);
user.subscriptionPlan = 'free';
await this.userService.save(user);
this.user = await this.userService.getByMail(this.keycloakUser.email);
this.user.subscriptionPlan = 'free';
await this.userService.save(this.user);
this.router.navigate([`/account`]);
} else {
this.checkout({ priceId: priceId, email: this.keycloakUser.email, name: `${this.keycloakUser.firstName} ${this.keycloakUser.lastName}` });