#1508 - Anzahl der Lesepunkte stimmt nicht

This commit is contained in:
Lorenz Hilpert
2021-03-09 13:55:06 +01:00
parent e8e4bb4347
commit eb32e11a6e
19 changed files with 492 additions and 204 deletions

View File

@@ -2016,6 +2016,46 @@
} }
} }
} }
},
"@domain/catalog": {
"projectType": "library",
"root": "apps/domain/catalog",
"sourceRoot": "apps/domain/catalog/src",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:ng-packagr",
"options": {
"tsConfig": "apps/domain/catalog/tsconfig.lib.json",
"project": "apps/domain/catalog/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "apps/domain/catalog/tsconfig.lib.prod.json"
}
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "apps/domain/catalog/src/test.ts",
"tsConfig": "apps/domain/catalog/tsconfig.spec.json",
"karmaConfig": "apps/domain/catalog/karma.conf.js"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"apps/domain/catalog/tsconfig.lib.json",
"apps/domain/catalog/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
} }
}, },
"defaultProject": "sales" "defaultProject": "sales"

View File

@@ -0,0 +1,25 @@
# Catalog
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 10.1.2.
## Code scaffolding
Run `ng generate component component-name --project catalog` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project catalog`.
> Note: Don't forget to add `--project catalog` or else it will be added to the default project in your `angular.json` file.
## Build
Run `ng build catalog` to build the project. The build artifacts will be stored in the `dist/` directory.
## Publishing
After building your library with `ng build catalog`, go to the dist folder `cd dist/catalog` and run `npm publish`.
## Running unit tests
Run `ng test catalog` to execute the unit tests via [Karma](https://karma-runner.github.io).
## Further help
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).

View File

@@ -0,0 +1,32 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../../coverage/domain/catalog'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true,
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true,
});
};

View File

@@ -0,0 +1,7 @@
{
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../../dist/domain/catalog",
"lib": {
"entryFile": "src/public-api.ts"
}
}

View File

@@ -0,0 +1,11 @@
{
"name": "@domain/catalog",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^10.1.2",
"@angular/core": "^10.1.2"
},
"dependencies": {
"tslib": "^2.0.0"
}
}

View File

@@ -0,0 +1,16 @@
import { ModuleWithProviders, NgModule } from '@angular/core';
import { DomainCatalogService } from './catalog.service';
@NgModule({
declarations: [],
imports: [],
exports: [],
})
export class DomainCatalogModule {
static forRoot(): ModuleWithProviders<DomainCatalogModule> {
return {
ngModule: DomainCatalogModule,
providers: [DomainCatalogService],
};
}
}

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { CatalogService } from './catalog.service';
describe('CatalogService', () => {
let service: CatalogService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(CatalogService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,14 @@
import { Injectable } from '@angular/core';
import { PromotionService } from '@swagger/cat';
import { memorize } from '@utils/common';
import { shareReplay } from 'rxjs/operators';
@Injectable()
export class DomainCatalogService {
constructor(private promotionService: PromotionService) {}
@memorize()
getPromotionPoints({ items }: { items: { id: number; quantity: number; price?: number }[] }) {
return this.promotionService.PromotionLesepunkte(items).pipe(shareReplay());
}
}

View File

@@ -0,0 +1,6 @@
/*
* Public API Surface of catalog
*/
export * from './lib/catalog.service';
export * from './lib/catalog.module';

View File

@@ -0,0 +1,24 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
declare const require: {
context(
path: string,
deep?: boolean,
filter?: RegExp
): {
keys(): string[];
<T>(id: string): T;
};
};
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);

View File

@@ -0,0 +1,25 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "../../../out-tsc/lib",
"target": "es2015",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"types": [],
"lib": [
"dom",
"es2018"
]
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}

View File

@@ -0,0 +1,10 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "./tsconfig.lib.json",
"compilerOptions": {
"declarationMap": false
},
"angularCompilerOptions": {
"enableIvy": false
}
}

View File

@@ -0,0 +1,17 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "../../../out-tsc/spec",
"types": [
"jasmine"
]
},
"files": [
"src/test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}

View File

@@ -0,0 +1,17 @@
{
"extends": "../../../tslint.json",
"rules": {
"directive-selector": [
true,
"attribute",
"lib",
"camelCase"
],
"component-selector": [
true,
"element",
"lib",
"kebab-case"
]
}
}

View File

@@ -13,6 +13,7 @@ import { PurchasingOptionsModalComponent, PurchasingOptionsModalData } from '../
import { PurchasingOptions } from '../modals/purchasing-options-modal/purchasing-options-modal.store'; import { PurchasingOptions } from '../modals/purchasing-options-modal/purchasing-options-modal.store';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { StringDictionary } from '@cmf/core'; import { StringDictionary } from '@cmf/core';
import { DomainCatalogService } from '@domain/catalog';
@Component({ @Component({
selector: 'page-checkout-review', selector: 'page-checkout-review',
@@ -77,8 +78,17 @@ export class CheckoutReviewComponent {
); );
totalReadingPoints$ = this.items$.pipe( totalReadingPoints$ = this.items$.pipe(
takeUntil(this._orderCompleted), switchMap((displayOrders) =>
map((items) => items.reduce((total, item) => total + item?.promotion?.points * item?.quantity, 0)) this.domainCatalogService
.getPromotionPoints({
items: displayOrders.map((i) => ({
id: Number(i.product?.catalogProductNumber),
quantity: i.quantity,
price: i.unitPrice?.value?.value,
})),
})
.pipe(map((response) => Object.values(response.result).reduce((sum, points) => sum + points, 0)))
)
); );
customerFeatures$ = this.applicationService.activatedProcessId$.pipe( customerFeatures$ = this.applicationService.activatedProcessId$.pipe(
@@ -98,7 +108,8 @@ export class CheckoutReviewComponent {
private uiModal: UiModalService, private uiModal: UiModalService,
private sso: SsoService, private sso: SsoService,
private router: Router, private router: Router,
private cdr: ChangeDetectorRef private cdr: ChangeDetectorRef,
private domainCatalogService: DomainCatalogService
) {} ) {}
async changeItem(shoppingCartItem: ShoppingCartItemDTO) { async changeItem(shoppingCartItem: ShoppingCartItemDTO) {

View File

@@ -2,7 +2,9 @@ import { Component, ChangeDetectionStrategy } from '@angular/core';
import { DomainCheckoutService } from '@domain/checkout'; import { DomainCheckoutService } from '@domain/checkout';
import { UiModalService } from '@ui/modal'; import { UiModalService } from '@ui/modal';
import { PrintOrderComponent } from '@modal/printer'; import { PrintOrderComponent } from '@modal/printer';
import { map } from 'rxjs/operators'; import { map, switchMap } from 'rxjs/operators';
import { DomainCatalogService } from '@domain/catalog';
import { DisplayOrderItemDTO } from '@swagger/oms';
@Component({ @Component({
selector: 'page-checkout-summary', selector: 'page-checkout-summary',
@@ -23,12 +25,18 @@ export class CheckoutSummaryComponent {
); );
totalReadingPoints$ = this.displayOrders$.pipe( totalReadingPoints$ = this.displayOrders$.pipe(
map((displayOrders) => switchMap((displayOrders) =>
displayOrders.reduce( this.domainCatalogService
(total, displayOrder) => .getPromotionPoints({
total + displayOrder?.items?.reduce((subTotal, order) => subTotal + order?.promotion?.points * order?.quantity, 0), items: displayOrders
0 .reduce<DisplayOrderItemDTO[]>((items, order) => [...items, ...order.items], [])
) .map((i) => ({
id: Number(i.product?.catalogProductNumber),
quantity: i.quantity,
price: i.price?.value?.value,
})),
})
.pipe(map((response) => Object.values(response.result).reduce((sum, points) => sum + points, 0)))
) )
); );
@@ -51,7 +59,11 @@ export class CheckoutSummaryComponent {
) )
); );
constructor(private domainCheckoutService: DomainCheckoutService, private uiModal: UiModalService) {} constructor(
private domainCheckoutService: DomainCheckoutService,
private uiModal: UiModalService,
private domainCatalogService: DomainCatalogService
) {}
openPrintModal(id: number) { openPrintModal(id: number) {
this.uiModal.open({ this.uiModal.open({

View File

@@ -66,6 +66,7 @@ import { CDN_PRODUCT_PICTURES } from './tokens';
import { DateAdapter, NativeDateAdapter } from '@ui/common'; import { DateAdapter, NativeDateAdapter } from '@ui/common';
import { ApplicationRefactImp } from './refact-imp/application.refact-imp'; import { ApplicationRefactImp } from './refact-imp/application.refact-imp';
import { CDN_PRODUCT_IMAGE } from 'apps/cdn/product-image/src/lib/tokens'; import { CDN_PRODUCT_IMAGE } from 'apps/cdn/product-image/src/lib/tokens';
import { DomainCatalogModule } from '@domain/catalog';
registerLocaleData(localeDe, localeDeExtra); registerLocaleData(localeDe, localeDeExtra);
registerLocaleData(localeDe, 'de', localeDeExtra); registerLocaleData(localeDe, 'de', localeDeExtra);
@@ -140,6 +141,7 @@ export function cdnProdutctPictures(config: AppConfiguration): string {
* @core Domain * @core Domain
*/ */
DomainCheckoutModule, DomainCheckoutModule,
DomainCatalogModule.forRoot(),
/** /**
* @ui Modules * @ui Modules

386
package-lock.json generated
View File

File diff suppressed because it is too large Load Diff

View File

@@ -188,6 +188,9 @@
], ],
"@modal/history": [ "@modal/history": [
"apps/modal/history/src/public-api.ts" "apps/modal/history/src/public-api.ts"
],
"@domain/catalog": [
"apps/domain/catalog/src/public-api.ts"
] ]
} }
} }