-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
126 additions
and
6 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { CommonModule } from '@angular/common' | ||
import { NgModule } from '@angular/core' | ||
|
||
import { AppMaterialModule } from '../app-material.module' | ||
import { PosRoutingModule } from './pos-routing.module' | ||
import { PosComponent } from './pos/pos.component' | ||
|
||
@NgModule({ | ||
declarations: [PosComponent], | ||
imports: [CommonModule, PosRoutingModule], | ||
imports: [CommonModule, PosRoutingModule, AppMaterialModule], | ||
}) | ||
export class PosModule {} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,57 @@ | ||
import { Component, OnInit } from '@angular/core' | ||
import { Component, OnDestroy, OnInit } from '@angular/core' | ||
import { filter, tap } from 'rxjs/operators' | ||
import { SubSink } from 'subsink' | ||
|
||
import { UiService } from '../../common/ui.service' | ||
import { ITransaction } from '../transaction/transaction' | ||
import { TransactionType } from '../transaction/transaction.enum' | ||
import { TransactionService } from '../transaction/transaction.service' | ||
|
||
interface IEvent { | ||
event: 'checkoutCompleted' | 'checkoutInitiated' | ||
} | ||
declare let dataLayer: IEvent[] | ||
|
||
@Component({ | ||
selector: 'app-pos', | ||
templateUrl: './pos.component.html', | ||
styleUrls: ['./pos.component.css'], | ||
}) | ||
export class PosComponent implements OnInit { | ||
constructor() {} | ||
export class PosComponent implements OnInit, OnDestroy { | ||
private subs = new SubSink() | ||
currentTransaction: ITransaction | ||
constructor( | ||
private transactionService: TransactionService, | ||
private uiService: UiService | ||
) {} | ||
|
||
ngOnInit() { | ||
this.currentTransaction = { | ||
paymentAmount: 25.78, | ||
paymentType: TransactionType.Credit, | ||
} as ITransaction | ||
} | ||
|
||
checkout(transaction: ITransaction) { | ||
this.uiService.showToast('Checkout initiated') | ||
dataLayer.push({ | ||
event: 'checkoutInitiated', | ||
}) | ||
this.subs.sink = this.transactionService | ||
.processTransaction(transaction) | ||
.pipe( | ||
filter((tx) => tx != null || tx !== undefined), | ||
tap((transactionId) => { | ||
this.uiService.showToast('Checkout completed') | ||
dataLayer.push({ | ||
event: 'checkoutCompleted', | ||
}) | ||
}) | ||
) | ||
.subscribe() | ||
} | ||
|
||
ngOnInit(): void {} | ||
ngOnDestroy() { | ||
this.subs.unsubscribe() | ||
} | ||
} |
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 @@ | ||
export enum TransactionType { | ||
Cash, | ||
Credit, | ||
LemonCoin, | ||
} |
17 changes: 17 additions & 0 deletions
17
projects/ch14/src/app/pos/transaction/transaction.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,17 @@ | ||
import { HttpClientTestingModule } from '@angular/common/http/testing' | ||
import { TestBed, inject } from '@angular/core/testing' | ||
|
||
import { TransactionService } from './transaction.service' | ||
|
||
describe('TransactionService', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule], | ||
providers: [TransactionService], | ||
}) | ||
}) | ||
|
||
it('should be created', inject([TransactionService], (service: TransactionService) => { | ||
expect(service).toBeTruthy() | ||
})) | ||
}) |
15 changes: 15 additions & 0 deletions
15
projects/ch14/src/app/pos/transaction/transaction.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,15 @@ | ||
import { Injectable } from '@angular/core' | ||
import { BehaviorSubject, Observable } from 'rxjs' | ||
|
||
import { ITransaction } from './transaction' | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class TransactionService { | ||
constructor() {} | ||
|
||
processTransaction(transaction: ITransaction): Observable<string> { | ||
return new BehaviorSubject<string>('5a6352c6810c19729de860ea').asObservable() | ||
} | ||
} |
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,7 @@ | ||
import { TransactionType } from './transaction.enum' | ||
|
||
export interface ITransaction { | ||
paymentType: TransactionType | ||
paymentAmount: number | ||
transactionId?: string | ||
} |
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