File: /var/www/vhost/disk-apps/pwa.sports-crowd.com/src/app/services/tickets.service.ts
import { Injectable } from "@angular/core";
import { ApiService } from "./api.service";
import { UtilsService } from "./utils.service";
@Injectable({
providedIn: "root",
})
export class TicketsService {
parameters: any = {};
matchEvents: any = {};
constructor(
public api: ApiService,
public utilsService: UtilsService
) { }
getMatchEvents(token) {
return this.api.get(`tickets/match_events`, token);
}
loadStadiumZones(token, params) {
return this.api.get(`tickets/loadStadiumZones`, token, params);
}
getSeats(token, sub_zone_id, event_id) {
return this.api.get(`tickets/get_seats/${sub_zone_id}/${event_id}`, token);
}
getSeatPrice(token, zone_id, event_id) {
return this.api.get(`tickets/get_seat_price/${zone_id}/${event_id}`, token);
}
generateBlock(token, info) {
return this.api.post(`tickets/createBlock`, info, token);
}
getMatchEventsSuscription(token, params) {
return this.api.get(`tickets/getMatchEventsSuscription`, token, params);
}
isPreabonado(token, document) {
return this.api.get(`tickets/isPreabonado/${document}`, token);
}
createBlocks(token, info) {
return this.api.post(`tickets/createBlocks`, info, token);
}
purchaseTickets(id) {
let url = this.api.getUrl();
let link = `${url}/tickets/purchase?id=` + id;
this.utilsService.openLink(link);
}
purchaseAbonos() {
let url = this.api.getUrl();
let link = `${url}/abonados/abonados.html`;
this.utilsService.openLink(link);
}
getTickets(take, offset) {
return this.api.get(`tickets/get_tickets/${take}/${offset}`);
}
async getPdf(code, platform) {
return this.api.post(`tickets/pdf`, { code, platform }, await this.utilsService.getAccessToken());
}
generateTicketBycoins(token: string, ticket_main_id: number) {
return this.api.get(`coins/generateTickets/${ticket_main_id}`, token);
}
validateUserTickets(token: string, ticketType: number, matchEventId: number) {
return this.api.get(`flash_tickets/validateUserTickets/${ticketType}/${matchEventId}`, token);
}
getTribunesParentFlashTicket(token: string, matchEventId: number, availableCupon: boolean, cuponCodes: string) {
return this.api.get(`flash_tickets/getTribunesParent/${matchEventId}?availableCupon=${availableCupon}&cuponCode=${cuponCodes}`, token);
}
validateSeatsAvailableByCapacity(token: string, info: object) {
return this.api.post(`flash_tickets/validateSeatsAvailableByCapacity`, info, token);
}
getTicketsSubscriptions(token: string, document: object) {
return this.api.get(`tickets/getTicketsSubscriptions/${document}`, token);
}
createPurchaseSubscribers(token: string, info: object) {
return this.api.post(`tickets/createPurchaseSubscribers`, info, token);
}
async validateCouponExist(matchEventId: number, coupon: string) {
let token = await this.utilsService.getAccessToken();
return new Promise(async (resolve, reject) => {
(await this.api.get(`flash_tickets/validateACoupon/${matchEventId}/${coupon}`, token)).subscribe((res: any) => {
resolve(res);
}, (err) => {
console.error("Error validateCouponExist", err);
reject(err);
}
);
});
}
async userTransferTickets(userInfo) {
let token = await this.utilsService.getAccessToken();
return new Promise(async (resolve, reject) => {
(await this.api.post("tickets/transfer", userInfo, token)).subscribe((res: any) => {
resolve(res);
}, (err) => {
console.error("Error userTransferTickets", err);
reject(err);
}
);
});
}
async userInformation(userData) {
let token = await this.utilsService.getAccessToken();
return new Promise(async (resolve, reject) => {
(await this.api.post("tickets/userInformationToTransferTicket", userData, token)).subscribe((res: any) => {
resolve(res);
}, (err) => {
console.error("Error userInformation", err);
reject(err);
}
);
});
}
getParameters(keys?: any) {
return new Promise(async (resolve, reject) => {
let seq = await this.api.get(`tickets/parameters/info` + (keys ? '?keys=' + keys : ''));
seq.subscribe(
(res: any) => {
if (res.status == "success") {
if (!keys) {
this.parameters = res.parameters;
}
}
resolve(res);
},
(err) => {
console.error("Error provider getParameters", err);
reject(err);
}
);
});
}
}