import { IUserEventModel, ITicketInfoModel } from "@nimee/shared-types"; import axios from "axios"; const port = process.env.USER_EVENT_PORT; const basePath = process.env.IS_LOCAL === "true" ? `http://127.0.0.1:${port}` : "http://user-event"; const userEventUrl = `${basePath}/user-event`; export class UserEventClient { // return axios.get(`/user-event/getByEndUser/${accountId}/${endUserId}`) async getUserEventsByEndUser(params: { accountId: string; endUserId: string; jwt: string; populateEvent?: boolean; populateEventOrder?: boolean; }) { const { accountId, endUserId, jwt, populateEvent, populateEventOrder } = params; const response = await axios.get(`${userEventUrl}/getByEndUser/${accountId}/${endUserId}`, { headers: { jwt }, // add qs param populateEvent: true params: { populateEvent, populateEventOrder }, }); return response?.data; } async getUserEventByJWT(params: { customPaymentJWT: string; adminJWT: string }) { const { customPaymentJWT, adminJWT } = params; const response = await axios.post( `${userEventUrl}/getByJWT`, { customPaymentJWT }, { headers: { jwt: `${adminJWT}` }, } ); return response?.data; } async getById(params: { accountId: string; eventId: string; userEventId: string; jwt: string }) { const { accountId, eventId, userEventId, jwt } = params; const response = await axios.get(`${userEventUrl}/getById/${accountId}/${eventId}/${userEventId}`, { headers: { jwt }, }); return response?.data; } async getByIds(params: { accountId: string; eventId: string; userEventsIds: string[]; jwt: string }) { const { accountId, eventId, userEventsIds, jwt } = params; const response = await axios.post( `${userEventUrl}/getByIds/${accountId}/${eventId}`, { userEventsIds }, { headers: { jwt } } ); return response?.data; } async updateUserEventById(params: { userEvent: IUserEventModel; jwt: string; accountId: string; eventId: string; userEventId: string; }) { const { userEvent, jwt, accountId, eventId, userEventId } = params; const response = await axios.put(`${userEventUrl}/updateUserEvent/${accountId}/${eventId}/${userEventId}`, userEvent, { headers: { jwt }, }); return response?.data; } async getUserEventsByEventId(params: { accountId: string; eventId: string; jwt: string }) { const { accountId, eventId, jwt } = params; const response = await axios.get(`${userEventUrl}/getUserEventsOfEvent/${accountId}/${eventId}`, { headers: { jwt }, }); return response?.data; } async getTotalPriceOfTicketsByIds(params: { userEventsIds: string[]; adminJWT: string }) { const { userEventsIds, adminJWT } = params; const response = await axios.post( `${userEventUrl}/getTotalPriceOfTicketsByIds`, { userEventsIds }, { headers: { jwt: `${adminJWT}` }, } ); return response?.data; } static extractSeatDetails(arr: IUserEventModel[], convertToString?: boolean): string[] | string { const seatDetails: Array = []; arr.forEach((item: IUserEventModel) => { if (item.ticketsInfo?.length) { item.ticketsInfo.forEach((ticketInfo: ITicketInfoModel) => { const { seatLabel, rowLabel, categoryLabel, seat } = ticketInfo; let seatDetail = ""; if (seatLabel && rowLabel) { seatDetail = `${seatLabel} ${rowLabel}`; } else if (seat && seat.includes("-")) { const [row, seatLabel] = seat.split("-"); seatDetail = `שורה-${row} כסא-${seatLabel}`; } else { seatDetail = seat; } const category = categoryLabel ? `(${categoryLabel})` : ""; const combined = `${seatDetail}, ${category}`; seatDetails.push(combined); }); } }); if (convertToString) { return seatDetails.join(" | "); } return seatDetails; } static extractSeats(arr: IUserEventModel[], convertToString?: boolean): string[] | string { const seats: Array = []; arr.forEach((item: IUserEventModel) => { if (item.ticketsInfo?.length) { item.ticketsInfo.forEach((ticketInfo: ITicketInfoModel) => { seats.push(ticketInfo.seat as string); }); } }); if (convertToString) { return seats.join(", "); } return seats; } async getAllUserEvents(params: { seller?: string; skip?: number; limit?: number }) { let { skip, limit } = params; const { seller } = params; if (seller) { if (skip === undefined) skip = 0; if (limit === undefined) limit = 20000; const response = await axios.get(`${userEventUrl}/getAll/${seller}/${skip}/${limit}`, { headers: { jwt: "234243" }, }); return response?.data; } else { const response = await axios.get(`${userEventUrl}/getAll/${skip}/${limit}`, { headers: { jwt: "234243" }, }); return response?.data; } } async getEventOrdersOfEvent(params: { accountId: string; eventId: string; jwt: string }) { const { accountId, eventId, jwt } = params; const response = await axios.get(`${userEventUrl}/event-order/getEventOrdersOfEvent/${accountId}/${eventId}`, { headers: { jwt }, }); return response?.data; } async getEntryPassUsedByEndUserSeasonTicketId(params: { eventId: string; endUserSeasonTicketId: string; jwt: string; timeSlotId?: string; }) { const { eventId, endUserSeasonTicketId, jwt, timeSlotId } = params; const response = await axios.get( `${userEventUrl}/getEntryPassUsedByEndUserSeasonTicketId/${eventId}/${endUserSeasonTicketId}`, { headers: { jwt }, params: timeSlotId ? { timeSlotId } : {}, } ); return response?.data; } async addEntryPassUsedByEndUserSeasonTicketId(params: { eventOrderId: string; endUserSeasonTicketId: string; ticketsUsed: number; jwt: string; }) { const { eventOrderId, endUserSeasonTicketId, ticketsUsed, jwt } = params; const response = await axios.post( `${userEventUrl}/addEntryPassUsedByEndUserSeasonTicketId/${endUserSeasonTicketId}/${eventOrderId}`, { ticketsUsed }, { headers: { jwt }, } ); return response?.data; } async getByEndUser(params: { jwt: string; accountId: string; endUserId: string }) { const { jwt, endUserId, accountId } = params; const response = await axios.get(`${userEventUrl}/getByEndUser/${accountId}/${endUserId}`, { headers: { jwt }, }); return response?.data; } async getApprovedUserEventsByEventId(params: { eventId: string; jwt: string }) { const response = await axios.get(`${userEventUrl}/getApprovedUserEventsByEvent/${params.eventId}`, { headers: { jwt: params.jwt }, }); return response?.data; } async getUserEventsByEventIds(params: { accountId: string; eventIds: string[]; jwt: string }) { const { accountId, eventIds, jwt } = params; const response = await axios.post(`${userEventUrl}/getUserEventsOfEvents/${accountId}`, { eventIds }, { headers: { jwt } }); return response?.data; } async deleteUserEventsForBasket(params: { userEventIds: string[]; jwt: string }) { const { userEventIds, jwt } = params; const response = await axios.post( `${userEventUrl}/deleteForBasket`, { userEventIds }, { headers: { jwt } } ); return response?.data; } async createUserEventForBasket(params: { accountId: string; eventId: string; ticketIds: string[]; timeSlotId?: string; phone: string; fname?: string; lname?: string; email?: string; jwt: string; }) { const { accountId, eventId, jwt, ...body } = params; const response = await axios.post( `${userEventUrl}/createForBasket/${accountId}/${eventId}`, body, { headers: { jwt } } ); return response?.data; } }