Skip to content

Commit

Permalink
feat: fit recurring order mapper to REST API changes and separated li…
Browse files Browse the repository at this point in the history
…st and detail handling
  • Loading branch information
shauke committed Sep 4, 2024
1 parent 027c4fd commit 1ac043e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { AddressData } from 'ish-core/models/address/address.interface';
import { Link } from 'ish-core/models/link/link.model';
import { OrderLineItem } from 'ish-core/models/order/order.model';
import { PriceAmountData } from 'ish-core/models/price/price.interface';
import { ShippingMethod } from 'ish-core/models/shipping-method/shipping-method.model';
import { UserData } from 'ish-core/models/user/user.interface';

export interface RecurringOrderData extends Omit<RecurringOrderLinkData, 'link' | 'totalNet' | 'totalGross'> {
id: string;

export interface RecurringOrderData extends Omit<RecurringOrderLinkData, 'totalNet' | 'totalGross'> {
orderCount?: number;
totals: RecurringOrderTotalsData;

Expand All @@ -24,7 +21,7 @@ export interface RecurringOrderData extends Omit<RecurringOrderLinkData, 'link'
}

export interface RecurringOrderLinkData {
link: Link;
id: string;
number: string;
active: boolean;
expired: boolean;
Expand Down
72 changes: 44 additions & 28 deletions src/app/core/models/recurring-order/recurring-order.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,45 @@ export class RecurringOrderMapper {
if (!recurringOrderData.length) {
return [];
}
return recurringOrderData.map(data => RecurringOrderMapper.fromData(data));
return recurringOrderData.map(data => ({
id: data.id,
number: data.number,
active: data.active,
expired: data.expired,

// TODO: check recurrence date handling - string vs. number
recurrence: {
interval: data.interval,
startDate: data.startDate?.toString(),
endDate: data.endDate?.toString(),
repetitions: data.repetitions,
},

creationDate: data.creationDate,
lastOrderDate: data.lastOrderDate,
nextOrderDate: data.nextOrderDate,

user: UserMapper.fromData(data.buyer),

totals: {

Check warning on line 37 in src/app/core/models/recurring-order/recurring-order.mapper.ts

View workflow job for this annotation

GitHub Actions / GitBash

Type assertion on object literals is forbidden, use a type annotation instead

Check warning on line 37 in src/app/core/models/recurring-order/recurring-order.mapper.ts

View workflow job for this annotation

GitHub Actions / CommandLine

Type assertion on object literals is forbidden, use a type annotation instead

Check warning on line 37 in src/app/core/models/recurring-order/recurring-order.mapper.ts

View workflow job for this annotation

GitHub Actions / Powershell

Type assertion on object literals is forbidden, use a type annotation instead
total: {
type: 'PriceItem',
gross: data.totalGross.amount,
net: data.totalNet.amount,
currency: data.totalGross.currency,
},
} as BasketTotal,
}));
}

static fromData(data: RecurringOrderData | RecurringOrderLinkData): RecurringOrder {
static fromData(data: RecurringOrderData): RecurringOrder {
console.log('RECURRING ORDER DATA MAPPER', data);

Check warning on line 49 in src/app/core/models/recurring-order/recurring-order.mapper.ts

View workflow job for this annotation

GitHub Actions / GitBash

Unexpected console statement

Check warning on line 49 in src/app/core/models/recurring-order/recurring-order.mapper.ts

View workflow job for this annotation

GitHub Actions / CommandLine

Unexpected console statement

Check warning on line 49 in src/app/core/models/recurring-order/recurring-order.mapper.ts

View workflow job for this annotation

GitHub Actions / Powershell

Unexpected console statement
if (!data) {
return;
}

const detailData = 'id' in data;

console.log('RECURRING ORDER DATA MAPPER', detailData, data);

return {
id: detailData ? data.id : data.link?.title,
id: data.id,
number: data.number,
active: data.active,
expired: data.expired,
Expand All @@ -43,33 +68,24 @@ export class RecurringOrderMapper {
creationDate: data.creationDate,
lastOrderDate: data.lastOrderDate,
nextOrderDate: data.nextOrderDate,
orderCount: detailData ? data.orderCount : undefined,
orderCount: data.orderCount,

user: UserMapper.fromData(data.buyer),

invoiceToAddress: detailData ? data.invoiceToAddress : undefined,
commonShipToAddress: detailData ? data.shippingBuckets?.[0]?.shipToAddress : undefined,
commonShippingMethod: detailData ? data.shippingBuckets?.[0]?.shippingMethod : undefined,
payment: detailData
? ({ id: data.payments?.[0].id, displayName: data.payments?.[0].name } as Payment)
: undefined,
invoiceToAddress: data.invoiceToAddress,
commonShipToAddress: data.shippingBuckets?.[0]?.shipToAddress,
commonShippingMethod: data.shippingBuckets?.[0]?.shippingMethod,
payment: { id: data.payments?.[0].id, displayName: data.payments?.[0].name } as Payment,

Check warning on line 78 in src/app/core/models/recurring-order/recurring-order.mapper.ts

View workflow job for this annotation

GitHub Actions / GitBash

Type assertion on object literals is forbidden, use a type annotation instead

Check warning on line 78 in src/app/core/models/recurring-order/recurring-order.mapper.ts

View workflow job for this annotation

GitHub Actions / CommandLine

Type assertion on object literals is forbidden, use a type annotation instead

Check warning on line 78 in src/app/core/models/recurring-order/recurring-order.mapper.ts

View workflow job for this annotation

GitHub Actions / Powershell

Type assertion on object literals is forbidden, use a type annotation instead

lineItems: detailData ? data.shippingBuckets?.[0]?.lineItems : undefined,
lineItems: data.shippingBuckets?.[0]?.lineItems,

totals: {

Check warning on line 82 in src/app/core/models/recurring-order/recurring-order.mapper.ts

View workflow job for this annotation

GitHub Actions / GitBash

Type assertion on object literals is forbidden, use a type annotation instead

Check warning on line 82 in src/app/core/models/recurring-order/recurring-order.mapper.ts

View workflow job for this annotation

GitHub Actions / CommandLine

Type assertion on object literals is forbidden, use a type annotation instead

Check warning on line 82 in src/app/core/models/recurring-order/recurring-order.mapper.ts

View workflow job for this annotation

GitHub Actions / Powershell

Type assertion on object literals is forbidden, use a type annotation instead
total: detailData
? {
type: 'PriceItem',
gross: data.totals.totalGross.amount,
net: data.totals.totalNet.amount,
currency: data.totals.totalGross.currency,
}
: {
type: 'PriceItem',
gross: data.totalGross.amount,
net: data.totalNet.amount,
currency: data.totalGross.currency,
},
total: {
type: 'PriceItem',
gross: data.totals.totalGross.amount,
net: data.totals.totalNet.amount,
currency: data.totals.totalGross.currency,
},
} as BasketTotal,
};
}
Expand Down

0 comments on commit 1ac043e

Please sign in to comment.