{ "version": 3, "sources": ["src/app/store/orders/orders.actions.ts", "src/app/enums/order-status.enum.ts", "src/app/store/orders/orders.state.ts"], "sourcesContent": ["export class GetOrders {\n public static readonly type = '[Orders] Get orders by partner';\n constructor(public partner?: string) {}\n}\n\nexport class GetNextOrders {\n public static readonly type = '[Orders] Get next orders';\n}\n\nexport class GetNextOrder {\n public static readonly type = '[Orders] Get next order';\n constructor(public id: string) {\n }\n}\n\nexport class GetPrevOrder {\n public static readonly type = '[Orders] Get prev order';\n constructor(public id: string) {\n }\n}\n\n", "export enum OrderStatusEnum {\n New = 'New',\n Checkout = 'Checkout',\n Placed = 'Placed',\n Payment = 'Payment',\n Paid = 'Paid',\n InTransit = 'InTransit',\n Delivered = 'Delivered',\n Fulfilled = 'Fulfilled',\n Canceled = 'Canceled',\n Expired = 'Expired',\n Error = 'Error',\n FulfillmentError = 'FulfillmentError',\n Deleted = 'Deleted',\n}\n", "import {Action, createSelector, Selector, State, StateContext, Store} from '@ngxs/store';\nimport {Injectable} from '@angular/core';\nimport {GetNextOrder, GetNextOrders, GetOrders, GetPrevOrder} from './orders.actions';\nimport {IOrder} from 'src/app/interfaces/general/profile-definitions/order.interface';\nimport {OrdersService} from 'src/app/modules/orders/orders.service';\nimport {ItemPayload} from 'src/app/interfaces/general/responses/item-payload.interface';\nimport {Navigate} from '@ngxs/router-plugin';\nimport {OrderStatusEnum} from 'src/app/enums/order-status.enum';\nimport {firstValueFrom} from 'rxjs';\nimport {AppInsightsService} from 'src/app/core/app-insights/app-insights.service';\nimport {errorHandler, IErrorHandlerArgs} from 'src/app/shared/helpers/error-handler';\n\nexport interface IOrdersState {\n partner?: string;\n orders: IOrder[];\n loading: boolean;\n hasValue: boolean;\n nextPageToken?: string;\n error: any,\n}\n\n@State({\n name: 'orders',\n defaults: {\n partner: '',\n orders: [],\n loading: false,\n hasValue: false,\n nextPageToken: null,\n error: null,\n },\n})\n@Injectable()\nexport class OrdersState {\n private _errorHandlerArgsInit: IErrorHandlerArgs = {\n error: null,\n appInsightsSrv: this.insights,\n scope: 'OrdersState',\n };\n constructor(\n private ordersService: OrdersService,\n private store: Store,\n private insights: AppInsightsService,\n ) { }\n\n @Selector()\n public static orders(state: IOrdersState): IOrder[] {\n return state.orders;\n }\n\n @Selector()\n public static loading(state: IOrdersState): boolean {\n return state.loading;\n }\n\n @Selector()\n public static hasValue(state: IOrdersState): boolean {\n return !!state.orders?.length;\n }\n\n @Selector()\n public static hasValueInStatusDone(state: IOrdersState): boolean {\n return state.orders?.some((order) => {\n return (\n order.orderStatus === OrderStatusEnum.Canceled ||\n order.orderStatus === OrderStatusEnum.FulfillmentError ||\n order.orderStatus === OrderStatusEnum.Fulfilled\n );\n });\n }\n\n public static hasPrevValue(id: string) {\n return createSelector([OrdersState], (state: IOrdersState) => {\n return state.orders?.findIndex((order) => order.orderNumber === id) > 0;\n });\n }\n\n public static hasNextValue(id: string) {\n return createSelector([OrdersState], (state: IOrdersState) => {\n return (\n state.orders.findIndex((order) => order.orderNumber === id) <\n state.orders.length - 1\n );\n });\n }\n\n @Action(GetOrders)\n public async getOrders(ctx: StateContext, {partner}: GetOrders): Promise {\n ctx.patchState({loading: true, error: null});\n try {\n const orders: ItemPayload = await firstValueFrom(\n this.ordersService.getOrders(undefined, partner)\n );\n ctx.patchState({\n partner,\n orders: orders.data,\n hasValue: !!orders.data.length,\n nextPageToken: orders.nextPageToken,\n loading: false,\n });\n } catch (error) {\n errorHandler({...this._errorHandlerArgsInit, error});\n ctx.patchState({\n loading: false,\n error,\n });\n }\n }\n\n @Action(GetNextOrders)\n public async getNextOrders(ctx: StateContext): Promise {\n const partner = ctx.getState().partner;\n const orders = ctx.getState().orders;\n const nextPageToken = ctx.getState().nextPageToken;\n if (nextPageToken) {\n ctx.patchState({loading: true, error: null});\n try {\n const ordersState: ItemPayload = await firstValueFrom(\n this.ordersService.getOrders(nextPageToken, partner)\n );\n ctx.patchState({\n partner,\n orders: [...orders, ...ordersState.data],\n nextPageToken: ordersState.nextPageToken,\n loading: false,\n });\n } catch (error) {\n errorHandler({...this._errorHandlerArgsInit, error});\n ctx.patchState({\n loading: false,\n error,\n });\n }\n }\n }\n\n @Action(GetPrevOrder)\n public getPrevOrder(ctx: StateContext, {id}: GetPrevOrder): void {\n const state = ctx.getState();\n const orders = state.orders;\n const index = orders?.findIndex((order) => order.orderNumber === id);\n if (index > 0) {\n this.store.dispatch(new Navigate(['/', 'orders', orders[index - 1].orderNumber]));\n }\n }\n\n @Action(GetNextOrder)\n public getNextOrder(ctx: StateContext, {id}: GetNextOrder): void {\n const state = ctx.getState();\n const orders = state.orders;\n const index = orders.findIndex((order) => order.orderNumber === id);\n if (index === orders.length - 2) {\n this.store.dispatch(new GetNextOrders());\n this.store.dispatch(new Navigate(['/', 'orders', orders[index + 1].orderNumber]));\n }\n\n if (index < orders.length - 2) {\n this.store.dispatch(new Navigate(['/', 'orders', orders[index + 1].orderNumber]));\n }\n }\n}\n"], "mappings": "sTAAA,IAAaA,GAAS,IAAA,CAAhB,MAAOA,CAAS,QACK,KAAAC,KAAO,gCAAiC,CAC/DC,YAAmBC,EAAgB,CAAhB,KAAAA,QAAAA,CAAmB,SAF7BH,CAAS,GAAA,EAKTI,GAAa,IAAA,CAApB,MAAOA,CAAa,QACC,KAAAH,KAAO,0BAA2B,SADhDG,CAAa,GAAA,EAIbC,GAAY,IAAA,CAAnB,MAAOA,CAAY,QACE,KAAAJ,KAAO,yBAA0B,CACxDC,YAAmBI,EAAU,CAAV,KAAAA,GAAAA,CACnB,SAHSD,CAAY,GAAA,EAMZE,GAAY,IAAA,CAAnB,MAAOA,CAAY,QACE,KAAAN,KAAO,yBAA0B,CACxDC,YAAmBI,EAAU,CAAV,KAAAA,GAAAA,CACnB,SAHSC,CAAY,GAAA,ECfzB,IAAYC,EAAZ,SAAYA,EAAe,CACvBA,OAAAA,EAAA,IAAA,MACAA,EAAA,SAAA,WACAA,EAAA,OAAA,SACAA,EAAA,QAAA,UACAA,EAAA,KAAA,OACAA,EAAA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SACNC,SAAU,CACNhC,QAAS,GACTxB,OAAQ,CAAA,EACRE,QAAS,GACTC,SAAU,GACV0B,cAAe,KACfhC,MAAO,MAEd,CAAC,EAEWN,CAAW", "names": ["GetOrders", "type", "constructor", "partner", "GetNextOrders", "GetNextOrder", "id", "GetPrevOrder", "OrderStatusEnum", "OrdersState", "constructor", "ordersService", "store", "insights", "_errorHandlerArgsInit", "error", "appInsightsSrv", "scope", "orders", "state", "loading", "hasValue", "length", "hasValueInStatusDone", "some", "order", "orderStatus", "OrderStatusEnum", "Canceled", "FulfillmentError", "Fulfilled", "hasPrevValue", "id", "createSelector", "OrdersState_1", "findIndex", "orderNumber", "hasNextValue", "getOrders", "ctx", "_1", "__async", "partner", "patchState", "firstValueFrom", "undefined", "data", "nextPageToken", "errorHandler", "__spreadProps", "__spreadValues", "getNextOrders", "getState", "ordersState", "getPrevOrder", "index", "dispatch", "Navigate", "getNextOrder", "GetNextOrders", "\u0275\u0275inject", "OrdersService", "Store", "AppInsightsService", "factory", "\u0275fac", "__decorate", "Action", "GetOrders", "GetPrevOrder", "GetNextOrder", "Selector", "State", "name", "defaults"] }