import { ITicketInfoModel, ITicketModel, IUserEventModel, IFeeCollectionType } from "@nimee/shared-types"; import axios from "axios"; const port = process.env.EVENT_PORT; const basePath = process.env.IS_LOCAL === "true" ? `http://127.0.0.1:${port}` : "http://event"; const ticketUrl = `${basePath}/event/ticket`; export class TicketClient { async getTicketById(params: { token: string; eventId: string; accountId: string; ticketId: string }) { const { token, accountId, eventId, ticketId } = params; const response = await axios.get(`${ticketUrl}/getById/${accountId}/${eventId}/${ticketId}`, { headers: { jwt: `${token}` }, }); return response?.data; } async getTicketsByIds(params: { token: string; ticketIds: string[]; eventId: string; accountId: string }) { const { token, ticketIds, accountId, eventId } = params; const response = await axios.post( `${ticketUrl}/getByIds/${accountId}/${eventId}`, { ticketIds }, { headers: { jwt: `${token}` } } ); return response?.data; } async getTotalPriceOfTicketByIds(params: { token: string; ticketIds: string[] }) { const { token, ticketIds } = params; const response = await axios.post( `${ticketUrl}/getTotalPriceOfTicketByIds`, { ticketIds }, { headers: { jwt: `${token}` }, } ); return response?.data; } static extractTickets(arr: IUserEventModel[]): string[] { const tickets: Array = []; arr.forEach((item: IUserEventModel) => { if (item.ticketsInfo?.length) { item.ticketsInfo.forEach((ticketInfo: ITicketInfoModel) => { tickets.push(ticketInfo.ticket as string); }); } else if (item.ticket) { tickets.push(item.ticket); } }); return tickets; } async getTicketsOfEventUnsecured(params: { eventId: string; accountId: string; nimiFeeType: IFeeCollectionType }) { const { eventId, accountId, nimiFeeType } = params; const response = await axios.get(`${ticketUrl}/getTickets/${accountId}/${eventId}`, { params: { nimiFeeType }, }); return response?.data; } }