Skip to content

Commit

Permalink
fix: display orders on cost center details page
Browse files Browse the repository at this point in the history
* additionally some minor improvements to increase robustness
  • Loading branch information
SGrueber committed Dec 4, 2024
1 parent d84dffd commit 58f1aec
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/app/core/models/cost-center/cost-center.mapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down
7 changes: 6 additions & 1 deletion src/app/core/models/cost-center/cost-center.mapper.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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: {
Expand Down
5 changes: 4 additions & 1 deletion src/app/core/models/cost-center/cost-center.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ export interface CostCenter extends CostCenterBase {
spentBudget?: Price;
remainingBudget?: Price;
buyers?: CostCenterBuyer[];
orders?: Pick<Order, 'documentNo' | 'creationDate' | 'status' | 'attributes' | 'totalProductQuantity' | 'totals'>[];
orders?: Pick<
Order,
'documentNo' | 'creationDate' | 'status' | 'attributes' | 'user' | 'totalProductQuantity' | 'totals'
>[];
}
2 changes: 1 addition & 1 deletion src/app/core/store/customer/orders/orders.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }))
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -252,11 +252,9 @@ export class AccountOrderFiltersComponent implements OnInit, AfterViewInit {
}

private getModel(params?: UrlModel): Observable<FormModel> {
this.modelChange.emit(urlToQuery(params));
return this.isAdmin$.pipe(
distinctUntilChanged(),
tap(() => {
this.modelChange.emit(urlToQuery(params));
}),
map(isAdmin => ({
date:
params?.from || params?.to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{{ 'account.orderlist.table.buyer' | translate }}
</th>
<td cdk-cell *cdkCellDef="let order" [attr.data-label]="'account.orderlist.table.buyer' | translate">
{{ order.user.firstName }} {{ order.user.lastName }}
{{ order.user?.firstName }} {{ order.user?.lastName }}
</td>
</ng-container>

Expand Down

0 comments on commit 58f1aec

Please sign in to comment.