-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: recurring orders listing in my account (initial, service but no…
… state management)
- Loading branch information
Showing
20 changed files
with
295 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/app/core/models/recurring-order/recurring-order.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Link } from 'ish-core/models/link/link.model'; | ||
import { PriceData } from 'ish-core/models/price/price.interface'; | ||
import { UserData } from 'ish-core/models/user/user.interface'; | ||
|
||
export interface RecurringOrderData { | ||
number: string; | ||
creationDate: number; | ||
startDate: number; | ||
nextOrderDate: number; | ||
totalNet: PriceData; | ||
totalGross: PriceData; | ||
interval: string; | ||
repetitions: number; | ||
active: boolean; | ||
expired: boolean; | ||
itemCount: number; | ||
priceType: string; | ||
buyer: UserData; | ||
link: Link; | ||
} |
28 changes: 28 additions & 0 deletions
28
src/app/core/models/recurring-order/recurring-order.mapper.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { RecurringOrderData } from './recurring-order.interface'; | ||
import { RecurringOrderMapper } from './recurring-order.mapper'; | ||
|
||
describe('Recurring Order Mapper', () => { | ||
let recurringOrderMapper: RecurringOrderMapper; | ||
|
||
beforeEach(() => { | ||
recurringOrderMapper = TestBed.inject(RecurringOrderMapper); | ||
}); | ||
|
||
describe('fromData', () => { | ||
it('should throw when input is falsy', () => { | ||
expect(() => recurringOrderMapper.fromData(undefined)).toThrow(); | ||
Check failure on line 15 in src/app/core/models/recurring-order/recurring-order.mapper.spec.ts GitHub Actions / Quality
|
||
}); | ||
|
||
it('should map incoming data to model data', () => { | ||
const data: RecurringOrderData = { | ||
incomingField: 'test', | ||
otherField: false, | ||
}; | ||
const mapped = recurringOrderMapper.fromData(data); | ||
Check failure on line 23 in src/app/core/models/recurring-order/recurring-order.mapper.spec.ts GitHub Actions / Quality
|
||
expect(mapped).toHaveProperty('id', 'test'); | ||
expect(mapped).not.toHaveProperty('otherField'); | ||
}); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
src/app/core/models/recurring-order/recurring-order.mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
import { PriceMapper } from 'ish-core/models/price/price.mapper'; | ||
|
||
import { RecurringOrderData } from './recurring-order.interface'; | ||
import { RecurringOrder } from './recurring-order.model'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class RecurringOrderMapper { | ||
static fromData(recurringOrderData: RecurringOrderData[]): RecurringOrder[] { | ||
console.log('RECURRING ORDER DATA MAPPER', recurringOrderData); | ||
Check warning on line 11 in src/app/core/models/recurring-order/recurring-order.mapper.ts GitHub Actions / GitBash
Check warning on line 11 in src/app/core/models/recurring-order/recurring-order.mapper.ts GitHub Actions / Powershell
|
||
if (recurringOrderData.length) { | ||
return recurringOrderData.map(data => ({ | ||
id: data.link.title, | ||
number: data.number, | ||
creationDate: data.creationDate, | ||
startDate: data.startDate, | ||
nextOrderDate: data.nextOrderDate, | ||
interval: data.interval, | ||
repetitions: data.repetitions, | ||
active: data.active, | ||
expired: data.expired, | ||
itemCount: data.itemCount, | ||
priceType: data.priceType, | ||
totalNet: PriceMapper.fromData(data.totalNet), | ||
totalGross: PriceMapper.fromData(data.totalGross), | ||
buyer: data.buyer, | ||
})); | ||
} else { | ||
return []; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/app/core/models/recurring-order/recurring-order.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Price } from 'ish-core/models/price/price.model'; | ||
import { User } from 'ish-core/models/user/user.model'; | ||
|
||
export interface RecurringOrder { | ||
id: string; | ||
number: string; | ||
creationDate: number; | ||
startDate: number; | ||
nextOrderDate: number; | ||
interval: string; | ||
repetitions: number; | ||
active: boolean; | ||
expired: boolean; | ||
itemCount: number; | ||
priceType: string; | ||
totalNet: Price; | ||
totalGross: Price; | ||
buyer: User; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/app/core/services/recurring-orders/recurring-orders.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { instance, mock } from 'ts-mockito'; | ||
|
||
import { ApiService } from 'ish-core/services/api/api.service'; | ||
|
||
import { RecurringOrdersService } from './recurring-orders.service'; | ||
|
||
describe('Recurring Orders Service', () => { | ||
let apiServiceMock: ApiService; | ||
let recurringOrdersService: RecurringOrdersService; | ||
|
||
beforeEach(() => { | ||
apiServiceMock = mock(ApiService); | ||
TestBed.configureTestingModule({ | ||
providers: [{ provide: ApiService, useFactory: () => instance(apiServiceMock) }], | ||
}); | ||
recurringOrdersService = TestBed.inject(RecurringOrdersService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(recurringOrdersService).toBeTruthy(); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
src/app/core/services/recurring-orders/recurring-orders.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Store, select } from '@ngrx/store'; | ||
import { iif, map, switchMap, take } from 'rxjs'; | ||
|
||
import { RecurringOrderData } from 'ish-core/models/recurring-order/recurring-order.interface'; | ||
import { RecurringOrderMapper } from 'ish-core/models/recurring-order/recurring-order.mapper'; | ||
import { ApiService, unpackEnvelope } from 'ish-core/services/api/api.service'; | ||
import { getLoggedInCustomer } from 'ish-core/store/customer/user'; | ||
import { whenTruthy } from 'ish-core/utils/operators'; | ||
import { encodeResourceID } from 'ish-core/utils/url-resource-ids'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class RecurringOrdersService { | ||
constructor(private apiService: ApiService, private store: Store) {} | ||
|
||
private currentCustomer$ = this.store.pipe(select(getLoggedInCustomer), whenTruthy(), take(1)); | ||
|
||
getRecurringOrders() { | ||
return this.currentCustomer$.pipe( | ||
switchMap(customer => | ||
iif( | ||
() => customer.isBusinessCustomer, | ||
this.apiService.b2bUserEndpoint().get(`recurringorders`), | ||
this.apiService.get(`privatecustomers/${encodeResourceID(customer.customerNo)}/recurringorders`) | ||
).pipe( | ||
unpackEnvelope<RecurringOrderData>(), | ||
map(data => RecurringOrderMapper.fromData(data)) | ||
) | ||
) | ||
); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/app/pages/account-recurring-orders/account-recurring-orders-page.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>{{ 'account.recurring_orders.heading' | translate }}</h1> | ||
|
||
<ng-container *ngIf="recurringOrders$ | async as recurringOrders"> | ||
<ish-recurring-order-list [recurringOrders]="recurringOrders" /> | ||
</ng-container> |
27 changes: 27 additions & 0 deletions
27
src/app/pages/account-recurring-orders/account-recurring-orders-page.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { AccountRecurringOrdersPageComponent } from './account-recurring-orders-page.component'; | ||
|
||
describe('Account Recurring Orders Page Component', () => { | ||
let component: AccountRecurringOrdersPageComponent; | ||
let fixture: ComponentFixture<AccountRecurringOrdersPageComponent>; | ||
let element: HTMLElement; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [AccountRecurringOrdersPageComponent], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(AccountRecurringOrdersPageComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
src/app/pages/account-recurring-orders/account-recurring-orders-page.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
|
||
import { AccountFacade } from 'ish-core/facades/account.facade'; | ||
import { RecurringOrder } from 'ish-core/models/recurring-order/recurring-order.model'; | ||
|
||
@Component({ | ||
selector: 'ish-account-recurring-orders-page', | ||
templateUrl: './account-recurring-orders-page.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class AccountRecurringOrdersPageComponent implements OnInit { | ||
recurringOrders$: Observable<RecurringOrder[]>; | ||
|
||
constructor(private accountFacade: AccountFacade) {} | ||
|
||
ngOnInit() { | ||
this.recurringOrders$ = this.accountFacade.recurringOrders$(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/app/pages/account-recurring-orders/account-recurring-orders-page.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { RouterModule, Routes } from '@angular/router'; | ||
|
||
import { SharedModule } from 'ish-shared/shared.module'; | ||
|
||
import { AccountRecurringOrdersPageComponent } from './account-recurring-orders-page.component'; | ||
import { RecurringOrderListComponent } from './recurring-order-list/recurring-order-list.component'; | ||
|
||
const accountRecurringOrdersPageRoutes: Routes = [{ path: '', component: AccountRecurringOrdersPageComponent }]; | ||
|
||
@NgModule({ | ||
imports: [RouterModule.forChild(accountRecurringOrdersPageRoutes), SharedModule], | ||
declarations: [AccountRecurringOrdersPageComponent, RecurringOrderListComponent], | ||
}) | ||
export class AccountRecurringOrdersPageModule {} |
1 change: 1 addition & 0 deletions
1
...p/pages/account-recurring-orders/recurring-order-list/recurring-order-list.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<pre>{{ recurringOrders | json }}</pre> |
27 changes: 27 additions & 0 deletions
27
...ages/account-recurring-orders/recurring-order-list/recurring-order-list.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { RecurringOrderListComponent } from './recurring-order-list.component'; | ||
|
||
describe('Recurring Order List Component', () => { | ||
let component: RecurringOrderListComponent; | ||
let fixture: ComponentFixture<RecurringOrderListComponent>; | ||
let element: HTMLElement; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [RecurringOrderListComponent], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(RecurringOrderListComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
...app/pages/account-recurring-orders/recurring-order-list/recurring-order-list.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; | ||
|
||
import { RecurringOrder } from 'ish-core/models/recurring-order/recurring-order.model'; | ||
|
||
@Component({ | ||
selector: 'ish-recurring-order-list', | ||
templateUrl: './recurring-order-list.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class RecurringOrderListComponent { | ||
@Input() recurringOrders: RecurringOrder[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters