import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { AuthService } from 'src/app/shared/services/auth.service'; import { SoldTournamentTicket, SoldTicketFilter } from 'tournee.businesslogic'; import { TournamentTicketsService } from 'src/app/shared/services/tournament.tickets.service'; @Component({ selector: 'app-ticket', templateUrl: './ticket.component.html', styleUrls: ['./ticket.component.css'], providers: [ TournamentTicketsService ] }) export class TicketComponent implements OnInit { isWorking: boolean = false; Tickets: Array; TransactionId: string; constructor(private _route: ActivatedRoute, private _router: Router, public auth: AuthService, private _tickets: TournamentTicketsService) { } ngOnInit() { this._route.queryParams.subscribe(params => { if (params['tid']) { this.TransactionId = params['tid']; } }); this._route.params.subscribe(params => { this.isWorking = true; let filter = SoldTicketFilter.create().set('attendee_id', this.auth.User.id).set('include_competitions', true); let ids = params['sold_ticket_id'].split(','); if (ids.length == 1) { filter.set('sold_ticket_id', ids[0]); } else { filter.set('sold_ticket_ids', ids); } this._tickets.get_sold_tickets(filter) .then((result) => { if (!result.result || result.result.length == 0) { this._router.navigate(['/404']); this.isWorking = false; } else { this.Tickets = result.result.map((st) => { return new SoldTournamentTicket(st); }); this.isWorking = false; } }) .catch((err) => { this._router.navigate(['/404']); console.log(err); }); }); } }