mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
#4134 Einlösecode- Warenkorb Pop Up
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { CommandService } from './command.service';
|
||||
|
||||
export abstract class ActionHandler<T = any> {
|
||||
constructor(readonly action: string) {}
|
||||
abstract handler(data: T): Promise<T>;
|
||||
abstract handler(data: T, service?: CommandService): Promise<T>;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { ModuleWithProviders, NgModule, Type } from '@angular/core';
|
||||
import { ModuleWithProviders, NgModule, Provider, Type } from '@angular/core';
|
||||
import { ActionHandler } from './action-handler.interface';
|
||||
import { CommandService } from './command.service';
|
||||
import { FEATURE_ACTION_HANDLERS, ROOT_ACTION_HANDLERS } from './tokens';
|
||||
|
||||
export function provideActionHandlers(actionHandlers: Type<ActionHandler>[]): Provider[] {
|
||||
return [CommandService, actionHandlers.map((handler) => ({ provide: FEATURE_ACTION_HANDLERS, useClass: handler, multi: true }))];
|
||||
}
|
||||
|
||||
@NgModule({})
|
||||
export class CoreCommandModule {
|
||||
static forRoot(actionHandlers: Type<ActionHandler>[]): ModuleWithProviders<CoreCommandModule> {
|
||||
|
||||
@@ -16,7 +16,7 @@ export class CommandService {
|
||||
throw new Error('Action Handler does not exist');
|
||||
}
|
||||
|
||||
data = await handler.handler(data);
|
||||
data = await handler.handler(data, this);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,78 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { OrderItemsContext } from './order-items.context';
|
||||
import { ActionHandler } from '@core/command';
|
||||
import { ActionHandler, CommandService } from '@core/command';
|
||||
import { KulturpassOrderModalService } from '@shared/modals/kulturpass-order-modal';
|
||||
import { DisplayOrderItemSubsetDTO, OrderItemListItemDTO, ReceiptDTO } from '@swagger/oms';
|
||||
import { DomainReceiptService } from '../receipt.service';
|
||||
import { DomainGoodsService } from '../goods.service';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
@Injectable()
|
||||
export class ShopWithKulturpassActionHandler extends ActionHandler<OrderItemsContext> {
|
||||
constructor(private _modal: KulturpassOrderModalService) {
|
||||
constructor(
|
||||
private _modal: KulturpassOrderModalService,
|
||||
private _receiptService: DomainReceiptService,
|
||||
private _goodsService: DomainGoodsService
|
||||
) {
|
||||
super('SHOP_WITH_KULTURPASS');
|
||||
}
|
||||
|
||||
async handler(data: OrderItemsContext): Promise<OrderItemsContext> {
|
||||
async handler(data: OrderItemsContext, service: CommandService): Promise<OrderItemsContext> {
|
||||
const items: OrderItemListItemDTO[] = [];
|
||||
const receipts: ReceiptDTO[] = [];
|
||||
|
||||
let command: string;
|
||||
for (const item of data.items) {
|
||||
await this._modal.open({ orderItemListItem: item, order: data.order }).afterClosed$.toPromise();
|
||||
const result = await this._modal.open({ orderItemListItem: item, order: data.order }).afterClosed$.toPromise();
|
||||
|
||||
const displayOrder = result.data[0];
|
||||
command = result.data[1];
|
||||
|
||||
if (displayOrder) {
|
||||
const subsetItems = displayOrder.items.reduce((acc, item) => [...acc, ...item.subsetItems], [] as DisplayOrderItemSubsetDTO[]);
|
||||
|
||||
const orderItems = await this.getItems(displayOrder.orderNumber);
|
||||
|
||||
items.push(...orderItems);
|
||||
|
||||
const subsetItemIds = subsetItems.map((item) => item.id);
|
||||
|
||||
const r = await this.getReceipts(subsetItemIds);
|
||||
|
||||
receipts.push(...r);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
|
||||
if (!command) {
|
||||
return {
|
||||
...data,
|
||||
items,
|
||||
receipts,
|
||||
};
|
||||
} else {
|
||||
return service.handleCommand(command, {
|
||||
...data,
|
||||
items,
|
||||
receipts,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
getReceipts(ids: number[]) {
|
||||
return this._receiptService
|
||||
.getReceipts({
|
||||
receiptType: 128,
|
||||
eagerLoading: 1,
|
||||
ids,
|
||||
})
|
||||
.pipe(map((res) => res.result.map((data) => data.item3.data).filter((data) => !!data)))
|
||||
.toPromise();
|
||||
}
|
||||
|
||||
getItems(orderNumber: string) {
|
||||
return this._goodsService
|
||||
.getWarenausgabeItemByOrderNumber(orderNumber, false)
|
||||
.pipe(map((res) => res.result))
|
||||
.toPromise();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { BranchNamePipe } from '@shared/pipes/branch';
|
||||
import { combineLatest } from 'rxjs';
|
||||
import { KulturpassOrderItemComponent } from './kulturpass-order-item/kulturpass-order-item.component';
|
||||
import { LoaderComponent } from '@shared/components/loader';
|
||||
|
||||
import { DisplayOrderDTO, KeyValueDTOOfStringAndString } from '@swagger/oms';
|
||||
@Component({
|
||||
selector: 'shared-kulturpass-order-modal',
|
||||
templateUrl: 'kulturpass-order-modal.component.html',
|
||||
@@ -49,7 +49,10 @@ export class KulturpassOrderModalComponent implements OnInit {
|
||||
map(([emptyShoppingCart, negativeBalance, ordering]) => emptyShoppingCart || negativeBalance || ordering)
|
||||
);
|
||||
|
||||
constructor(private _modalRef: UiModalRef<void, KulturpassOrderModalData>, private _store: KulturpassOrderModalStore) {}
|
||||
constructor(
|
||||
private _modalRef: UiModalRef<[DisplayOrderDTO, string], KulturpassOrderModalData>,
|
||||
private _store: KulturpassOrderModalStore
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this._store.updateOrder(this._modalRef.data.order);
|
||||
@@ -65,8 +68,10 @@ export class KulturpassOrderModalComponent implements OnInit {
|
||||
}
|
||||
|
||||
order() {
|
||||
this._store.handleOrderResponse = () => {
|
||||
return this._modalRef.close();
|
||||
this._store.onOrderSuccess = async (displayOrder: DisplayOrderDTO, action: KeyValueDTOOfStringAndString[]) => {
|
||||
const command = action.map((action) => action.command).join('|');
|
||||
|
||||
this._modalRef.close([displayOrder, command]);
|
||||
};
|
||||
this._store.orderItems();
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@ import { UiModalRef, UiModalService } from '@ui/modal';
|
||||
import { KulturpassOrderModalData } from './kulturpass-order-modal.data';
|
||||
import { KulturpassOrderModalComponent } from './kulturpass-order-modal.component';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { DisplayOrderDTO } from '@swagger/oms';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class KulturpassOrderModalService {
|
||||
constructor(private modal: UiModalService) {}
|
||||
|
||||
open(data: KulturpassOrderModalData): UiModalRef<string, KulturpassOrderModalData> {
|
||||
return this.modal.open<string, KulturpassOrderModalData>({
|
||||
open(data: KulturpassOrderModalData): UiModalRef<[DisplayOrderDTO, string], KulturpassOrderModalData> {
|
||||
return this.modal.open<[DisplayOrderDTO, string], KulturpassOrderModalData>({
|
||||
content: KulturpassOrderModalComponent,
|
||||
data,
|
||||
config: {
|
||||
|
||||
@@ -3,7 +3,15 @@ import { ComponentStore, OnStoreInit, tapResponse } from '@ngrx/component-store'
|
||||
import { AddToShoppingCartDTO, BranchDTO, CheckoutDTO, ShoppingCartDTO, ShoppingCartItemDTO } from '@swagger/checkout';
|
||||
import { DomainCheckoutService } from '@domain/checkout';
|
||||
import { switchMap, tap, withLatestFrom } from 'rxjs/operators';
|
||||
import { BranchService, OrderDTO, OrderItemListItemDTO, ResponseArgsOfIEnumerableOfBranchDTO } from '@swagger/oms';
|
||||
import {
|
||||
BranchService,
|
||||
DisplayOrderDTO,
|
||||
KeyValueDTOOfStringAndString,
|
||||
OrderDTO,
|
||||
OrderItemListItemDTO,
|
||||
ResponseArgsOfIEnumerableOfBranchDTO,
|
||||
ResponseArgsOfValueTupleOfIEnumerableOfDisplayOrderDTOAndIEnumerableOfKeyValueDTOOfStringAndString,
|
||||
} from '@swagger/oms';
|
||||
import { Observable } from 'rxjs';
|
||||
import { AuthService } from '@core/auth';
|
||||
import { UiModalService } from '@ui/modal';
|
||||
@@ -170,7 +178,11 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
)
|
||||
);
|
||||
|
||||
handleOrderResponse = (res: any) => {};
|
||||
handleOrderResponse = (res: ResponseArgsOfValueTupleOfIEnumerableOfDisplayOrderDTOAndIEnumerableOfKeyValueDTOOfStringAndString) => {
|
||||
this.onOrderSuccess(res.result.item1[0], res.result.item2);
|
||||
};
|
||||
|
||||
onOrderSuccess = (displayOrder: DisplayOrderDTO, action: KeyValueDTOOfStringAndString[]) => {};
|
||||
|
||||
handleOrderError = (err: any) => {
|
||||
this._modal.error('Fehler beim Bestellen', err);
|
||||
|
||||
Reference in New Issue
Block a user