Skip to content

Commit

Permalink
fix: broken page on missing requisition data like user and budget (#859)
Browse files Browse the repository at this point in the history
  • Loading branch information
DiverDori authored and shauke committed Sep 1, 2021
1 parent 72a439f commit 0f3f847
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
{{ 'account.approvallist.table.buyer' | translate }}
</th>
<td cdk-cell *cdkCellDef="let requisition" [attr.data-label]="'account.approvallist.table.buyer' | translate">
{{ requisition.user.firstName }} {{ requisition.user.lastName }}
{{ requisition.user?.firstName }} {{ requisition.user?.lastName }}
</td>
</ng-container>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('Requisition Mapper', () => {
id: 'testUUDI',
requisitionNo: '0001',
orderNo: '10001',
purchaseCurrency: 'USD',
invoiceToAddress: 'urn_invoiceToAddress_123',
commonShipToAddress: 'urn_commonShipToAddress_123',
commonShippingMethod: 'shipping_method_123',
Expand Down Expand Up @@ -74,7 +75,7 @@ describe('Requisition Mapper', () => {
"orderNo": "10001",
"payment": undefined,
"promotionCodes": undefined,
"purchaseCurrency": undefined,
"purchaseCurrency": "USD",
"requisitionNo": "0001",
"totalProductQuantity": undefined,
"totals": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@ import { PriceItemMapper } from 'ish-core/models/price-item/price-item.mapper';
import { Price } from 'ish-core/models/price/price.model';

import { RequisitionData } from './requisition.interface';
import { Requisition } from './requisition.model';
import { Requisition, RequisitionUserBudget } from './requisition.model';

@Injectable({ providedIn: 'root' })
export class RequisitionMapper {
fromData(payload: RequisitionData, orderPayload?: OrderData): Requisition {
if (!Array.isArray(payload.data)) {
const { data } = payload;
const emptyPrice: Price = {
type: 'Money',
value: 0,
currency: data.userBudgets?.budget?.currency,
};

if (data) {
const payloadData = (orderPayload ? orderPayload : payload) as BasketData;
Expand All @@ -30,7 +25,7 @@ export class RequisitionMapper {
requisitionNo: data.requisitionNo,
orderNo: data.orderNo,
creationDate: data.creationDate,
userBudget: { ...data.userBudgets, spentBudget: data.userBudgets?.spentBudget || emptyPrice },
userBudget: this.fromUserBudgets(data.userBudgets, data.purchaseCurrency),
lineItemCount: data.lineItemCount,
user: data.userInformation,
approval: {
Expand Down Expand Up @@ -68,4 +63,16 @@ export class RequisitionMapper {
);
}
}

private fromUserBudgets(userBudgets: RequisitionUserBudget, purchaseCurrency: string): RequisitionUserBudget {
if (!(userBudgets && userBudgets.budgetPeriod)) {
return;
}
const emptyPrice: Price = {
type: 'Money',
value: 0,
currency: purchaseCurrency,
};
return { ...userBudgets, spentBudget: userBudgets.spentBudget || emptyPrice };
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div *ngIf="requisition" class="row">
<div *ngIf="requisition && requisition.userBudget" class="row">
<ish-info-box heading="approval.detailspage.buyer_budget.heading" class="infobox-wrapper col-12">
<div class="row">
<div class="col-md-6">
Expand Down

0 comments on commit 0f3f847

Please sign in to comment.