From 58f1aecdb23970a16834b4fe7cab2676dca327c0 Mon Sep 17 00:00:00 2001 From: Silke Date: Wed, 4 Dec 2024 11:58:02 +0100 Subject: [PATCH] fix: display orders on cost center details page * additionally some minor improvements to increase robustness --- src/app/core/models/cost-center/cost-center.mapper.spec.ts | 2 +- src/app/core/models/cost-center/cost-center.mapper.ts | 7 ++++++- src/app/core/models/cost-center/cost-center.model.ts | 5 ++++- src/app/core/store/customer/orders/orders.effects.ts | 2 +- .../account-order-filters.component.ts | 6 ++---- .../components/order/order-list/order-list.component.html | 2 +- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/app/core/models/cost-center/cost-center.mapper.spec.ts b/src/app/core/models/cost-center/cost-center.mapper.spec.ts index 67494efd4b..c4b111f83d 100644 --- a/src/app/core/models/cost-center/cost-center.mapper.spec.ts +++ b/src/app/core/models/cost-center/cost-center.mapper.spec.ts @@ -30,7 +30,7 @@ describe('Cost Center Mapper', () => { expect(costCenter).toBeTruthy(); expect(costCenter.costCenterId).toBe('100400'); expect(costCenter.orders).toHaveLength(2); - expect(costCenter.orders[0].attributes).toHaveLength(1); + expect(costCenter.orders[0].user.firstName).toBe('John'); expect(costCenter.orders[1].totals.total.gross).toBe(1000.23); }); }); diff --git a/src/app/core/models/cost-center/cost-center.mapper.ts b/src/app/core/models/cost-center/cost-center.mapper.ts index 7e62cdb4e4..95c51fad6c 100644 --- a/src/app/core/models/cost-center/cost-center.mapper.ts +++ b/src/app/core/models/cost-center/cost-center.mapper.ts @@ -1,3 +1,5 @@ +import { AttributeHelper } from 'ish-core/models/attribute/attribute.helper'; + import { CostCenterData } from './cost-center.interface'; import { CostCenter } from './cost-center.model'; @@ -10,7 +12,10 @@ export class CostCenterMapper { documentNo: order.orderNo, status: order.orderStatus, creationDate: order.orderDate.toString(), - attributes: order.buyer.attributes, + user: { + firstName: AttributeHelper.getAttributeValueByAttributeName(order.buyer?.attributes, 'firstName'), + lastName: AttributeHelper.getAttributeValueByAttributeName(order.buyer?.attributes, 'lastName'), + }, totalProductQuantity: order.items, totals: { total: { diff --git a/src/app/core/models/cost-center/cost-center.model.ts b/src/app/core/models/cost-center/cost-center.model.ts index bcc61ae50b..89477897a2 100644 --- a/src/app/core/models/cost-center/cost-center.model.ts +++ b/src/app/core/models/cost-center/cost-center.model.ts @@ -34,5 +34,8 @@ export interface CostCenter extends CostCenterBase { spentBudget?: Price; remainingBudget?: Price; buyers?: CostCenterBuyer[]; - orders?: Pick[]; + orders?: Pick< + Order, + 'documentNo' | 'creationDate' | 'status' | 'attributes' | 'user' | 'totalProductQuantity' | 'totals' + >[]; } diff --git a/src/app/core/store/customer/orders/orders.effects.ts b/src/app/core/store/customer/orders/orders.effects.ts index aead236d64..ac82663175 100644 --- a/src/app/core/store/customer/orders/orders.effects.ts +++ b/src/app/core/store/customer/orders/orders.effects.ts @@ -128,7 +128,7 @@ export class OrdersEffects { this.actions$.pipe( ofType(loadMoreOrders), concatLatestFrom(() => this.store.pipe(select(getOrderListQuery))), - map(([, query]) => loadOrders({ query: { ...query, offset: (query.offset ?? 0) + query.limit } })) + map(([, query]) => loadOrders({ query: { ...query, offset: (query?.offset ?? 0) + query.limit } })) ) ); diff --git a/src/app/pages/account-order-history/account-order-filters/account-order-filters.component.ts b/src/app/pages/account-order-history/account-order-filters/account-order-filters.component.ts index eeb0bac0c9..cf4c9ff355 100644 --- a/src/app/pages/account-order-history/account-order-filters/account-order-filters.component.ts +++ b/src/app/pages/account-order-history/account-order-filters/account-order-filters.component.ts @@ -15,7 +15,7 @@ import { UntypedFormGroup } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; import { NgbDateAdapter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap'; import { FormlyFieldConfig } from '@ngx-formly/core'; -import { Observable, distinctUntilChanged, map, shareReplay, takeUntil, tap } from 'rxjs'; +import { Observable, distinctUntilChanged, map, shareReplay, takeUntil } from 'rxjs'; import { AccountFacade } from 'ish-core/facades/account.facade'; import { OrderListQuery } from 'ish-core/models/order-list-query/order-list-query.model'; @@ -252,11 +252,9 @@ export class AccountOrderFiltersComponent implements OnInit, AfterViewInit { } private getModel(params?: UrlModel): Observable { + this.modelChange.emit(urlToQuery(params)); return this.isAdmin$.pipe( distinctUntilChanged(), - tap(() => { - this.modelChange.emit(urlToQuery(params)); - }), map(isAdmin => ({ date: params?.from || params?.to diff --git a/src/app/shared/components/order/order-list/order-list.component.html b/src/app/shared/components/order/order-list/order-list.component.html index 3c7c760b34..c1f31475f1 100644 --- a/src/app/shared/components/order/order-list/order-list.component.html +++ b/src/app/shared/components/order/order-list/order-list.component.html @@ -36,7 +36,7 @@ {{ 'account.orderlist.table.buyer' | translate }} - {{ order.user.firstName }} {{ order.user.lastName }} + {{ order.user?.firstName }} {{ order.user?.lastName }}