{ "version": 3, "sources": ["src/app/store/e-tickets/tickets-item/tickets-item.actions.ts", "src/app/store/e-tickets/tickets-item/tickets-item.state.ts"], "sourcesContent": ["import {IOrder} from \"src/app/interfaces/general/profile-definitions/order.interface\";\n\n\nexport class GetTicket {\n public static readonly type = '[TicketItem] Get ticket';\n constructor(public id: string) {}\n}\n\nexport class SetTicketsOfCurrentOrder {\n public static readonly type = '[TicketItem] Set tickets of current order';\n constructor(public order: IOrder) {}\n}\n\nexport class GetPrevTicketInOrder {\n public static readonly type = '[TicketItem] Get prev ticket in order';\n constructor(public id: string) {}\n}\n\nexport class GetNextTicketInOrder {\n public static readonly type = '[TicketItem] Get next ticket in order';\n constructor(public id: string) {}\n}\n", "import {Action, createSelector, Selector, State, StateContext, Store} from '@ngxs/store';\nimport {Injectable} from '@angular/core';\nimport {TicketsService} from 'src/app/modules/tickets/tickets.service';\nimport {\n GetNextTicketInOrder,\n GetPrevTicketInOrder,\n GetTicket,\n SetTicketsOfCurrentOrder,\n} from './tickets-item.actions';\nimport {ITicket} from '@discover-swiss/models/interfaces/infocenter/profile-definitions/ticket.interface';\nimport {Navigate} from '@ngxs/router-plugin';\nimport {firstValueFrom} from 'rxjs';\nimport {errorHandler} from 'src/app/shared/helpers/error-handler';\nimport {AppInsightsService} from 'src/app/core/app-insights/app-insights.service';\n\nexport interface ITicketsOfCurrentOrder {\n orderNumber: string;\n ticketsIds: string[];\n}\n\nexport interface ITicketItemState {\n ticket: ITicket;\n loading: boolean;\n hasValue: boolean;\n error: any;\n ticketsOfCurrentOrder: ITicketsOfCurrentOrder;\n}\n\n@State({\n name: 'ticketItem',\n defaults: {\n ticket: null,\n loading: false,\n hasValue: false,\n error: null,\n ticketsOfCurrentOrder: null,\n },\n})\n@Injectable()\nexport class TicketsItemState {\n constructor(\n private ticketsService: TicketsService,\n private store: Store,\n private insights: AppInsightsService,\n ) { }\n\n @Selector()\n public static ticket(state: ITicketItemState): ITicket {\n return state.ticket;\n }\n\n @Selector()\n public static ticketsOfCurrentOrder(state: ITicketItemState): ITicketsOfCurrentOrder {\n return state.ticketsOfCurrentOrder;\n }\n\n @Selector()\n public static loading(state: ITicketItemState): boolean {\n return state.loading;\n }\n\n @Selector()\n public static hasValue(state: ITicketItemState): boolean {\n return state.hasValue;\n }\n\n @Selector()\n public static error(state: ITicketItemState): any {\n return state.error;\n }\n\n public static hasPrevValueInOrder(id: string) {\n return createSelector([TicketsItemState], (state: ITicketItemState) => {\n return (\n state.ticketsOfCurrentOrder?.ticketsIds?.findIndex((ticketId) => ticketId === id) >\n 0\n );\n });\n }\n\n public static hasNextValueInOrder(id: string) {\n return createSelector([TicketsItemState], (state: ITicketItemState) => {\n return (\n state.ticketsOfCurrentOrder?.ticketsIds?.findIndex((ticketId) => ticketId === id) <\n state.ticketsOfCurrentOrder?.ticketsIds?.length - 1\n );\n });\n }\n\n @Action(GetPrevTicketInOrder)\n public getPrevTicketInOrder(\n ctx: StateContext,\n {id}: GetPrevTicketInOrder\n ): void {\n const state = ctx.getState();\n const indexOfPrev =\n state.ticketsOfCurrentOrder.ticketsIds.findIndex((ticketId) => ticketId === id) - 1;\n this.store.dispatch(\n new Navigate([\n '/orders',\n state.ticketsOfCurrentOrder.orderNumber,\n 'tickets',\n state.ticketsOfCurrentOrder.ticketsIds[indexOfPrev],\n ])\n );\n }\n\n @Action(GetNextTicketInOrder)\n public getNextTicketInOrder(\n ctx: StateContext,\n {id}: GetNextTicketInOrder\n ): void {\n const state = ctx.getState();\n const indexOfNext =\n state.ticketsOfCurrentOrder.ticketsIds.findIndex((ticketId) => ticketId === id) + 1;\n\n this.store.dispatch(\n new Navigate([\n '/orders',\n state.ticketsOfCurrentOrder.orderNumber,\n 'tickets',\n state.ticketsOfCurrentOrder.ticketsIds[indexOfNext],\n ])\n );\n }\n\n @Action(GetTicket)\n public async getTicket(ctx: StateContext, {id}: GetTicket): Promise {\n try {\n ctx.patchState({loading: true, error: null});\n const ticket: ITicket = await firstValueFrom(this.ticketsService.getTicketById(id));\n ctx.patchState({\n ticket,\n hasValue: !!ticket,\n loading: false,\n error: null,\n });\n } catch (error) {\n errorHandler({\n error,\n appInsightsSrv: this.insights,\n scope: 'TicketsItemState'\n\n });\n ctx.patchState({\n error: error.error ?? error.message ?? error,\n ticket: null,\n hasValue: false,\n loading: false,\n });\n }\n }\n\n @Action(SetTicketsOfCurrentOrder)\n public setTicketsOfCurrentOrder(\n ctx: StateContext,\n {order}: SetTicketsOfCurrentOrder\n ) {\n if (!order) {\n ctx.patchState({ticketsOfCurrentOrder: null});\n return;\n }\n if (order.orderNumber === ctx.getState().ticketsOfCurrentOrder?.orderNumber) {\n return;\n }\n\n let allTicketsOfOrder: any[] = [];\n order.orderedItem?.forEach((item) => {\n allTicketsOfOrder = allTicketsOfOrder.concat(item.ticket);\n });\n allTicketsOfOrder = allTicketsOfOrder.map((ticket) => ticket.identifier);\n\n ctx.patchState({\n ticketsOfCurrentOrder: {\n orderNumber: order.orderNumber,\n ticketsIds: allTicketsOfOrder,\n },\n });\n }\n}\n"], "mappings": "wSAGA,IAAaA,GAAS,IAAA,CAAhB,MAAOA,CAAS,QACK,KAAAC,KAAO,yBAA0B,CACxDC,YAAmBC,EAAU,CAAV,KAAAA,GAAAA,CAAa,SAFvBH,CAAS,GAAA,EAKTI,GAAwB,IAAA,CAA/B,MAAOA,CAAwB,QACV,KAAAH,KAAO,2CAA4C,CAC1EC,YAAmBG,EAAa,CAAb,KAAAA,MAAAA,CAAgB,SAF1BD,CAAwB,GAAA,EAKxBE,GAAoB,IAAA,CAA3B,MAAOA,CAAoB,QACN,KAAAL,KAAO,uCAAwC,CACtEC,YAAmBC,EAAU,CAAV,KAAAA,GAAAA,CAAa,SAFvBG,CAAoB,GAAA,EAKpBC,GAAoB,IAAA,CAA3B,MAAOA,CAAoB,QACN,KAAAN,KAAO,uCAAwC,CACtEC,YAAmBC,EAAU,CAAV,KAAAA,GAAAA,CAAa,SAFvBI,CAAoB,GAAA,QCqBpBC,EAAN,MAAMA,CA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B,CAAC,EAAAxD,EAAA,UAAA,uBAAA,IAAA,EAmBtBsD,EAAA,CADNC,EAAOE,CAAoB,CAAC,EAAAzD,EAAA,UAAA,uBAAA,IAAA,EAoBhBsD,EAAA,CADZC,EAAOG,CAAS,CAAC,EAAA1D,EAAA,UAAA,YAAA,IAAA,EA4BXsD,EAAA,CADNC,EAAOI,CAAwB,CAAC,EAAA3D,EAAA,UAAA,2BAAA,IAAA,EA1GnBsD,EAAA,CADbM,EAAQ,CAAE,EAAA5D,EAAA,SAAA,IAAA,EAMGsD,EAAA,CADbM,EAAQ,CAAE,EAAA5D,EAAA,wBAAA,IAAA,EAMGsD,EAAA,CADbM,EAAQ,CAAE,EAAA5D,EAAA,UAAA,IAAA,EAMGsD,EAAA,CADbM,EAAQ,CAAE,EAAA5D,EAAA,WAAA,IAAA,EAMGsD,EAAA,CADbM,EAAQ,CAAE,EAAA5D,EAAA,QAAA,IAAA,EA3BFA,EAAgBc,EAAAwC,EAAA,CAX5BO,EAAwB,CACrBC,KAAM,aACNC,SAAU,CACN1D,OAAQ,KACRG,QAAS,GACTC,SAAU,GACVC,MAAO,KACPH,sBAAuB,MAE9B,CAAC,EAEWP,CAAgB", "names": ["GetTicket", "type", "constructor", "id", "SetTicketsOfCurrentOrder", "order", "GetPrevTicketInOrder", "GetNextTicketInOrder", "TicketsItemState", "constructor", "ticketsService", "store", "insights", "ticket", "state", "ticketsOfCurrentOrder", "loading", "hasValue", "error", "hasPrevValueInOrder", "id", "createSelector", "TicketsItemState_1", "ticketsIds", "findIndex", "ticketId", "hasNextValueInOrder", "length", "getPrevTicketInOrder", "ctx", "getState", "indexOfPrev", "dispatch", "Navigate", "orderNumber", "getNextTicketInOrder", "indexOfNext", "getTicket", "_1", "__async", "patchState", "firstValueFrom", "getTicketById", "errorHandler", "appInsightsSrv", "scope", "message", "setTicketsOfCurrentOrder", "order", "allTicketsOfOrder", "orderedItem", "forEach", "item", "concat", "map", "identifier", "\u0275\u0275inject", "TicketsService", "Store", "AppInsightsService", "factory", "\u0275fac", "__decorate", "Action", "GetPrevTicketInOrder", "GetNextTicketInOrder", "GetTicket", "SetTicketsOfCurrentOrder", "Selector", "State", "name", "defaults"] }