mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
Compare commits
95 Commits
feature/51
...
hotfix/dea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
353864e2f0 | ||
|
|
1b6b726036 | ||
|
|
4c56f394c5 | ||
|
|
a086111ab5 | ||
|
|
15a4718e58 | ||
|
|
40592b4477 | ||
|
|
d430f544f0 | ||
|
|
62e586cfda | ||
|
|
304f8a64e5 | ||
|
|
c672ae4012 | ||
|
|
fd693a4beb | ||
|
|
2c70339f23 | ||
|
|
59f0cc7d43 | ||
|
|
0ca58fe1bf | ||
|
|
8cf80a60a0 | ||
|
|
cffa7721bc | ||
|
|
066ab5d5be | ||
|
|
3bbf79a3c3 | ||
|
|
357485e32f | ||
|
|
39984342a6 | ||
|
|
c52f18e979 | ||
|
|
e58ec93087 | ||
|
|
4e6204817d | ||
|
|
c41355bcdf | ||
|
|
fa8e601660 | ||
|
|
708ec01704 | ||
|
|
332699ca74 | ||
|
|
3b0a63a53a | ||
|
|
327fdc745d | ||
|
|
297ec9100d | ||
|
|
298ab1acbe | ||
|
|
fe77a0ea8b | ||
|
|
48f588f53b | ||
|
|
7f4af304ac | ||
|
|
643b2b0e60 | ||
|
|
cd1ff5f277 | ||
|
|
46c70cae3e | ||
|
|
2cb1f9ec99 | ||
|
|
d2dcf638e3 | ||
|
|
a4241cbd7a | ||
|
|
dd3705f8bc | ||
|
|
514715589b | ||
|
|
0740273dbc | ||
|
|
bbb9c5d39c | ||
|
|
f0bd957a07 | ||
|
|
e4f289c67d | ||
|
|
2af16d92ea | ||
|
|
99e8e7cfe0 | ||
|
|
ac728f2dd9 | ||
|
|
2e012a124a | ||
|
|
d22e320294 | ||
|
|
a0f24aac17 | ||
|
|
7ae484fc83 | ||
|
|
0dcb31973f | ||
|
|
c2f393d249 | ||
|
|
2dbf7dda37 | ||
|
|
cce15a2137 | ||
|
|
14a5a67a1e | ||
|
|
d7d535c10d | ||
|
|
ad00899b6e | ||
|
|
0addf392b6 | ||
|
|
1e84223076 | ||
|
|
244984b6cf | ||
|
|
b39abe630d | ||
|
|
239ab52890 | ||
|
|
4732656a0f | ||
|
|
0da9800ca0 | ||
|
|
baf4a0dfbc | ||
|
|
da5a42280a | ||
|
|
4d29189c8d | ||
|
|
32bd3e26d2 | ||
|
|
6d26f7f6c0 | ||
|
|
72bcacefb6 | ||
|
|
71e9a6da0e | ||
|
|
b339a6d79f | ||
|
|
0b4aef5f6c | ||
|
|
c5182809ac | ||
|
|
f4b541c7c0 | ||
|
|
afe6c6abcc | ||
|
|
3f233f9580 | ||
|
|
6f9d4d9218 | ||
|
|
4111663d8c | ||
|
|
2beeba5c92 | ||
|
|
edab1322c8 | ||
|
|
59ce736faa | ||
|
|
3cd6f4bd58 | ||
|
|
594acaa5f5 | ||
|
|
76ff54dd3a | ||
|
|
598df7d5ed | ||
|
|
442670bdd0 | ||
|
|
b015e97e1f | ||
|
|
65ab3bfc0a | ||
|
|
e674378080 | ||
|
|
40c9d51dfc | ||
|
|
5f74c6ddf8 |
2
.github/copilot-instructions.md
vendored
2
.github/copilot-instructions.md
vendored
@@ -4,6 +4,8 @@
|
||||
|
||||
You are Mentor, an AI assistant focused on ensuring code quality, strict adherence to best practices, and development efficiency. **Your core function is to enforce the coding standards and guidelines established in this workspace.** Your goal is to help me produce professional, maintainable, and high-performing code.
|
||||
|
||||
**Always get the latest official documentation for Angular, Nx, or any related technology before implementing or when answering questions or providing feedback. Use Context7:**
|
||||
|
||||
## Tone and Personality
|
||||
|
||||
Maintain a professional, objective, and direct tone consistently:
|
||||
|
||||
47
.github/instructions/nx.instructions.md
vendored
47
.github/instructions/nx.instructions.md
vendored
@@ -1,47 +0,0 @@
|
||||
---
|
||||
applyTo: '**'
|
||||
---
|
||||
|
||||
// This file is automatically generated by Nx Console
|
||||
|
||||
You are in an nx workspace using Nx 21.2.1 and npm as the package manager.
|
||||
|
||||
You have access to the Nx MCP server and the tools it provides. Use them. Follow these guidelines in order to best help the user:
|
||||
|
||||
# General Guidelines
|
||||
- When answering questions, use the nx_workspace tool first to gain an understanding of the workspace architecture
|
||||
- For questions around nx configuration, best practices or if you're unsure, use the nx_docs tool to get relevant, up-to-date docs!! Always use this instead of assuming things about nx configuration
|
||||
- If the user needs help with an Nx configuration or project graph error, use the 'nx_workspace' tool to get any errors
|
||||
- To help answer questions about the workspace structure or simply help with demonstrating how tasks depend on each other, use the 'nx_visualize_graph' tool
|
||||
|
||||
# Generation Guidelines
|
||||
If the user wants to generate something, use the following flow:
|
||||
|
||||
- learn about the nx workspace and any specifics the user needs by using the 'nx_workspace' tool and the 'nx_project_details' tool if applicable
|
||||
- get the available generators using the 'nx_generators' tool
|
||||
- decide which generator to use. If no generators seem relevant, check the 'nx_available_plugins' tool to see if the user could install a plugin to help them
|
||||
- get generator details using the 'nx_generator_schema' tool
|
||||
- you may use the 'nx_docs' tool to learn more about a specific generator or technology if you're unsure
|
||||
- decide which options to provide in order to best complete the user's request. Don't make any assumptions and keep the options minimalistic
|
||||
- open the generator UI using the 'nx_open_generate_ui' tool
|
||||
- wait for the user to finish the generator
|
||||
- read the generator log file using the 'nx_read_generator_log' tool
|
||||
- use the information provided in the log file to answer the user's question or continue with what they were doing
|
||||
|
||||
# Running Tasks Guidelines
|
||||
If the user wants help with tasks or commands (which include keywords like "test", "build", "lint", or other similar actions), use the following flow:
|
||||
- Use the 'nx_current_running_tasks_details' tool to get the list of tasks (this can include tasks that were completed, stopped or failed).
|
||||
- If there are any tasks, ask the user if they would like help with a specific task then use the 'nx_current_running_task_output' tool to get the terminal output for that task/command
|
||||
- Use the terminal output from 'nx_current_running_task_output' to see what's wrong and help the user fix their problem. Use the appropriate tools if necessary
|
||||
- If the user would like to rerun the task or command, always use `nx run <taskId>` to rerun in the terminal. This will ensure that the task will run in the nx context and will be run the same way it originally executed
|
||||
- If the task was marked as "continuous" do not offer to rerun the task. This task is already running and the user can see the output in the terminal. You can use 'nx_current_running_task_output' to get the output of the task to verify the output.
|
||||
|
||||
|
||||
# CI Error Guidelines
|
||||
If the user wants help with fixing an error in their CI pipeline, use the following flow:
|
||||
- Retrieve the list of current CI Pipeline Executions (CIPEs) using the 'nx_cloud_cipe_details' tool
|
||||
- If there are any errors, use the 'nx_cloud_fix_cipe_failure' tool to retrieve the logs for a specific task
|
||||
- Use the task logs to see what's wrong and help the user fix their problem. Use the appropriate tools if necessary
|
||||
- Make sure that the problem is fixed by running the task that you passed into the 'nx_cloud_fix_cipe_failure' tool
|
||||
|
||||
|
||||
39
.github/testing-instructions.md
vendored
39
.github/testing-instructions.md
vendored
@@ -2,8 +2,10 @@
|
||||
|
||||
## Framework and Tools
|
||||
|
||||
- Use **Jest** as the testing framework.
|
||||
- For unit tests, utilize **Spectator** to simplify Angular component testing.
|
||||
- **Vitest** is the recommended testing framework.
|
||||
[Vitest Documentation (latest)](https://context7.com/vitest-dev/vitest/llms.txt?topic=getting+started)
|
||||
- **Jest** and **Spectator** are **deprecated**.
|
||||
Do not use them for new tests. Existing tests should be migrated to Vitest where possible.
|
||||
|
||||
## Guidelines
|
||||
|
||||
@@ -23,28 +25,31 @@
|
||||
## Example Test Structure
|
||||
|
||||
```typescript
|
||||
// Example using Jest and Spectator
|
||||
import { createComponentFactory, Spectator } from '@ngneat/spectator';
|
||||
// Example using Vitest (Jest and Spectator are deprecated)
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { render } from '@testing-library/angular';
|
||||
import { MyComponent } from './my-component.component';
|
||||
|
||||
describe('MyComponent', () => {
|
||||
let spectator: Spectator<MyComponent>;
|
||||
const createComponent = createComponentFactory(MyComponent);
|
||||
let component: MyComponent;
|
||||
|
||||
beforeEach(() => {
|
||||
spectator = createComponent();
|
||||
beforeEach(async () => {
|
||||
const { fixture } = await render(MyComponent);
|
||||
component = fixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should display the correct title', () => {
|
||||
it('should display the correct title', async () => {
|
||||
// Arrange
|
||||
const expectedTitle = 'Hello World';
|
||||
|
||||
// Act
|
||||
spectator.component.title = expectedTitle;
|
||||
spectator.detectChanges();
|
||||
component.title = expectedTitle;
|
||||
// If using Angular, trigger change detection:
|
||||
// fixture.detectChanges();
|
||||
|
||||
// Assert
|
||||
expect(spectator.query('h1')).toHaveText(expectedTitle);
|
||||
const compiled = fixture.nativeElement as HTMLElement;
|
||||
expect(compiled.querySelector('h1')?.textContent).toBe(expectedTitle);
|
||||
});
|
||||
|
||||
it('should handle error cases gracefully', () => {
|
||||
@@ -52,15 +57,17 @@ describe('MyComponent', () => {
|
||||
const invalidInput = null;
|
||||
|
||||
// Act
|
||||
spectator.component.input = invalidInput;
|
||||
component.input = invalidInput;
|
||||
|
||||
// Assert
|
||||
expect(() => spectator.component.processInput()).toThrowError('Invalid input');
|
||||
expect(() => component.processInput()).toThrowError('Invalid input');
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
## Additional Resources
|
||||
|
||||
- [Jest Documentation](https://jestjs.io/docs/getting-started)
|
||||
- [Spectator Documentation](https://ngneat.github.io/spectator/)
|
||||
- [Vitest Documentation (latest)](https://context7.com/vitest-dev/vitest/llms.txt?topic=getting+started)
|
||||
- [Vitest Official Guide](https://vitest.dev/guide/)
|
||||
- [Testing Library for Angular](https://testing-library.com/docs/angular-testing-library/intro/)
|
||||
- **Jest** and **Spectator** documentation are deprecated
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -73,3 +73,5 @@ vitest.config.*.timestamp*
|
||||
|
||||
.mcp.json
|
||||
.memory.json
|
||||
|
||||
nx.instructions.md
|
||||
|
||||
@@ -8,7 +8,7 @@ WORKDIR /app
|
||||
COPY . .
|
||||
RUN umask 0022
|
||||
RUN npm version ${SEMVERSION}
|
||||
RUN npm install --foreground-scripts --legacy-peer-deps
|
||||
RUN npm install --foreground-scripts
|
||||
RUN if [ "${IS_PRODUCTION}" = "true" ] ; then npm run-script build-prod ; else npm run-script build ; fi
|
||||
|
||||
# stage final
|
||||
|
||||
@@ -1,162 +1,162 @@
|
||||
{
|
||||
"name": "isa-app",
|
||||
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
||||
"projectType": "application",
|
||||
"prefix": "app",
|
||||
"sourceRoot": "apps/isa-app/src",
|
||||
"tags": [],
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@angular-devkit/build-angular:application",
|
||||
"options": {
|
||||
"allowedCommonJsDependencies": [
|
||||
"lodash",
|
||||
"moment",
|
||||
"jsrsasign",
|
||||
"pdfjs-dist/build/pdf",
|
||||
"pdfjs-dist/web/pdf_viewer",
|
||||
"pdfjs-dist/es5/build/pdf",
|
||||
"pdfjs-dist/es5/web/pdf_viewer"
|
||||
],
|
||||
"outputPath": "dist/isa-app",
|
||||
"index": "apps/isa-app/src/index.html",
|
||||
"browser": "apps/isa-app/src/main.ts",
|
||||
"polyfills": ["zone.js"],
|
||||
"tsConfig": "apps/isa-app/tsconfig.app.json",
|
||||
"inlineStyleLanguage": "scss",
|
||||
"assets": [
|
||||
"apps/isa-app/src/favicon.ico",
|
||||
"apps/isa-app/src/assets",
|
||||
"apps/isa-app/src/config",
|
||||
"apps/isa-app/src/silent-refresh.html",
|
||||
"apps/isa-app/src/manifest.webmanifest",
|
||||
{
|
||||
"glob": "**/*",
|
||||
"input": "node_modules/scandit-web-datacapture-barcode/build/engine",
|
||||
"output": "scandit"
|
||||
}
|
||||
],
|
||||
"styles": [
|
||||
"@angular/cdk/overlay-prebuilt.css",
|
||||
"apps/isa-app/src/tailwind.scss",
|
||||
"apps/isa-app/src/styles.scss"
|
||||
],
|
||||
"scripts": []
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "2mb",
|
||||
"maximumError": "5mb"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "25kb"
|
||||
}
|
||||
],
|
||||
"fileReplacements": [
|
||||
{
|
||||
"replace": "apps/isa-app/src/environments/environment.ts",
|
||||
"with": "apps/isa-app/src/environments/environment.prod.ts"
|
||||
}
|
||||
],
|
||||
"outputHashing": "all",
|
||||
"serviceWorker": "apps/isa-app/ngsw-config.json"
|
||||
},
|
||||
"development": {
|
||||
"optimization": false,
|
||||
"extractLicenses": false,
|
||||
"sourceMap": true
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "production",
|
||||
"outputs": ["{options.outputPath}"]
|
||||
},
|
||||
"serve": {
|
||||
"executor": "@angular-devkit/build-angular:dev-server",
|
||||
"configurations": {
|
||||
"production": {
|
||||
"buildTarget": "isa-app:build:production"
|
||||
},
|
||||
"development": {
|
||||
"buildTarget": "isa-app:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development",
|
||||
"continuous": true
|
||||
},
|
||||
"extract-i18n": {
|
||||
"executor": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"buildTarget": "isa-app:build"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nx/eslint:lint"
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nx/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"options": {
|
||||
"jestConfig": "apps/isa-app/jest.config.ts"
|
||||
}
|
||||
},
|
||||
"serve-static": {
|
||||
"executor": "@nx/web:file-server",
|
||||
"options": {
|
||||
"buildTarget": "isa-app:build",
|
||||
"staticFilePath": "dist/apps/isa-app/browser",
|
||||
"spa": true
|
||||
}
|
||||
},
|
||||
"storybook": {
|
||||
"executor": "@storybook/angular:start-storybook",
|
||||
"options": {
|
||||
"port": 4400,
|
||||
"configDir": "apps/isa-app/.storybook",
|
||||
"browserTarget": "isa-app:build",
|
||||
"compodoc": false,
|
||||
"open": false,
|
||||
"assets": [
|
||||
{
|
||||
"glob": "**/*",
|
||||
"input": "apps/isa-app/src/assets",
|
||||
"output": "/assets"
|
||||
}
|
||||
],
|
||||
"styles": [
|
||||
"@angular/cdk/overlay-prebuilt.css",
|
||||
"apps/isa-app/src/tailwind.scss",
|
||||
"apps/isa-app/src/styles.scss"
|
||||
]
|
||||
},
|
||||
"configurations": {
|
||||
"ci": {
|
||||
"quiet": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"build-storybook": {
|
||||
"executor": "@storybook/angular:build-storybook",
|
||||
"outputs": ["{options.outputDir}"],
|
||||
"options": {
|
||||
"outputDir": "dist/storybook/isa-app",
|
||||
"configDir": "apps/isa-app/.storybook",
|
||||
"browserTarget": "isa-app:build",
|
||||
"compodoc": false,
|
||||
"styles": [
|
||||
"@angular/cdk/overlay-prebuilt.css",
|
||||
"apps/isa-app/src/tailwind.scss",
|
||||
"apps/isa-app/src/styles.scss"
|
||||
]
|
||||
},
|
||||
"configurations": {
|
||||
"ci": {
|
||||
"quiet": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
"name": "isa-app",
|
||||
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
||||
"projectType": "application",
|
||||
"prefix": "app",
|
||||
"sourceRoot": "apps/isa-app/src",
|
||||
"tags": [],
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@angular-devkit/build-angular:application",
|
||||
"options": {
|
||||
"allowedCommonJsDependencies": [
|
||||
"lodash",
|
||||
"moment",
|
||||
"jsrsasign",
|
||||
"pdfjs-dist/build/pdf",
|
||||
"pdfjs-dist/web/pdf_viewer",
|
||||
"pdfjs-dist/es5/build/pdf",
|
||||
"pdfjs-dist/es5/web/pdf_viewer"
|
||||
],
|
||||
"outputPath": "dist/isa-app",
|
||||
"index": "apps/isa-app/src/index.html",
|
||||
"browser": "apps/isa-app/src/main.ts",
|
||||
"polyfills": ["zone.js"],
|
||||
"tsConfig": "apps/isa-app/tsconfig.app.json",
|
||||
"inlineStyleLanguage": "scss",
|
||||
"assets": [
|
||||
"apps/isa-app/src/favicon.ico",
|
||||
"apps/isa-app/src/assets",
|
||||
"apps/isa-app/src/config",
|
||||
"apps/isa-app/src/silent-refresh.html",
|
||||
"apps/isa-app/src/manifest.webmanifest",
|
||||
{
|
||||
"glob": "**/*",
|
||||
"input": "node_modules/scandit-web-datacapture-barcode/build/engine",
|
||||
"output": "scandit"
|
||||
}
|
||||
],
|
||||
"styles": [
|
||||
"@angular/cdk/overlay-prebuilt.css",
|
||||
"apps/isa-app/src/tailwind.scss",
|
||||
"apps/isa-app/src/styles.scss"
|
||||
],
|
||||
"scripts": []
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "2mb",
|
||||
"maximumError": "5mb"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "25kb"
|
||||
}
|
||||
],
|
||||
"fileReplacements": [
|
||||
{
|
||||
"replace": "apps/isa-app/src/environments/environment.ts",
|
||||
"with": "apps/isa-app/src/environments/environment.prod.ts"
|
||||
}
|
||||
],
|
||||
"outputHashing": "all",
|
||||
"serviceWorker": "apps/isa-app/ngsw-config.json"
|
||||
},
|
||||
"development": {
|
||||
"optimization": false,
|
||||
"extractLicenses": false,
|
||||
"sourceMap": true
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "production",
|
||||
"outputs": ["{options.outputPath}"]
|
||||
},
|
||||
"serve": {
|
||||
"executor": "@angular-devkit/build-angular:dev-server",
|
||||
"configurations": {
|
||||
"production": {
|
||||
"buildTarget": "isa-app:build:production"
|
||||
},
|
||||
"development": {
|
||||
"buildTarget": "isa-app:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development",
|
||||
"continuous": true
|
||||
},
|
||||
"extract-i18n": {
|
||||
"executor": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"buildTarget": "isa-app:build"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nx/eslint:lint"
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nx/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"options": {
|
||||
"jestConfig": "apps/isa-app/jest.config.ts"
|
||||
}
|
||||
},
|
||||
"serve-static": {
|
||||
"executor": "@nx/web:file-server",
|
||||
"options": {
|
||||
"buildTarget": "isa-app:build",
|
||||
"staticFilePath": "dist/apps/isa-app/browser",
|
||||
"spa": true
|
||||
}
|
||||
},
|
||||
"storybook": {
|
||||
"executor": "@storybook/angular:start-storybook",
|
||||
"options": {
|
||||
"port": 4400,
|
||||
"configDir": "apps/isa-app/.storybook",
|
||||
"browserTarget": "isa-app:build",
|
||||
"compodoc": false,
|
||||
"open": false,
|
||||
"assets": [
|
||||
{
|
||||
"glob": "**/*",
|
||||
"input": "apps/isa-app/src/assets",
|
||||
"output": "/assets"
|
||||
}
|
||||
],
|
||||
"styles": [
|
||||
"@angular/cdk/overlay-prebuilt.css",
|
||||
"apps/isa-app/src/tailwind.scss",
|
||||
"apps/isa-app/src/styles.scss"
|
||||
]
|
||||
},
|
||||
"configurations": {
|
||||
"ci": {
|
||||
"quiet": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"build-storybook": {
|
||||
"executor": "@storybook/angular:build-storybook",
|
||||
"outputs": ["{options.outputDir}"],
|
||||
"options": {
|
||||
"outputDir": "dist/storybook/isa-app",
|
||||
"configDir": "apps/isa-app/.storybook",
|
||||
"browserTarget": "isa-app:build",
|
||||
"compodoc": false,
|
||||
"styles": [
|
||||
"@angular/cdk/overlay-prebuilt.css",
|
||||
"apps/isa-app/src/tailwind.scss",
|
||||
"apps/isa-app/src/styles.scss"
|
||||
]
|
||||
},
|
||||
"configurations": {
|
||||
"ci": {
|
||||
"quiet": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,12 +153,12 @@ const routes: Routes = [
|
||||
import('@page/goods-in').then((m) => m.GoodsInModule),
|
||||
canActivate: [CanActivateGoodsInGuard],
|
||||
},
|
||||
{
|
||||
path: 'remission',
|
||||
loadChildren: () =>
|
||||
import('@page/remission').then((m) => m.PageRemissionModule),
|
||||
canActivate: [CanActivateRemissionGuard],
|
||||
},
|
||||
// {
|
||||
// path: 'remission',
|
||||
// loadChildren: () =>
|
||||
// import('@page/remission').then((m) => m.PageRemissionModule),
|
||||
// canActivate: [CanActivateRemissionGuard],
|
||||
// },
|
||||
{
|
||||
path: 'package-inspection',
|
||||
loadChildren: () =>
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
withInterceptorsFromDi,
|
||||
} from '@angular/common/http';
|
||||
import {
|
||||
DEFAULT_CURRENCY_CODE,
|
||||
ErrorHandler,
|
||||
Injector,
|
||||
LOCALE_ID,
|
||||
@@ -228,6 +229,10 @@ export function _notificationsHubOptionsFactory(
|
||||
withRouteData(),
|
||||
),
|
||||
provideLogging(withLogLevel(LogLevel.Debug), withSink(ConsoleLogSink)),
|
||||
{
|
||||
provide: DEFAULT_CURRENCY_CODE,
|
||||
useValue: 'EUR',
|
||||
},
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { ErrorHandler, Injectable } from '@angular/core';
|
||||
import { AuthService } from '@core/auth';
|
||||
import { DialogModel, UiDialogModalComponent, UiErrorModalComponent, UiModalService } from '@ui/modal';
|
||||
import { IsaLogProvider } from './isa.log-provider';
|
||||
import { LogLevel } from '@core/logger';
|
||||
import { HttpErrorResponse } from "@angular/common/http";
|
||||
import { ErrorHandler, Injectable } from "@angular/core";
|
||||
import { AuthService } from "@core/auth";
|
||||
import {
|
||||
DialogModel,
|
||||
UiDialogModalComponent,
|
||||
UiErrorModalComponent,
|
||||
UiModalService,
|
||||
} from "@ui/modal";
|
||||
import { IsaLogProvider } from "./isa.log-provider";
|
||||
import { LogLevel } from "@core/logger";
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
@Injectable({ providedIn: "root" })
|
||||
export class IsaErrorHandler implements ErrorHandler {
|
||||
constructor(
|
||||
private _modal: UiModalService,
|
||||
@@ -17,7 +22,7 @@ export class IsaErrorHandler implements ErrorHandler {
|
||||
console.error(error);
|
||||
|
||||
// Bei Klick auf Abbrechen auf der Login Seite erneut zur Login Seite weiterleiten
|
||||
if (error?.type === 'token_error') {
|
||||
if (error?.type === "token_error") {
|
||||
this._authService.login();
|
||||
return;
|
||||
}
|
||||
@@ -26,11 +31,14 @@ export class IsaErrorHandler implements ErrorHandler {
|
||||
await this._modal
|
||||
.open({
|
||||
content: UiDialogModalComponent,
|
||||
title: 'Sitzung abgelaufen',
|
||||
title: "Sitzung abgelaufen",
|
||||
data: {
|
||||
handleCommand: false,
|
||||
content: 'Sie waren zu lange nicht in der ISA aktiv. Bitte melden Sie sich erneut an',
|
||||
actions: [{ command: 'CLOSE', selected: true, label: 'Erneut anmelden' }],
|
||||
content:
|
||||
"Sie waren zu lange nicht in der ISA aktiv. Bitte melden Sie sich erneut an",
|
||||
actions: [
|
||||
{ command: "CLOSE", selected: true, label: "Erneut anmelden" },
|
||||
],
|
||||
} as DialogModel,
|
||||
})
|
||||
.afterClosed$.toPromise();
|
||||
@@ -39,7 +47,11 @@ export class IsaErrorHandler implements ErrorHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
this._isaLogProvider.log(LogLevel.ERROR, 'Client Error', error);
|
||||
try {
|
||||
this._isaLogProvider.log(LogLevel.ERROR, "Client Error", error);
|
||||
} catch (logError) {
|
||||
console.error("Error logging to IsaLogProvider:", logError);
|
||||
}
|
||||
|
||||
// this._modal.open({
|
||||
// content: UiErrorModalComponent,
|
||||
|
||||
@@ -1,28 +1,36 @@
|
||||
import { Injectable, Injector } from '@angular/core';
|
||||
import { LogLevel, LogProvider } from '@core/logger';
|
||||
import { UserStateService } from '@generated/swagger/isa-api';
|
||||
import { environment } from '../../environments/environment';
|
||||
import { Injectable } from "@angular/core";
|
||||
import { LogLevel, LogProvider } from "@core/logger";
|
||||
import { UserStateService } from "@generated/swagger/isa-api";
|
||||
import { environment } from "../../environments/environment";
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
@Injectable({ providedIn: "root" })
|
||||
export class IsaLogProvider implements LogProvider {
|
||||
static InfoService: UserStateService | undefined;
|
||||
|
||||
constructor() {}
|
||||
|
||||
log(logLevel: LogLevel, message: string, error: Error, ...optionalParams: any[]): void {
|
||||
if (!environment.production && (logLevel === LogLevel.WARN || logLevel === LogLevel.ERROR)) {
|
||||
IsaLogProvider.InfoService?.UserStateSaveLog({
|
||||
logType: logLevel,
|
||||
message: message,
|
||||
content: JSON.stringify({
|
||||
error: error?.name,
|
||||
message: error?.message,
|
||||
stack: error?.stack,
|
||||
data: optionalParams,
|
||||
}),
|
||||
})
|
||||
.toPromise()
|
||||
.catch(() => {});
|
||||
log(
|
||||
logLevel: LogLevel,
|
||||
message: string,
|
||||
error: Error,
|
||||
...optionalParams: any[]
|
||||
): void {
|
||||
try {
|
||||
if (
|
||||
!environment.production &&
|
||||
(logLevel === LogLevel.WARN || logLevel === LogLevel.ERROR)
|
||||
) {
|
||||
IsaLogProvider.InfoService?.UserStateSaveLog({
|
||||
logType: logLevel,
|
||||
message: message,
|
||||
content: JSON.stringify({
|
||||
error: error?.name,
|
||||
message: error?.message,
|
||||
stack: error?.stack,
|
||||
data: optionalParams,
|
||||
}),
|
||||
}).toPromise();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error logging to InfoService:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Logger, LogLevel } from '@core/logger';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { debounceTime, switchMap, takeUntil } from 'rxjs/operators';
|
||||
import { RootState } from './root.state';
|
||||
import packageInfo from 'packageJson';
|
||||
import { environment } from '../../environments/environment';
|
||||
import { Subject } from 'rxjs';
|
||||
import { AuthService } from '@core/auth';
|
||||
import { injectStorage, UserStorageProvider } from '@isa/core/storage';
|
||||
import { isEqual } from 'lodash';
|
||||
import { Injectable } from "@angular/core";
|
||||
import { Logger, LogLevel } from "@core/logger";
|
||||
import { Store } from "@ngrx/store";
|
||||
import { debounceTime, switchMap, takeUntil } from "rxjs/operators";
|
||||
import { RootState } from "./root.state";
|
||||
import packageInfo from "packageJson";
|
||||
import { environment } from "../../environments/environment";
|
||||
import { Subject } from "rxjs";
|
||||
import { AuthService } from "@core/auth";
|
||||
import { injectStorage, UserStorageProvider } from "@isa/core/storage";
|
||||
import { isEqual } from "lodash";
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
@Injectable({ providedIn: "root" })
|
||||
export class RootStateService {
|
||||
static LOCAL_STORAGE_KEY = 'ISA_APP_INITIALSTATE';
|
||||
static LOCAL_STORAGE_KEY = "ISA_APP_INITIALSTATE";
|
||||
|
||||
#storage = injectStorage(UserStorageProvider);
|
||||
|
||||
@@ -29,14 +29,17 @@ export class RootStateService {
|
||||
);
|
||||
}
|
||||
|
||||
window['clearUserState'] = () => {
|
||||
window["clearUserState"] = () => {
|
||||
this.clear();
|
||||
};
|
||||
}
|
||||
|
||||
async init() {
|
||||
await this.load();
|
||||
this._store.dispatch({ type: 'HYDRATE', payload: RootStateService.LoadFromLocalStorage() });
|
||||
this._store.dispatch({
|
||||
type: "HYDRATE",
|
||||
payload: RootStateService.LoadFromLocalStorage(),
|
||||
});
|
||||
this.initSave();
|
||||
}
|
||||
|
||||
@@ -50,14 +53,10 @@ export class RootStateService {
|
||||
const data = {
|
||||
...state,
|
||||
version: packageInfo.version,
|
||||
sub: this._authService.getClaimByKey('sub'),
|
||||
sub: this._authService.getClaimByKey("sub"),
|
||||
};
|
||||
RootStateService.SaveToLocalStorageRaw(JSON.stringify(data));
|
||||
return this.#storage.set('state', {
|
||||
...state,
|
||||
version: packageInfo.version,
|
||||
sub: this._authService.getClaimByKey('sub'),
|
||||
});
|
||||
return this.#storage.set("state", data);
|
||||
}),
|
||||
)
|
||||
.subscribe();
|
||||
@@ -68,7 +67,7 @@ export class RootStateService {
|
||||
*/
|
||||
async load(): Promise<boolean> {
|
||||
try {
|
||||
const res = await this.#storage.get('state');
|
||||
const res = await this.#storage.get("state");
|
||||
|
||||
const storageContent = RootStateService.LoadFromLocalStorageRaw();
|
||||
|
||||
@@ -88,7 +87,7 @@ export class RootStateService {
|
||||
async clear() {
|
||||
try {
|
||||
this._cancelSave.next();
|
||||
await this.#storage.clear('state');
|
||||
await this.#storage.clear("state");
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
RootStateService.RemoveFromLocalStorage();
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
@@ -112,7 +111,7 @@ export class RootStateService {
|
||||
try {
|
||||
return JSON.parse(raw);
|
||||
} catch (error) {
|
||||
console.error('Error parsing local storage:', error);
|
||||
console.error("Error parsing local storage:", error);
|
||||
this.RemoveFromLocalStorage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { LogLevel } from './log-level';
|
||||
import { LogLevel } from "./log-level";
|
||||
|
||||
export interface LogProvider {
|
||||
log(logLevel: LogLevel, message: string, ...optionalParams: any[]): void;
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
<div class="notification-list scroll-bar">
|
||||
@for (notification of notifications; track notification) {
|
||||
<modal-notifications-list-item [item]="notification" (itemSelected)="itemSelected($event)"></modal-notifications-list-item>
|
||||
<modal-notifications-list-item
|
||||
[item]="notification"
|
||||
(itemSelected)="itemSelected($event)"
|
||||
></modal-notifications-list-item>
|
||||
<hr />
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<a class="cta-primary" [routerLink]="['/filiale/remission/create']" (click)="navigated.emit()">Zur Remission</a>
|
||||
<a
|
||||
class="cta-primary"
|
||||
[routerLink]="remissionPath()"
|
||||
(click)="navigated.emit()"
|
||||
>Zur Remission</a
|
||||
>
|
||||
</div>
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, inject } from '@angular/core';
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
EventEmitter,
|
||||
Input,
|
||||
Output,
|
||||
inject,
|
||||
linkedSignal,
|
||||
} from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { PickupShelfInNavigationService } from '@shared/services/navigation';
|
||||
import { UiFilter } from '@ui/filter';
|
||||
import { MessageBoardItemDTO } from '@hub/notifications';
|
||||
import { TabService } from '@isa/core/tabs';
|
||||
|
||||
@Component({
|
||||
selector: 'modal-notifications-remission-group',
|
||||
@@ -11,7 +20,10 @@ import { MessageBoardItemDTO } from '@hub/notifications';
|
||||
standalone: false,
|
||||
})
|
||||
export class ModalNotificationsRemissionGroupComponent {
|
||||
private _pickupShelfInNavigationService = inject(PickupShelfInNavigationService);
|
||||
tabService = inject(TabService);
|
||||
private _pickupShelfInNavigationService = inject(
|
||||
PickupShelfInNavigationService,
|
||||
);
|
||||
|
||||
@Input()
|
||||
notifications: MessageBoardItemDTO[];
|
||||
@@ -19,11 +31,19 @@ export class ModalNotificationsRemissionGroupComponent {
|
||||
@Output()
|
||||
navigated = new EventEmitter<void>();
|
||||
|
||||
remissionPath = linkedSignal(() => [
|
||||
'/',
|
||||
this.tabService.activatedTab()?.id || this.tabService.nextId(),
|
||||
'remission',
|
||||
]);
|
||||
|
||||
constructor(private _router: Router) {}
|
||||
|
||||
itemSelected(item: MessageBoardItemDTO) {
|
||||
const defaultNav = this._pickupShelfInNavigationService.listRoute();
|
||||
const queryParams = UiFilter.getQueryParamsFromQueryTokenDTO(item.queryToken);
|
||||
const queryParams = UiFilter.getQueryParamsFromQueryTokenDTO(
|
||||
item.queryToken,
|
||||
);
|
||||
this._router.navigate(defaultNav.path, {
|
||||
queryParams: {
|
||||
...defaultNav.queryParams,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<ng-container *ifRole="'Store'">
|
||||
<!-- <ng-container *ifRole="'Store'">
|
||||
@if (customerType !== 'b2b') {
|
||||
<shared-checkbox
|
||||
[ngModel]="p4mUser"
|
||||
@@ -8,15 +8,17 @@
|
||||
Kundenkarte
|
||||
</shared-checkbox>
|
||||
}
|
||||
</ng-container>
|
||||
</ng-container> -->
|
||||
@for (option of filteredOptions$ | async; track option) {
|
||||
@if (option?.enabled !== false) {
|
||||
<shared-checkbox
|
||||
[ngModel]="option.value === customerType"
|
||||
(ngModelChange)="setValue({ customerType: $event ? option.value : undefined })"
|
||||
(ngModelChange)="
|
||||
setValue({ customerType: $event ? option.value : undefined })
|
||||
"
|
||||
[disabled]="isOptionDisabled(option)"
|
||||
[name]="option.value"
|
||||
>
|
||||
>
|
||||
{{ option.label }}
|
||||
</shared-checkbox>
|
||||
}
|
||||
|
||||
@@ -21,7 +21,13 @@ import { OptionDTO } from '@generated/swagger/checkout-api';
|
||||
import { UiCheckboxComponent } from '@ui/checkbox';
|
||||
import { first, isBoolean, isString } from 'lodash';
|
||||
import { combineLatest, Observable, Subject } from 'rxjs';
|
||||
import { distinctUntilChanged, filter, map, shareReplay, switchMap } from 'rxjs/operators';
|
||||
import {
|
||||
distinctUntilChanged,
|
||||
filter,
|
||||
map,
|
||||
shareReplay,
|
||||
switchMap,
|
||||
} from 'rxjs/operators';
|
||||
|
||||
export interface CustomerTypeSelectorState {
|
||||
processId: number;
|
||||
@@ -58,18 +64,18 @@ export class CustomerTypeSelectorComponent
|
||||
|
||||
@Input()
|
||||
get value() {
|
||||
if (this.p4mUser) {
|
||||
return `${this.customerType}-p4m`;
|
||||
}
|
||||
// if (this.p4mUser) {
|
||||
// return `${this.customerType}-p4m`;
|
||||
// }
|
||||
return this.customerType;
|
||||
}
|
||||
set value(value: string) {
|
||||
if (value.includes('-p4m')) {
|
||||
this.p4mUser = true;
|
||||
this.customerType = value.replace('-p4m', '');
|
||||
} else {
|
||||
this.customerType = value;
|
||||
}
|
||||
// if (value.includes('-p4m')) {
|
||||
// this.p4mUser = true;
|
||||
// this.customerType = value.replace('-p4m', '');
|
||||
// } else {
|
||||
this.customerType = value;
|
||||
// }
|
||||
}
|
||||
|
||||
@Output()
|
||||
@@ -111,30 +117,35 @@ export class CustomerTypeSelectorComponent
|
||||
get filteredOptions$() {
|
||||
const options$ = this.select((s) => s.options).pipe(distinctUntilChanged());
|
||||
const p4mUser$ = this.select((s) => s.p4mUser).pipe(distinctUntilChanged());
|
||||
const customerType$ = this.select((s) => s.customerType).pipe(distinctUntilChanged());
|
||||
const customerType$ = this.select((s) => s.customerType).pipe(
|
||||
distinctUntilChanged(),
|
||||
);
|
||||
return combineLatest([options$, p4mUser$, customerType$]).pipe(
|
||||
filter(([options]) => options?.length > 0),
|
||||
map(([options, p4mUser, customerType]) => {
|
||||
const initial = { p4mUser: this.p4mUser, customerType: this.customerType };
|
||||
const initial = {
|
||||
p4mUser: this.p4mUser,
|
||||
customerType: this.customerType,
|
||||
};
|
||||
let result: OptionDTO[] = options;
|
||||
if (p4mUser) {
|
||||
result = result.filter((o) => o.value === 'store' || (o.value === 'webshop' && o.enabled !== false));
|
||||
// if (p4mUser) {
|
||||
// result = result.filter((o) => o.value === 'store' || (o.value === 'webshop' && o.enabled !== false));
|
||||
|
||||
result = result.map((o) => {
|
||||
if (o.value === 'store') {
|
||||
return { ...o, enabled: false };
|
||||
}
|
||||
return o;
|
||||
});
|
||||
}
|
||||
// result = result.map((o) => {
|
||||
// if (o.value === 'store') {
|
||||
// return { ...o, enabled: false };
|
||||
// }
|
||||
// return o;
|
||||
// });
|
||||
// }
|
||||
|
||||
if (customerType === 'b2b' && this.p4mUser) {
|
||||
this.p4mUser = false;
|
||||
}
|
||||
|
||||
if (initial.p4mUser !== this.p4mUser || initial.customerType !== this.customerType) {
|
||||
this.setValue({ customerType: this.customerType, p4mUser: this.p4mUser });
|
||||
}
|
||||
// if (initial.p4mUser !== this.p4mUser || initial.customerType !== this.customerType) {
|
||||
// this.setValue({ customerType: this.customerType, p4mUser: this.p4mUser });
|
||||
// }
|
||||
|
||||
return result;
|
||||
}),
|
||||
@@ -224,42 +235,53 @@ export class CustomerTypeSelectorComponent
|
||||
if (typeof value === 'string') {
|
||||
this.value = value;
|
||||
} else {
|
||||
if (isBoolean(value.p4mUser)) {
|
||||
this.p4mUser = value.p4mUser;
|
||||
}
|
||||
// if (isBoolean(value.p4mUser)) {
|
||||
// this.p4mUser = value.p4mUser;
|
||||
// }
|
||||
if (isString(value.customerType)) {
|
||||
this.customerType = value.customerType;
|
||||
} else if (this.p4mUser) {
|
||||
// Implementierung wie im PBI #3467 beschrieben
|
||||
// wenn customerType nicht gesetzt wird und p4mUser true ist,
|
||||
// dann customerType auf store setzen.
|
||||
// wenn dies nicht möglich ist da der Warenkob keinen store Kunden zulässt,
|
||||
// dann customerType auf webshop setzen.
|
||||
// wenn dies nicht möglich ist da der Warenkob keinen webshop Kunden zulässt,
|
||||
// dann customerType auf den ersten verfügbaren setzen und p4mUser auf false setzen.
|
||||
if (this.enabledOptions.some((o) => o.value === 'store')) {
|
||||
this.customerType = 'store';
|
||||
} else if (this.enabledOptions.some((o) => o.value === 'webshop')) {
|
||||
this.customerType = 'webshop';
|
||||
} else {
|
||||
this.p4mUser = false;
|
||||
const includesGuest = this.enabledOptions.some((o) => o.value === 'guest');
|
||||
this.customerType = includesGuest ? 'guest' : first(this.enabledOptions)?.value;
|
||||
}
|
||||
// } else if (this.p4mUser) {
|
||||
// // Implementierung wie im PBI #3467 beschrieben
|
||||
// // wenn customerType nicht gesetzt wird und p4mUser true ist,
|
||||
// // dann customerType auf store setzen.
|
||||
// // wenn dies nicht möglich ist da der Warenkob keinen store Kunden zulässt,
|
||||
// // dann customerType auf webshop setzen.
|
||||
// // wenn dies nicht möglich ist da der Warenkob keinen webshop Kunden zulässt,
|
||||
// // dann customerType auf den ersten verfügbaren setzen und p4mUser auf false setzen.
|
||||
// if (this.enabledOptions.some((o) => o.value === 'store')) {
|
||||
// this.customerType = 'store';
|
||||
// } else if (this.enabledOptions.some((o) => o.value === 'webshop')) {
|
||||
// this.customerType = 'webshop';
|
||||
// } else {
|
||||
// this.p4mUser = false;
|
||||
// const includesGuest = this.enabledOptions.some(
|
||||
// (o) => o.value === 'guest',
|
||||
// );
|
||||
// this.customerType = includesGuest
|
||||
// ? 'guest'
|
||||
// : first(this.enabledOptions)?.value;
|
||||
// }
|
||||
} else {
|
||||
// wenn customerType nicht gesetzt wird und p4mUser false ist,
|
||||
// dann customerType auf den ersten verfügbaren setzen der nicht mit dem aktuellen customerType übereinstimmt.
|
||||
this.customerType =
|
||||
first(this.enabledOptions.filter((o) => o.value === this.customerType))?.value ?? this.customerType;
|
||||
first(
|
||||
this.enabledOptions.filter((o) => o.value === this.customerType),
|
||||
)?.value ?? this.customerType;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.customerType !== initial.customerType || this.p4mUser !== initial.p4mUser) {
|
||||
if (
|
||||
this.customerType !== initial.customerType ||
|
||||
this.p4mUser !== initial.p4mUser
|
||||
) {
|
||||
this.onChange(this.value);
|
||||
this.onTouched();
|
||||
this.valueChanges.emit(this.value);
|
||||
}
|
||||
|
||||
this.checkboxes?.find((c) => c.name === this.customerType)?.writeValue(true);
|
||||
this.checkboxes
|
||||
?.find((c) => c.name === this.customerType)
|
||||
?.writeValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ export * from './interests';
|
||||
export * from './name';
|
||||
export * from './newsletter';
|
||||
export * from './organisation';
|
||||
export * from './p4m-number';
|
||||
// export * from './p4m-number';
|
||||
export * from './phone-numbers';
|
||||
export * from './form-block';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// start:ng42.barrel
|
||||
export * from './p4m-number-form-block.component';
|
||||
export * from './p4m-number-form-block.module';
|
||||
// end:ng42.barrel
|
||||
// // start:ng42.barrel
|
||||
// export * from './p4m-number-form-block.component';
|
||||
// export * from './p4m-number-form-block.module';
|
||||
// // end:ng42.barrel
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<shared-form-control label="Kundenkartencode" class="flex-grow">
|
||||
<!-- <shared-form-control label="Kundenkartencode" class="flex-grow">
|
||||
<input
|
||||
placeholder="Kundenkartencode"
|
||||
class="input-control"
|
||||
@@ -13,4 +13,4 @@
|
||||
<button type="button" (click)="scan()">
|
||||
<shared-icon icon="barcode-scan" [size]="32"></shared-icon>
|
||||
</button>
|
||||
}
|
||||
} -->
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
import { Component, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
|
||||
import { UntypedFormControl, Validators } from '@angular/forms';
|
||||
import { FormBlockControl } from '../form-block';
|
||||
import { ScanAdapterService } from '@adapter/scan';
|
||||
// import { Component, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
|
||||
// import { UntypedFormControl, Validators } from '@angular/forms';
|
||||
// import { FormBlockControl } from '../form-block';
|
||||
// import { ScanAdapterService } from '@adapter/scan';
|
||||
|
||||
@Component({
|
||||
selector: 'app-p4m-number-form-block',
|
||||
templateUrl: 'p4m-number-form-block.component.html',
|
||||
styleUrls: ['p4m-number-form-block.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
standalone: false,
|
||||
})
|
||||
export class P4mNumberFormBlockComponent extends FormBlockControl<string> {
|
||||
get tabIndexEnd() {
|
||||
return this.tabIndexStart;
|
||||
}
|
||||
// @Component({
|
||||
// selector: 'app-p4m-number-form-block',
|
||||
// templateUrl: 'p4m-number-form-block.component.html',
|
||||
// styleUrls: ['p4m-number-form-block.component.scss'],
|
||||
// changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
// standalone: false,
|
||||
// })
|
||||
// export class P4mNumberFormBlockComponent extends FormBlockControl<string> {
|
||||
// get tabIndexEnd() {
|
||||
// return this.tabIndexStart;
|
||||
// }
|
||||
|
||||
constructor(
|
||||
private scanAdapter: ScanAdapterService,
|
||||
private changeDetectorRef: ChangeDetectorRef,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
// constructor(
|
||||
// private scanAdapter: ScanAdapterService,
|
||||
// private changeDetectorRef: ChangeDetectorRef,
|
||||
// ) {
|
||||
// super();
|
||||
// }
|
||||
|
||||
updateValidators(): void {
|
||||
this.control.setValidators([...this.getValidatorFn()]);
|
||||
this.control.setAsyncValidators(this.getAsyncValidatorFn());
|
||||
this.control.updateValueAndValidity();
|
||||
}
|
||||
// updateValidators(): void {
|
||||
// this.control.setValidators([...this.getValidatorFn()]);
|
||||
// this.control.setAsyncValidators(this.getAsyncValidatorFn());
|
||||
// this.control.updateValueAndValidity();
|
||||
// }
|
||||
|
||||
initializeControl(data?: string): void {
|
||||
this.control = new UntypedFormControl(data ?? '', [Validators.required], this.getAsyncValidatorFn());
|
||||
}
|
||||
// initializeControl(data?: string): void {
|
||||
// this.control = new UntypedFormControl(data ?? '', [Validators.required], this.getAsyncValidatorFn());
|
||||
// }
|
||||
|
||||
_patchValue(update: { previous: string; current: string }): void {
|
||||
this.control.patchValue(update.current);
|
||||
}
|
||||
// _patchValue(update: { previous: string; current: string }): void {
|
||||
// this.control.patchValue(update.current);
|
||||
// }
|
||||
|
||||
scan() {
|
||||
this.scanAdapter.scan().subscribe((result) => {
|
||||
this.control.patchValue(result);
|
||||
this.changeDetectorRef.markForCheck();
|
||||
});
|
||||
}
|
||||
// scan() {
|
||||
// this.scanAdapter.scan().subscribe((result) => {
|
||||
// this.control.patchValue(result);
|
||||
// this.changeDetectorRef.markForCheck();
|
||||
// });
|
||||
// }
|
||||
|
||||
canScan() {
|
||||
return this.scanAdapter.isReady();
|
||||
}
|
||||
}
|
||||
// canScan() {
|
||||
// return this.scanAdapter.isReady();
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
// import { NgModule } from '@angular/core';
|
||||
// import { CommonModule } from '@angular/common';
|
||||
|
||||
import { P4mNumberFormBlockComponent } from './p4m-number-form-block.component';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { IconComponent } from '@shared/components/icon';
|
||||
import { FormControlComponent } from '@shared/components/form-control';
|
||||
// import { P4mNumberFormBlockComponent } from './p4m-number-form-block.component';
|
||||
// import { ReactiveFormsModule } from '@angular/forms';
|
||||
// import { IconComponent } from '@shared/components/icon';
|
||||
// import { FormControlComponent } from '@shared/components/form-control';
|
||||
|
||||
@NgModule({
|
||||
imports: [CommonModule, ReactiveFormsModule, FormControlComponent, IconComponent],
|
||||
exports: [P4mNumberFormBlockComponent],
|
||||
declarations: [P4mNumberFormBlockComponent],
|
||||
})
|
||||
export class P4mNumberFormBlockModule {}
|
||||
// @NgModule({
|
||||
// imports: [CommonModule, ReactiveFormsModule, FormControlComponent, IconComponent],
|
||||
// exports: [P4mNumberFormBlockComponent],
|
||||
// declarations: [P4mNumberFormBlockComponent],
|
||||
// })
|
||||
// export class P4mNumberFormBlockModule {}
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { ChangeDetectorRef, Directive, OnDestroy, OnInit, ViewChild, inject } from '@angular/core';
|
||||
import {
|
||||
ChangeDetectorRef,
|
||||
Directive,
|
||||
OnDestroy,
|
||||
OnInit,
|
||||
ViewChild,
|
||||
inject,
|
||||
} from '@angular/core';
|
||||
import {
|
||||
AbstractControl,
|
||||
AsyncValidatorFn,
|
||||
@@ -11,7 +18,12 @@ import {
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { BreadcrumbService } from '@core/breadcrumb';
|
||||
import { CrmCustomerService } from '@domain/crm';
|
||||
import { AddressDTO, CustomerDTO, PayerDTO, ShippingAddressDTO } from '@generated/swagger/crm-api';
|
||||
import {
|
||||
AddressDTO,
|
||||
CustomerDTO,
|
||||
PayerDTO,
|
||||
ShippingAddressDTO,
|
||||
} from '@generated/swagger/crm-api';
|
||||
import { UiErrorModalComponent, UiModalService } from '@ui/modal';
|
||||
import { UiValidators } from '@ui/validators';
|
||||
import { isNull } from 'lodash';
|
||||
@@ -42,7 +54,10 @@ import {
|
||||
mapCustomerInfoDtoToCustomerCreateFormData,
|
||||
} from './customer-create-form-data';
|
||||
import { AddressSelectionModalService } from '../modals';
|
||||
import { CustomerCreateNavigation, CustomerSearchNavigation } from '@shared/services/navigation';
|
||||
import {
|
||||
CustomerCreateNavigation,
|
||||
CustomerSearchNavigation,
|
||||
} from '@shared/services/navigation';
|
||||
|
||||
@Directive()
|
||||
export abstract class AbstractCreateCustomer implements OnInit, OnDestroy {
|
||||
@@ -104,7 +119,12 @@ export abstract class AbstractCreateCustomer implements OnInit, OnDestroy {
|
||||
);
|
||||
|
||||
this.processId$
|
||||
.pipe(startWith(undefined), bufferCount(2, 1), takeUntil(this.onDestroy$), delay(100))
|
||||
.pipe(
|
||||
startWith(undefined),
|
||||
bufferCount(2, 1),
|
||||
takeUntil(this.onDestroy$),
|
||||
delay(100),
|
||||
)
|
||||
.subscribe(async ([previous, current]) => {
|
||||
if (previous === undefined) {
|
||||
await this._initFormData();
|
||||
@@ -155,7 +175,10 @@ export abstract class AbstractCreateCustomer implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
async addOrUpdateBreadcrumb(processId: number, formData: CustomerCreateFormData) {
|
||||
async addOrUpdateBreadcrumb(
|
||||
processId: number,
|
||||
formData: CustomerCreateFormData,
|
||||
) {
|
||||
await this.breadcrumb.addOrUpdateBreadcrumbIfNotExists({
|
||||
key: processId,
|
||||
name: 'Kundendaten erfassen',
|
||||
@@ -195,7 +218,10 @@ export abstract class AbstractCreateCustomer implements OnInit, OnDestroy {
|
||||
console.log('customerTypeChanged', customerType);
|
||||
}
|
||||
|
||||
addFormBlock(key: keyof CustomerCreateFormData, block: FormBlock<any, AbstractControl>) {
|
||||
addFormBlock(
|
||||
key: keyof CustomerCreateFormData,
|
||||
block: FormBlock<any, AbstractControl>,
|
||||
) {
|
||||
this.form.addControl(key, block.control);
|
||||
this.cdr.markForCheck();
|
||||
}
|
||||
@@ -232,7 +258,10 @@ export abstract class AbstractCreateCustomer implements OnInit, OnDestroy {
|
||||
return true;
|
||||
}
|
||||
// Check Year + Month
|
||||
else if (inputDate.getFullYear() === minBirthDate.getFullYear() && inputDate.getMonth() < minBirthDate.getMonth()) {
|
||||
else if (
|
||||
inputDate.getFullYear() === minBirthDate.getFullYear() &&
|
||||
inputDate.getMonth() < minBirthDate.getMonth()
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
// Check Year + Month + Day
|
||||
@@ -279,70 +308,80 @@ export abstract class AbstractCreateCustomer implements OnInit, OnDestroy {
|
||||
);
|
||||
};
|
||||
|
||||
checkLoyalityCardValidator: AsyncValidatorFn = (control) => {
|
||||
return of(control.value).pipe(
|
||||
delay(500),
|
||||
mergeMap((value) => {
|
||||
const customerId = this.formData?._meta?.customerDto?.id ?? this.formData?._meta?.customerInfoDto?.id;
|
||||
return this.customerService.checkLoyaltyCard({ loyaltyCardNumber: value, customerId }).pipe(
|
||||
map((response) => {
|
||||
if (response.error) {
|
||||
throw response.message;
|
||||
}
|
||||
// checkLoyalityCardValidator: AsyncValidatorFn = (control) => {
|
||||
// return of(control.value).pipe(
|
||||
// delay(500),
|
||||
// mergeMap((value) => {
|
||||
// const customerId = this.formData?._meta?.customerDto?.id ?? this.formData?._meta?.customerInfoDto?.id;
|
||||
// return this.customerService.checkLoyaltyCard({ loyaltyCardNumber: value, customerId }).pipe(
|
||||
// map((response) => {
|
||||
// if (response.error) {
|
||||
// throw response.message;
|
||||
// }
|
||||
|
||||
/**
|
||||
* #4485 Kubi // Verhalten mit angelegte aber nicht verknüpfte Kundenkartencode in Kundensuche und Kundendaten erfassen ist nicht gleich
|
||||
* Fall1: Kundenkarte hat Daten in point4more:
|
||||
* Sobald Kundenkartencode in Feld "Kundenkartencode" reingegeben wird- werden die Daten von point4more in Formular "Kundendaten Erfassen" eingefügt und ersetzen (im Ganzen, nicht inkremental) die Daten in Felder, falls welche schon reingetippt werden.
|
||||
* Fall2: Kundenkarte hat keine Daten in point4more:
|
||||
* Sobald Kundenkartencode in Feld "Kundenkartencode" reingegeben wird- bleiben die Daten in Formular "Kundendaten Erfassen" in Felder, falls welche schon reingetippt werden.
|
||||
*/
|
||||
if (response.result && response.result.customer) {
|
||||
const customer = response.result.customer;
|
||||
const data = mapCustomerInfoDtoToCustomerCreateFormData(customer);
|
||||
// /**
|
||||
// * #4485 Kubi // Verhalten mit angelegte aber nicht verknüpfte Kundenkartencode in Kundensuche und Kundendaten erfassen ist nicht gleich
|
||||
// * Fall1: Kundenkarte hat Daten in point4more:
|
||||
// * Sobald Kundenkartencode in Feld "Kundenkartencode" reingegeben wird- werden die Daten von point4more in Formular "Kundendaten Erfassen" eingefügt und ersetzen (im Ganzen, nicht inkremental) die Daten in Felder, falls welche schon reingetippt werden.
|
||||
// * Fall2: Kundenkarte hat keine Daten in point4more:
|
||||
// * Sobald Kundenkartencode in Feld "Kundenkartencode" reingegeben wird- bleiben die Daten in Formular "Kundendaten Erfassen" in Felder, falls welche schon reingetippt werden.
|
||||
// */
|
||||
// if (response.result && response.result.customer) {
|
||||
// const customer = response.result.customer;
|
||||
// const data = mapCustomerInfoDtoToCustomerCreateFormData(customer);
|
||||
|
||||
if (data.name.firstName && data.name.lastName) {
|
||||
// Fall1
|
||||
this._formData.next(data);
|
||||
} else {
|
||||
// Fall2 Hier müssen die Metadaten gesetzt werden um eine verknüfung zur kundenkarte zu ermöglichen.
|
||||
const current = this.formData;
|
||||
current._meta = data._meta;
|
||||
current.p4m = data.p4m;
|
||||
}
|
||||
}
|
||||
// if (data.name.firstName && data.name.lastName) {
|
||||
// // Fall1
|
||||
// this._formData.next(data);
|
||||
// } else {
|
||||
// // Fall2 Hier müssen die Metadaten gesetzt werden um eine verknüfung zur kundenkarte zu ermöglichen.
|
||||
// const current = this.formData;
|
||||
// current._meta = data._meta;
|
||||
// current.p4m = data.p4m;
|
||||
// }
|
||||
// }
|
||||
|
||||
return null;
|
||||
}),
|
||||
catchError((error) => {
|
||||
if (error instanceof HttpErrorResponse) {
|
||||
if (error?.error?.invalidProperties?.loyaltyCardNumber) {
|
||||
return of({ invalid: error.error.invalidProperties.loyaltyCardNumber });
|
||||
} else {
|
||||
return of({ invalid: 'Kundenkartencode ist ungültig' });
|
||||
}
|
||||
}
|
||||
}),
|
||||
);
|
||||
}),
|
||||
tap(() => {
|
||||
control.markAsTouched();
|
||||
this.cdr.markForCheck();
|
||||
}),
|
||||
);
|
||||
};
|
||||
// return null;
|
||||
// }),
|
||||
// catchError((error) => {
|
||||
// if (error instanceof HttpErrorResponse) {
|
||||
// if (error?.error?.invalidProperties?.loyaltyCardNumber) {
|
||||
// return of({ invalid: error.error.invalidProperties.loyaltyCardNumber });
|
||||
// } else {
|
||||
// return of({ invalid: 'Kundenkartencode ist ungültig' });
|
||||
// }
|
||||
// }
|
||||
// }),
|
||||
// );
|
||||
// }),
|
||||
// tap(() => {
|
||||
// control.markAsTouched();
|
||||
// this.cdr.markForCheck();
|
||||
// }),
|
||||
// );
|
||||
// };
|
||||
|
||||
async navigateToCustomerDetails(customer: CustomerDTO) {
|
||||
const processId = await this.processId$.pipe(first()).toPromise();
|
||||
const route = this.customerSearchNavigation.detailsRoute({ processId, customerId: customer.id, customer });
|
||||
const route = this.customerSearchNavigation.detailsRoute({
|
||||
processId,
|
||||
customerId: customer.id,
|
||||
customer,
|
||||
});
|
||||
|
||||
return this.router.navigate(route.path, { queryParams: route.urlTree.queryParams });
|
||||
return this.router.navigate(route.path, {
|
||||
queryParams: route.urlTree.queryParams,
|
||||
});
|
||||
}
|
||||
|
||||
async validateAddressData(address: AddressDTO): Promise<AddressDTO> {
|
||||
const addressValidationResult = await this.addressVlidationModal.validateAddress(address);
|
||||
const addressValidationResult =
|
||||
await this.addressVlidationModal.validateAddress(address);
|
||||
|
||||
if (addressValidationResult !== undefined && (addressValidationResult as any) !== 'continue') {
|
||||
if (
|
||||
addressValidationResult !== undefined &&
|
||||
(addressValidationResult as any) !== 'continue'
|
||||
) {
|
||||
address = addressValidationResult;
|
||||
}
|
||||
|
||||
@@ -389,7 +428,9 @@ export abstract class AbstractCreateCustomer implements OnInit, OnDestroy {
|
||||
} catch (error) {
|
||||
this.form.enable();
|
||||
setTimeout(() => {
|
||||
this.addressFormBlock.setAddressValidationError(error.error.invalidProperties);
|
||||
this.addressFormBlock.setAddressValidationError(
|
||||
error.error.invalidProperties,
|
||||
);
|
||||
}, 10);
|
||||
|
||||
return;
|
||||
@@ -397,7 +438,10 @@ export abstract class AbstractCreateCustomer implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
if (data.birthDate && isNull(UiValidators.date(new UntypedFormControl(data.birthDate)))) {
|
||||
if (
|
||||
data.birthDate &&
|
||||
isNull(UiValidators.date(new UntypedFormControl(data.birthDate)))
|
||||
) {
|
||||
customer.dateOfBirth = data.birthDate;
|
||||
}
|
||||
|
||||
@@ -406,11 +450,15 @@ export abstract class AbstractCreateCustomer implements OnInit, OnDestroy {
|
||||
|
||||
if (this.validateShippingAddress) {
|
||||
try {
|
||||
billingAddress.address = await this.validateAddressData(billingAddress.address);
|
||||
billingAddress.address = await this.validateAddressData(
|
||||
billingAddress.address,
|
||||
);
|
||||
} catch (error) {
|
||||
this.form.enable();
|
||||
setTimeout(() => {
|
||||
this.addressFormBlock.setAddressValidationError(error.error.invalidProperties);
|
||||
this.addressFormBlock.setAddressValidationError(
|
||||
error.error.invalidProperties,
|
||||
);
|
||||
}, 10);
|
||||
|
||||
return;
|
||||
@@ -426,15 +474,21 @@ export abstract class AbstractCreateCustomer implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
if (data.deviatingDeliveryAddress?.deviatingAddress) {
|
||||
const shippingAddress = this.mapToShippingAddress(data.deviatingDeliveryAddress);
|
||||
const shippingAddress = this.mapToShippingAddress(
|
||||
data.deviatingDeliveryAddress,
|
||||
);
|
||||
|
||||
if (this.validateShippingAddress) {
|
||||
try {
|
||||
shippingAddress.address = await this.validateAddressData(shippingAddress.address);
|
||||
shippingAddress.address = await this.validateAddressData(
|
||||
shippingAddress.address,
|
||||
);
|
||||
} catch (error) {
|
||||
this.form.enable();
|
||||
setTimeout(() => {
|
||||
this.deviatingDeliveryAddressFormBlock.setAddressValidationError(error.error.invalidProperties);
|
||||
this.deviatingDeliveryAddressFormBlock.setAddressValidationError(
|
||||
error.error.invalidProperties,
|
||||
);
|
||||
}, 10);
|
||||
|
||||
return;
|
||||
@@ -474,7 +528,13 @@ export abstract class AbstractCreateCustomer implements OnInit, OnDestroy {
|
||||
};
|
||||
}
|
||||
|
||||
mapToBillingAddress({ name, address, email, organisation, phoneNumbers }: DeviatingAddressFormBlockData): PayerDTO {
|
||||
mapToBillingAddress({
|
||||
name,
|
||||
address,
|
||||
email,
|
||||
organisation,
|
||||
phoneNumbers,
|
||||
}: DeviatingAddressFormBlockData): PayerDTO {
|
||||
return {
|
||||
gender: name?.gender,
|
||||
title: name?.title,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CreateB2BCustomerModule } from './create-b2b-customer/create-b2b-customer.module';
|
||||
import { CreateGuestCustomerModule } from './create-guest-customer';
|
||||
import { CreateP4MCustomerModule } from './create-p4m-customer';
|
||||
// import { CreateP4MCustomerModule } from './create-p4m-customer';
|
||||
import { CreateStoreCustomerModule } from './create-store-customer/create-store-customer.module';
|
||||
import { CreateWebshopCustomerModule } from './create-webshop-customer/create-webshop-customer.module';
|
||||
import { UpdateP4MWebshopCustomerModule } from './update-p4m-webshop-customer';
|
||||
// import { UpdateP4MWebshopCustomerModule } from './update-p4m-webshop-customer';
|
||||
import { CreateCustomerComponent } from './create-customer.component';
|
||||
|
||||
@NgModule({
|
||||
@@ -13,8 +13,8 @@ import { CreateCustomerComponent } from './create-customer.component';
|
||||
CreateGuestCustomerModule,
|
||||
CreateStoreCustomerModule,
|
||||
CreateWebshopCustomerModule,
|
||||
CreateP4MCustomerModule,
|
||||
UpdateP4MWebshopCustomerModule,
|
||||
// CreateP4MCustomerModule,
|
||||
// UpdateP4MWebshopCustomerModule,
|
||||
CreateCustomerComponent,
|
||||
],
|
||||
exports: [
|
||||
@@ -22,8 +22,8 @@ import { CreateCustomerComponent } from './create-customer.component';
|
||||
CreateGuestCustomerModule,
|
||||
CreateStoreCustomerModule,
|
||||
CreateWebshopCustomerModule,
|
||||
CreateP4MCustomerModule,
|
||||
UpdateP4MWebshopCustomerModule,
|
||||
// CreateP4MCustomerModule,
|
||||
// UpdateP4MWebshopCustomerModule,
|
||||
CreateCustomerComponent,
|
||||
],
|
||||
})
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
@if (formData$ | async; as data) {
|
||||
<!-- @if (formData$ | async; as data) {
|
||||
<form (keydown.enter)="$event.preventDefault()">
|
||||
<h1 class="title flex flex-row items-center justify-center">
|
||||
Kundendaten erfassen
|
||||
<!-- <span
|
||||
class="rounded-full ml-4 h-8 w-8 text-xl text-center border-2 border-solid border-brand text-brand">i</span> -->
|
||||
<span
|
||||
class="rounded-full ml-4 h-8 w-8 text-xl text-center border-2 border-solid border-brand text-brand">i</span>
|
||||
</h1>
|
||||
<p class="description">
|
||||
Um Sie als Kunde beim nächsten
|
||||
@@ -135,4 +135,4 @@
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
} -->
|
||||
|
||||
@@ -1,292 +1,292 @@
|
||||
import { Component, ChangeDetectionStrategy, ViewChild, OnInit } from '@angular/core';
|
||||
import { AsyncValidatorFn, ValidatorFn, Validators } from '@angular/forms';
|
||||
import { Result } from '@domain/defs';
|
||||
import { CustomerDTO, CustomerInfoDTO, KeyValueDTOOfStringAndString } from '@generated/swagger/crm-api';
|
||||
import { UiErrorModalComponent, UiModalResult } from '@ui/modal';
|
||||
import { NEVER, Observable, of } from 'rxjs';
|
||||
import { catchError, distinctUntilChanged, first, map, switchMap, takeUntil, withLatestFrom } from 'rxjs/operators';
|
||||
import {
|
||||
AddressFormBlockComponent,
|
||||
AddressFormBlockData,
|
||||
DeviatingAddressFormBlockComponent,
|
||||
} from '../../components/form-blocks';
|
||||
import { NameFormBlockData } from '../../components/form-blocks/name/name-form-block-data';
|
||||
import { WebshopCustomnerAlreadyExistsModalComponent, WebshopCustomnerAlreadyExistsModalData } from '../../modals';
|
||||
import { validateEmail } from '../../validators/email-validator';
|
||||
import { AbstractCreateCustomer } from '../abstract-create-customer';
|
||||
import { encodeFormData, mapCustomerDtoToCustomerCreateFormData } from '../customer-create-form-data';
|
||||
import { zipCodeValidator } from '../../validators/zip-code-validator';
|
||||
// import { Component, ChangeDetectionStrategy, ViewChild, OnInit } from '@angular/core';
|
||||
// import { AsyncValidatorFn, ValidatorFn, Validators } from '@angular/forms';
|
||||
// import { Result } from '@domain/defs';
|
||||
// import { CustomerDTO, CustomerInfoDTO, KeyValueDTOOfStringAndString } from '@generated/swagger/crm-api';
|
||||
// import { UiErrorModalComponent, UiModalResult } from '@ui/modal';
|
||||
// import { NEVER, Observable, of } from 'rxjs';
|
||||
// import { catchError, distinctUntilChanged, first, map, switchMap, takeUntil, withLatestFrom } from 'rxjs/operators';
|
||||
// import {
|
||||
// AddressFormBlockComponent,
|
||||
// AddressFormBlockData,
|
||||
// DeviatingAddressFormBlockComponent,
|
||||
// } from '../../components/form-blocks';
|
||||
// import { NameFormBlockData } from '../../components/form-blocks/name/name-form-block-data';
|
||||
// import { WebshopCustomnerAlreadyExistsModalComponent, WebshopCustomnerAlreadyExistsModalData } from '../../modals';
|
||||
// import { validateEmail } from '../../validators/email-validator';
|
||||
// import { AbstractCreateCustomer } from '../abstract-create-customer';
|
||||
// import { encodeFormData, mapCustomerDtoToCustomerCreateFormData } from '../customer-create-form-data';
|
||||
// import { zipCodeValidator } from '../../validators/zip-code-validator';
|
||||
|
||||
@Component({
|
||||
selector: 'app-create-p4m-customer',
|
||||
templateUrl: 'create-p4m-customer.component.html',
|
||||
styleUrls: ['../create-customer.scss', 'create-p4m-customer.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
standalone: false,
|
||||
})
|
||||
export class CreateP4MCustomerComponent extends AbstractCreateCustomer implements OnInit {
|
||||
validateAddress = true;
|
||||
// @Component({
|
||||
// selector: 'app-create-p4m-customer',
|
||||
// templateUrl: 'create-p4m-customer.component.html',
|
||||
// styleUrls: ['../create-customer.scss', 'create-p4m-customer.component.scss'],
|
||||
// changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
// standalone: false,
|
||||
// })
|
||||
// export class CreateP4MCustomerComponent extends AbstractCreateCustomer implements OnInit {
|
||||
// validateAddress = true;
|
||||
|
||||
validateShippingAddress = true;
|
||||
// validateShippingAddress = true;
|
||||
|
||||
get _customerType() {
|
||||
return this.activatedRoute.snapshot.data.customerType;
|
||||
}
|
||||
// get _customerType() {
|
||||
// return this.activatedRoute.snapshot.data.customerType;
|
||||
// }
|
||||
|
||||
get customerType() {
|
||||
return `${this._customerType}-p4m`;
|
||||
}
|
||||
// get customerType() {
|
||||
// return `${this._customerType}-p4m`;
|
||||
// }
|
||||
|
||||
nameRequiredMarks: (keyof NameFormBlockData)[] = ['gender', 'firstName', 'lastName'];
|
||||
// nameRequiredMarks: (keyof NameFormBlockData)[] = ['gender', 'firstName', 'lastName'];
|
||||
|
||||
nameValidationFns: Record<keyof NameFormBlockData, ValidatorFn[]> = {
|
||||
firstName: [Validators.required],
|
||||
lastName: [Validators.required],
|
||||
gender: [Validators.required],
|
||||
title: [],
|
||||
};
|
||||
// nameValidationFns: Record<keyof NameFormBlockData, ValidatorFn[]> = {
|
||||
// firstName: [Validators.required],
|
||||
// lastName: [Validators.required],
|
||||
// gender: [Validators.required],
|
||||
// title: [],
|
||||
// };
|
||||
|
||||
emailRequiredMark: boolean;
|
||||
// emailRequiredMark: boolean;
|
||||
|
||||
emailValidatorFn: ValidatorFn[];
|
||||
// emailValidatorFn: ValidatorFn[];
|
||||
|
||||
asyncEmailVlaidtorFn: AsyncValidatorFn[];
|
||||
// asyncEmailVlaidtorFn: AsyncValidatorFn[];
|
||||
|
||||
asyncLoyaltyCardValidatorFn: AsyncValidatorFn[];
|
||||
// asyncLoyaltyCardValidatorFn: AsyncValidatorFn[];
|
||||
|
||||
shippingAddressRequiredMarks: (keyof AddressFormBlockData)[] = [
|
||||
'street',
|
||||
'streetNumber',
|
||||
'zipCode',
|
||||
'city',
|
||||
'country',
|
||||
];
|
||||
// shippingAddressRequiredMarks: (keyof AddressFormBlockData)[] = [
|
||||
// 'street',
|
||||
// 'streetNumber',
|
||||
// 'zipCode',
|
||||
// 'city',
|
||||
// 'country',
|
||||
// ];
|
||||
|
||||
shippingAddressValidators: Record<string, ValidatorFn[]> = {
|
||||
street: [Validators.required],
|
||||
streetNumber: [Validators.required],
|
||||
zipCode: [Validators.required, zipCodeValidator()],
|
||||
city: [Validators.required],
|
||||
country: [Validators.required],
|
||||
};
|
||||
// shippingAddressValidators: Record<string, ValidatorFn[]> = {
|
||||
// street: [Validators.required],
|
||||
// streetNumber: [Validators.required],
|
||||
// zipCode: [Validators.required, zipCodeValidator()],
|
||||
// city: [Validators.required],
|
||||
// country: [Validators.required],
|
||||
// };
|
||||
|
||||
addressRequiredMarks: (keyof AddressFormBlockData)[];
|
||||
// addressRequiredMarks: (keyof AddressFormBlockData)[];
|
||||
|
||||
addressValidatorFns: Record<string, ValidatorFn[]>;
|
||||
// addressValidatorFns: Record<string, ValidatorFn[]>;
|
||||
|
||||
@ViewChild(AddressFormBlockComponent, { static: false })
|
||||
addressFormBlock: AddressFormBlockComponent;
|
||||
// @ViewChild(AddressFormBlockComponent, { static: false })
|
||||
// addressFormBlock: AddressFormBlockComponent;
|
||||
|
||||
@ViewChild(DeviatingAddressFormBlockComponent, { static: false })
|
||||
deviatingDeliveryAddressFormBlock: DeviatingAddressFormBlockComponent;
|
||||
// @ViewChild(DeviatingAddressFormBlockComponent, { static: false })
|
||||
// deviatingDeliveryAddressFormBlock: DeviatingAddressFormBlockComponent;
|
||||
|
||||
agbValidatorFns = [Validators.requiredTrue];
|
||||
// agbValidatorFns = [Validators.requiredTrue];
|
||||
|
||||
birthDateValidatorFns = [];
|
||||
// birthDateValidatorFns = [];
|
||||
|
||||
existingCustomer$: Observable<CustomerInfoDTO | CustomerDTO | null>;
|
||||
// existingCustomer$: Observable<CustomerInfoDTO | CustomerDTO | null>;
|
||||
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
this.initMarksAndValidators();
|
||||
this.existingCustomer$ = this.customerExists$.pipe(
|
||||
distinctUntilChanged(),
|
||||
switchMap((exists) => {
|
||||
if (exists) {
|
||||
return this.fetchCustomerInfo();
|
||||
}
|
||||
return of(null);
|
||||
}),
|
||||
);
|
||||
// ngOnInit(): void {
|
||||
// super.ngOnInit();
|
||||
// this.initMarksAndValidators();
|
||||
// this.existingCustomer$ = this.customerExists$.pipe(
|
||||
// distinctUntilChanged(),
|
||||
// switchMap((exists) => {
|
||||
// if (exists) {
|
||||
// return this.fetchCustomerInfo();
|
||||
// }
|
||||
// return of(null);
|
||||
// }),
|
||||
// );
|
||||
|
||||
this.existingCustomer$
|
||||
.pipe(
|
||||
takeUntil(this.onDestroy$),
|
||||
switchMap((info) => {
|
||||
if (info) {
|
||||
return this.customerService.getCustomer(info.id, 2).pipe(
|
||||
map((res) => res.result),
|
||||
catchError((err) => NEVER),
|
||||
);
|
||||
}
|
||||
return NEVER;
|
||||
}),
|
||||
withLatestFrom(this.processId$),
|
||||
)
|
||||
.subscribe(([customer, processId]) => {
|
||||
if (customer) {
|
||||
this.modal
|
||||
.open({
|
||||
content: WebshopCustomnerAlreadyExistsModalComponent,
|
||||
data: {
|
||||
customer,
|
||||
processId,
|
||||
} as WebshopCustomnerAlreadyExistsModalData,
|
||||
title: 'Es existiert bereits ein Onlinekonto mit dieser E-Mail-Adresse',
|
||||
})
|
||||
.afterClosed$.subscribe(async (result: UiModalResult<boolean>) => {
|
||||
if (result.data) {
|
||||
this.navigateToUpdatePage(customer);
|
||||
} else {
|
||||
this.formData.email = '';
|
||||
this.cdr.markForCheck();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
// this.existingCustomer$
|
||||
// .pipe(
|
||||
// takeUntil(this.onDestroy$),
|
||||
// switchMap((info) => {
|
||||
// if (info) {
|
||||
// return this.customerService.getCustomer(info.id, 2).pipe(
|
||||
// map((res) => res.result),
|
||||
// catchError((err) => NEVER),
|
||||
// );
|
||||
// }
|
||||
// return NEVER;
|
||||
// }),
|
||||
// withLatestFrom(this.processId$),
|
||||
// )
|
||||
// .subscribe(([customer, processId]) => {
|
||||
// if (customer) {
|
||||
// this.modal
|
||||
// .open({
|
||||
// content: WebshopCustomnerAlreadyExistsModalComponent,
|
||||
// data: {
|
||||
// customer,
|
||||
// processId,
|
||||
// } as WebshopCustomnerAlreadyExistsModalData,
|
||||
// title: 'Es existiert bereits ein Onlinekonto mit dieser E-Mail-Adresse',
|
||||
// })
|
||||
// .afterClosed$.subscribe(async (result: UiModalResult<boolean>) => {
|
||||
// if (result.data) {
|
||||
// this.navigateToUpdatePage(customer);
|
||||
// } else {
|
||||
// this.formData.email = '';
|
||||
// this.cdr.markForCheck();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
async navigateToUpdatePage(customer: CustomerDTO) {
|
||||
const processId = await this.processId$.pipe(first()).toPromise();
|
||||
this.router.navigate(['/kunde', processId, 'customer', 'create', 'webshop-p4m', 'update'], {
|
||||
queryParams: {
|
||||
formData: encodeFormData({
|
||||
...mapCustomerDtoToCustomerCreateFormData(customer),
|
||||
p4m: this.formData.p4m,
|
||||
}),
|
||||
},
|
||||
});
|
||||
}
|
||||
// async navigateToUpdatePage(customer: CustomerDTO) {
|
||||
// const processId = await this.processId$.pipe(first()).toPromise();
|
||||
// this.router.navigate(['/kunde', processId, 'customer', 'create', 'webshop-p4m', 'update'], {
|
||||
// queryParams: {
|
||||
// formData: encodeFormData({
|
||||
// ...mapCustomerDtoToCustomerCreateFormData(customer),
|
||||
// p4m: this.formData.p4m,
|
||||
// }),
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
|
||||
initMarksAndValidators() {
|
||||
this.asyncLoyaltyCardValidatorFn = [this.checkLoyalityCardValidator];
|
||||
this.birthDateValidatorFns = [Validators.required, this.minBirthDateValidator()];
|
||||
if (this._customerType === 'webshop') {
|
||||
this.emailRequiredMark = true;
|
||||
this.emailValidatorFn = [Validators.required, Validators.email, validateEmail];
|
||||
this.asyncEmailVlaidtorFn = [this.emailExistsValidator];
|
||||
this.addressRequiredMarks = this.shippingAddressRequiredMarks;
|
||||
this.addressValidatorFns = this.shippingAddressValidators;
|
||||
} else {
|
||||
this.emailRequiredMark = false;
|
||||
this.emailValidatorFn = [Validators.email, validateEmail];
|
||||
}
|
||||
}
|
||||
// initMarksAndValidators() {
|
||||
// this.asyncLoyaltyCardValidatorFn = [this.checkLoyalityCardValidator];
|
||||
// this.birthDateValidatorFns = [Validators.required, this.minBirthDateValidator()];
|
||||
// if (this._customerType === 'webshop') {
|
||||
// this.emailRequiredMark = true;
|
||||
// this.emailValidatorFn = [Validators.required, Validators.email, validateEmail];
|
||||
// this.asyncEmailVlaidtorFn = [this.emailExistsValidator];
|
||||
// this.addressRequiredMarks = this.shippingAddressRequiredMarks;
|
||||
// this.addressValidatorFns = this.shippingAddressValidators;
|
||||
// } else {
|
||||
// this.emailRequiredMark = false;
|
||||
// this.emailValidatorFn = [Validators.email, validateEmail];
|
||||
// }
|
||||
// }
|
||||
|
||||
fetchCustomerInfo(): Observable<CustomerDTO | null> {
|
||||
const email = this.formData.email;
|
||||
return this.customerService.getOnlineCustomerByEmail(email).pipe(
|
||||
map((result) => {
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
catchError((err) => {
|
||||
this.modal.open({
|
||||
content: UiErrorModalComponent,
|
||||
data: err,
|
||||
});
|
||||
return [null];
|
||||
}),
|
||||
);
|
||||
}
|
||||
// fetchCustomerInfo(): Observable<CustomerDTO | null> {
|
||||
// const email = this.formData.email;
|
||||
// return this.customerService.getOnlineCustomerByEmail(email).pipe(
|
||||
// map((result) => {
|
||||
// if (result) {
|
||||
// return result;
|
||||
// }
|
||||
// return null;
|
||||
// }),
|
||||
// catchError((err) => {
|
||||
// this.modal.open({
|
||||
// content: UiErrorModalComponent,
|
||||
// data: err,
|
||||
// });
|
||||
// return [null];
|
||||
// }),
|
||||
// );
|
||||
// }
|
||||
|
||||
getInterests(): KeyValueDTOOfStringAndString[] {
|
||||
const interests: KeyValueDTOOfStringAndString[] = [];
|
||||
// getInterests(): KeyValueDTOOfStringAndString[] {
|
||||
// const interests: KeyValueDTOOfStringAndString[] = [];
|
||||
|
||||
for (const key in this.formData.interests) {
|
||||
if (this.formData.interests[key]) {
|
||||
interests.push({ key, group: 'KUBI_INTERESSEN' });
|
||||
}
|
||||
}
|
||||
// for (const key in this.formData.interests) {
|
||||
// if (this.formData.interests[key]) {
|
||||
// interests.push({ key, group: 'KUBI_INTERESSEN' });
|
||||
// }
|
||||
// }
|
||||
|
||||
return interests;
|
||||
}
|
||||
// return interests;
|
||||
// }
|
||||
|
||||
getNewsletter(): KeyValueDTOOfStringAndString | undefined {
|
||||
if (this.formData.newsletter) {
|
||||
return { key: 'kubi_newsletter', group: 'KUBI_NEWSLETTER' };
|
||||
}
|
||||
}
|
||||
// getNewsletter(): KeyValueDTOOfStringAndString | undefined {
|
||||
// if (this.formData.newsletter) {
|
||||
// return { key: 'kubi_newsletter', group: 'KUBI_NEWSLETTER' };
|
||||
// }
|
||||
// }
|
||||
|
||||
static MapCustomerInfoDtoToCustomerDto(customerInfoDto: CustomerInfoDTO): CustomerDTO {
|
||||
return {
|
||||
address: customerInfoDto.address,
|
||||
agentComment: customerInfoDto.agentComment,
|
||||
bonusCard: customerInfoDto.bonusCard,
|
||||
campaignCode: customerInfoDto.campaignCode,
|
||||
communicationDetails: customerInfoDto.communicationDetails,
|
||||
createdInBranch: customerInfoDto.createdInBranch,
|
||||
customerGroup: customerInfoDto.customerGroup,
|
||||
customerNumber: customerInfoDto.customerNumber,
|
||||
customerStatus: customerInfoDto.customerStatus,
|
||||
customerType: customerInfoDto.customerType,
|
||||
dateOfBirth: customerInfoDto.dateOfBirth,
|
||||
features: customerInfoDto.features,
|
||||
firstName: customerInfoDto.firstName,
|
||||
lastName: customerInfoDto.lastName,
|
||||
gender: customerInfoDto.gender,
|
||||
hasOnlineAccount: customerInfoDto.hasOnlineAccount,
|
||||
isGuestAccount: customerInfoDto.isGuestAccount,
|
||||
label: customerInfoDto.label,
|
||||
notificationChannels: customerInfoDto.notificationChannels,
|
||||
organisation: customerInfoDto.organisation,
|
||||
title: customerInfoDto.title,
|
||||
id: customerInfoDto.id,
|
||||
pId: customerInfoDto.pId,
|
||||
};
|
||||
}
|
||||
// static MapCustomerInfoDtoToCustomerDto(customerInfoDto: CustomerInfoDTO): CustomerDTO {
|
||||
// return {
|
||||
// address: customerInfoDto.address,
|
||||
// agentComment: customerInfoDto.agentComment,
|
||||
// bonusCard: customerInfoDto.bonusCard,
|
||||
// campaignCode: customerInfoDto.campaignCode,
|
||||
// communicationDetails: customerInfoDto.communicationDetails,
|
||||
// createdInBranch: customerInfoDto.createdInBranch,
|
||||
// customerGroup: customerInfoDto.customerGroup,
|
||||
// customerNumber: customerInfoDto.customerNumber,
|
||||
// customerStatus: customerInfoDto.customerStatus,
|
||||
// customerType: customerInfoDto.customerType,
|
||||
// dateOfBirth: customerInfoDto.dateOfBirth,
|
||||
// features: customerInfoDto.features,
|
||||
// firstName: customerInfoDto.firstName,
|
||||
// lastName: customerInfoDto.lastName,
|
||||
// gender: customerInfoDto.gender,
|
||||
// hasOnlineAccount: customerInfoDto.hasOnlineAccount,
|
||||
// isGuestAccount: customerInfoDto.isGuestAccount,
|
||||
// label: customerInfoDto.label,
|
||||
// notificationChannels: customerInfoDto.notificationChannels,
|
||||
// organisation: customerInfoDto.organisation,
|
||||
// title: customerInfoDto.title,
|
||||
// id: customerInfoDto.id,
|
||||
// pId: customerInfoDto.pId,
|
||||
// };
|
||||
// }
|
||||
|
||||
async saveCustomer(customer: CustomerDTO): Promise<CustomerDTO> {
|
||||
const isWebshop = this._customerType === 'webshop';
|
||||
let res: Result<CustomerDTO>;
|
||||
// async saveCustomer(customer: CustomerDTO): Promise<CustomerDTO> {
|
||||
// const isWebshop = this._customerType === 'webshop';
|
||||
// let res: Result<CustomerDTO>;
|
||||
|
||||
const { customerDto, customerInfoDto } = this.formData?._meta ?? {};
|
||||
// const { customerDto, customerInfoDto } = this.formData?._meta ?? {};
|
||||
|
||||
if (customerDto) {
|
||||
customer = { ...customerDto, ...customer };
|
||||
} else if (customerInfoDto) {
|
||||
customer = { ...CreateP4MCustomerComponent.MapCustomerInfoDtoToCustomerDto(customerInfoDto), ...customer };
|
||||
}
|
||||
// if (customerDto) {
|
||||
// customer = { ...customerDto, ...customer };
|
||||
// } else if (customerInfoDto) {
|
||||
// customer = { ...CreateP4MCustomerComponent.MapCustomerInfoDtoToCustomerDto(customerInfoDto), ...customer };
|
||||
// }
|
||||
|
||||
const p4mFeature = customer.features?.find((attr) => attr.key === 'p4mUser');
|
||||
if (p4mFeature) {
|
||||
p4mFeature.value = this.formData.p4m;
|
||||
} else {
|
||||
customer.features.push({
|
||||
key: 'p4mUser',
|
||||
value: this.formData.p4m,
|
||||
});
|
||||
}
|
||||
// const p4mFeature = customer.features?.find((attr) => attr.key === 'p4mUser');
|
||||
// if (p4mFeature) {
|
||||
// p4mFeature.value = this.formData.p4m;
|
||||
// } else {
|
||||
// customer.features.push({
|
||||
// key: 'p4mUser',
|
||||
// value: this.formData.p4m,
|
||||
// });
|
||||
// }
|
||||
|
||||
const interests = this.getInterests();
|
||||
// const interests = this.getInterests();
|
||||
|
||||
if (interests.length > 0) {
|
||||
customer.features?.push(...interests);
|
||||
// TODO: Klärung wie Interessen zukünftig gespeichert werden
|
||||
// await this._loyaltyCardService
|
||||
// .LoyaltyCardSaveInteressen({
|
||||
// customerId: res.result.id,
|
||||
// interessen: this.getInterests(),
|
||||
// })
|
||||
// .toPromise();
|
||||
}
|
||||
// if (interests.length > 0) {
|
||||
// customer.features?.push(...interests);
|
||||
// // TODO: Klärung wie Interessen zukünftig gespeichert werden
|
||||
// // await this._loyaltyCardService
|
||||
// // .LoyaltyCardSaveInteressen({
|
||||
// // customerId: res.result.id,
|
||||
// // interessen: this.getInterests(),
|
||||
// // })
|
||||
// // .toPromise();
|
||||
// }
|
||||
|
||||
const newsletter = this.getNewsletter();
|
||||
// const newsletter = this.getNewsletter();
|
||||
|
||||
if (newsletter) {
|
||||
customer.features.push(newsletter);
|
||||
} else {
|
||||
customer.features = customer.features.filter(
|
||||
(feature) => feature.key !== 'kubi_newsletter' && feature.group !== 'KUBI_NEWSLETTER',
|
||||
);
|
||||
}
|
||||
// if (newsletter) {
|
||||
// customer.features.push(newsletter);
|
||||
// } else {
|
||||
// customer.features = customer.features.filter(
|
||||
// (feature) => feature.key !== 'kubi_newsletter' && feature.group !== 'KUBI_NEWSLETTER',
|
||||
// );
|
||||
// }
|
||||
|
||||
if (isWebshop) {
|
||||
if (customer.id > 0) {
|
||||
if (this.formData?._meta?.hasLocalityCard) {
|
||||
res = await this.customerService.updateStoreP4MToWebshopP4M(customer);
|
||||
} else {
|
||||
res = await this.customerService.updateToP4MOnlineCustomer(customer);
|
||||
}
|
||||
} else {
|
||||
res = await this.customerService.createOnlineCustomer(customer).toPromise();
|
||||
}
|
||||
} else {
|
||||
res = await this.customerService.createStoreCustomer(customer).toPromise();
|
||||
}
|
||||
// if (isWebshop) {
|
||||
// if (customer.id > 0) {
|
||||
// if (this.formData?._meta?.hasLocalityCard) {
|
||||
// res = await this.customerService.updateStoreP4MToWebshopP4M(customer);
|
||||
// } else {
|
||||
// res = await this.customerService.updateToP4MOnlineCustomer(customer);
|
||||
// }
|
||||
// } else {
|
||||
// res = await this.customerService.createOnlineCustomer(customer).toPromise();
|
||||
// }
|
||||
// } else {
|
||||
// res = await this.customerService.createStoreCustomer(customer).toPromise();
|
||||
// }
|
||||
|
||||
return res.result;
|
||||
}
|
||||
}
|
||||
// return res.result;
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
// import { NgModule } from '@angular/core';
|
||||
// import { CommonModule } from '@angular/common';
|
||||
|
||||
import { CreateP4MCustomerComponent } from './create-p4m-customer.component';
|
||||
import {
|
||||
AddressFormBlockModule,
|
||||
BirthDateFormBlockModule,
|
||||
InterestsFormBlockModule,
|
||||
NameFormBlockModule,
|
||||
OrganisationFormBlockModule,
|
||||
P4mNumberFormBlockModule,
|
||||
NewsletterFormBlockModule,
|
||||
DeviatingAddressFormBlockComponentModule,
|
||||
AcceptAGBFormBlockModule,
|
||||
EmailFormBlockModule,
|
||||
PhoneNumbersFormBlockModule,
|
||||
} from '../../components/form-blocks';
|
||||
import { CustomerTypeSelectorModule } from '../../components/customer-type-selector';
|
||||
import { UiSpinnerModule } from '@ui/spinner';
|
||||
import { UiIconModule } from '@ui/icon';
|
||||
import { RouterModule } from '@angular/router';
|
||||
// import { CreateP4MCustomerComponent } from './create-p4m-customer.component';
|
||||
// import {
|
||||
// AddressFormBlockModule,
|
||||
// BirthDateFormBlockModule,
|
||||
// InterestsFormBlockModule,
|
||||
// NameFormBlockModule,
|
||||
// OrganisationFormBlockModule,
|
||||
// P4mNumberFormBlockModule,
|
||||
// NewsletterFormBlockModule,
|
||||
// DeviatingAddressFormBlockComponentModule,
|
||||
// AcceptAGBFormBlockModule,
|
||||
// EmailFormBlockModule,
|
||||
// PhoneNumbersFormBlockModule,
|
||||
// } from '../../components/form-blocks';
|
||||
// import { CustomerTypeSelectorModule } from '../../components/customer-type-selector';
|
||||
// import { UiSpinnerModule } from '@ui/spinner';
|
||||
// import { UiIconModule } from '@ui/icon';
|
||||
// import { RouterModule } from '@angular/router';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
CustomerTypeSelectorModule,
|
||||
AddressFormBlockModule,
|
||||
BirthDateFormBlockModule,
|
||||
InterestsFormBlockModule,
|
||||
NameFormBlockModule,
|
||||
OrganisationFormBlockModule,
|
||||
P4mNumberFormBlockModule,
|
||||
NewsletterFormBlockModule,
|
||||
DeviatingAddressFormBlockComponentModule,
|
||||
AcceptAGBFormBlockModule,
|
||||
EmailFormBlockModule,
|
||||
PhoneNumbersFormBlockModule,
|
||||
UiSpinnerModule,
|
||||
UiIconModule,
|
||||
RouterModule,
|
||||
],
|
||||
exports: [CreateP4MCustomerComponent],
|
||||
declarations: [CreateP4MCustomerComponent],
|
||||
})
|
||||
export class CreateP4MCustomerModule {}
|
||||
// @NgModule({
|
||||
// imports: [
|
||||
// CommonModule,
|
||||
// CustomerTypeSelectorModule,
|
||||
// AddressFormBlockModule,
|
||||
// BirthDateFormBlockModule,
|
||||
// InterestsFormBlockModule,
|
||||
// NameFormBlockModule,
|
||||
// OrganisationFormBlockModule,
|
||||
// P4mNumberFormBlockModule,
|
||||
// NewsletterFormBlockModule,
|
||||
// DeviatingAddressFormBlockComponentModule,
|
||||
// AcceptAGBFormBlockModule,
|
||||
// EmailFormBlockModule,
|
||||
// PhoneNumbersFormBlockModule,
|
||||
// UiSpinnerModule,
|
||||
// UiIconModule,
|
||||
// RouterModule,
|
||||
// ],
|
||||
// exports: [CreateP4MCustomerComponent],
|
||||
// declarations: [CreateP4MCustomerComponent],
|
||||
// })
|
||||
// export class CreateP4MCustomerModule {}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from './create-p4m-customer.component';
|
||||
export * from './create-p4m-customer.module';
|
||||
// export * from './create-p4m-customer.component';
|
||||
// export * from './create-p4m-customer.module';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Component, ChangeDetectionStrategy, ViewChild } from '@angular/core';
|
||||
import { ValidatorFn, Validators } from '@angular/forms';
|
||||
import { CustomerDTO } from '@generated/swagger/crm-api';
|
||||
import { CustomerDTO, CustomerInfoDTO } from '@generated/swagger/crm-api';
|
||||
import { map } from 'rxjs/operators';
|
||||
import {
|
||||
AddressFormBlockComponent,
|
||||
@@ -10,13 +10,16 @@ import {
|
||||
import { NameFormBlockData } from '../../components/form-blocks/name/name-form-block-data';
|
||||
import { validateEmail } from '../../validators/email-validator';
|
||||
import { AbstractCreateCustomer } from '../abstract-create-customer';
|
||||
import { CreateP4MCustomerComponent } from '../create-p4m-customer';
|
||||
// import { CreateP4MCustomerComponent } from '../create-p4m-customer';
|
||||
import { zipCodeValidator } from '../../validators/zip-code-validator';
|
||||
|
||||
@Component({
|
||||
selector: 'app-create-webshop-customer',
|
||||
templateUrl: 'create-webshop-customer.component.html',
|
||||
styleUrls: ['../create-customer.scss', 'create-webshop-customer.component.scss'],
|
||||
styleUrls: [
|
||||
'../create-customer.scss',
|
||||
'create-webshop-customer.component.scss',
|
||||
],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
standalone: false,
|
||||
})
|
||||
@@ -26,7 +29,11 @@ export class CreateWebshopCustomerComponent extends AbstractCreateCustomer {
|
||||
validateAddress = true;
|
||||
validateShippingAddress = true;
|
||||
|
||||
nameRequiredMarks: (keyof NameFormBlockData)[] = ['gender', 'firstName', 'lastName'];
|
||||
nameRequiredMarks: (keyof NameFormBlockData)[] = [
|
||||
'gender',
|
||||
'firstName',
|
||||
'lastName',
|
||||
];
|
||||
|
||||
nameValidationFns: Record<keyof NameFormBlockData, ValidatorFn[]> = {
|
||||
firstName: [Validators.required],
|
||||
@@ -35,7 +42,13 @@ export class CreateWebshopCustomerComponent extends AbstractCreateCustomer {
|
||||
title: [],
|
||||
};
|
||||
|
||||
addressRequiredMarks: (keyof AddressFormBlockData)[] = ['street', 'streetNumber', 'zipCode', 'city', 'country'];
|
||||
addressRequiredMarks: (keyof AddressFormBlockData)[] = [
|
||||
'street',
|
||||
'streetNumber',
|
||||
'zipCode',
|
||||
'city',
|
||||
'country',
|
||||
];
|
||||
|
||||
addressValidators: Record<string, ValidatorFn[]> = {
|
||||
street: [Validators.required],
|
||||
@@ -68,7 +81,11 @@ export class CreateWebshopCustomerComponent extends AbstractCreateCustomer {
|
||||
if (customerDto) {
|
||||
customer = { ...customerDto, ...customer };
|
||||
} else if (customerInfoDto) {
|
||||
customer = { ...CreateP4MCustomerComponent.MapCustomerInfoDtoToCustomerDto(customerInfoDto), ...customer };
|
||||
customer = {
|
||||
// ...CreateP4MCustomerComponent.MapCustomerInfoDtoToCustomerDto(customerInfoDto),
|
||||
...this.mapCustomerInfoDtoToCustomerDto(customerInfoDto),
|
||||
...customer,
|
||||
};
|
||||
}
|
||||
|
||||
const res = await this.customerService.updateToOnlineCustomer(customer);
|
||||
@@ -80,4 +97,34 @@ export class CreateWebshopCustomerComponent extends AbstractCreateCustomer {
|
||||
.toPromise();
|
||||
}
|
||||
}
|
||||
|
||||
mapCustomerInfoDtoToCustomerDto(
|
||||
customerInfoDto: CustomerInfoDTO,
|
||||
): CustomerDTO {
|
||||
return {
|
||||
address: customerInfoDto.address,
|
||||
agentComment: customerInfoDto.agentComment,
|
||||
bonusCard: customerInfoDto.bonusCard,
|
||||
campaignCode: customerInfoDto.campaignCode,
|
||||
communicationDetails: customerInfoDto.communicationDetails,
|
||||
createdInBranch: customerInfoDto.createdInBranch,
|
||||
customerGroup: customerInfoDto.customerGroup,
|
||||
customerNumber: customerInfoDto.customerNumber,
|
||||
customerStatus: customerInfoDto.customerStatus,
|
||||
customerType: customerInfoDto.customerType,
|
||||
dateOfBirth: customerInfoDto.dateOfBirth,
|
||||
features: customerInfoDto.features,
|
||||
firstName: customerInfoDto.firstName,
|
||||
lastName: customerInfoDto.lastName,
|
||||
gender: customerInfoDto.gender,
|
||||
hasOnlineAccount: customerInfoDto.hasOnlineAccount,
|
||||
isGuestAccount: customerInfoDto.isGuestAccount,
|
||||
label: customerInfoDto.label,
|
||||
notificationChannels: customerInfoDto.notificationChannels,
|
||||
organisation: customerInfoDto.organisation,
|
||||
title: customerInfoDto.title,
|
||||
id: customerInfoDto.id,
|
||||
pId: customerInfoDto.pId,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { CustomerDTO, Gender } from '@generated/swagger/crm-api';
|
||||
|
||||
export interface CreateCustomerQueryParams {
|
||||
p4mNumber?: string;
|
||||
// p4mNumber?: string;
|
||||
customerId?: number;
|
||||
gender?: Gender;
|
||||
title?: string;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export * from './create-b2b-customer';
|
||||
export * from './create-guest-customer';
|
||||
export * from './create-p4m-customer';
|
||||
// export * from './create-p4m-customer';
|
||||
export * from './create-store-customer';
|
||||
export * from './create-webshop-customer';
|
||||
export * from './defs';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@if (formData$ | async; as data) {
|
||||
<!-- @if (formData$ | async; as data) {
|
||||
<form (keydown.enter)="$event.preventDefault()">
|
||||
<h1 class="title flex flex-row items-center justify-center">Kundenkartendaten erfasen</h1>
|
||||
<p class="description">Bitte erfassen Sie die Kundenkarte</p>
|
||||
@@ -106,4 +106,4 @@
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
} -->
|
||||
|
||||
@@ -1,156 +1,156 @@
|
||||
import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core';
|
||||
import { AsyncValidatorFn, ValidatorFn, Validators } from '@angular/forms';
|
||||
import { Result } from '@domain/defs';
|
||||
import { CustomerDTO, KeyValueDTOOfStringAndString, PayerDTO } from '@generated/swagger/crm-api';
|
||||
import { AddressFormBlockData } from '../../components/form-blocks';
|
||||
import { NameFormBlockData } from '../../components/form-blocks/name/name-form-block-data';
|
||||
import { AbstractCreateCustomer } from '../abstract-create-customer';
|
||||
import { CreateP4MCustomerComponent } from '../create-p4m-customer';
|
||||
// import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core';
|
||||
// import { AsyncValidatorFn, ValidatorFn, Validators } from '@angular/forms';
|
||||
// import { Result } from '@domain/defs';
|
||||
// import { CustomerDTO, KeyValueDTOOfStringAndString, PayerDTO } from '@generated/swagger/crm-api';
|
||||
// import { AddressFormBlockData } from '../../components/form-blocks';
|
||||
// import { NameFormBlockData } from '../../components/form-blocks/name/name-form-block-data';
|
||||
// import { AbstractCreateCustomer } from '../abstract-create-customer';
|
||||
// import { CreateP4MCustomerComponent } from '../create-p4m-customer';
|
||||
|
||||
@Component({
|
||||
selector: 'page-update-p4m-webshop-customer',
|
||||
templateUrl: 'update-p4m-webshop-customer.component.html',
|
||||
styleUrls: ['../create-customer.scss', 'update-p4m-webshop-customer.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
standalone: false,
|
||||
})
|
||||
export class UpdateP4MWebshopCustomerComponent extends AbstractCreateCustomer implements OnInit {
|
||||
customerType = 'webshop-p4m/update';
|
||||
// @Component({
|
||||
// selector: 'page-update-p4m-webshop-customer',
|
||||
// templateUrl: 'update-p4m-webshop-customer.component.html',
|
||||
// styleUrls: ['../create-customer.scss', 'update-p4m-webshop-customer.component.scss'],
|
||||
// changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
// standalone: false,
|
||||
// })
|
||||
// export class UpdateP4MWebshopCustomerComponent extends AbstractCreateCustomer implements OnInit {
|
||||
// customerType = 'webshop-p4m/update';
|
||||
|
||||
validateAddress = true;
|
||||
// validateAddress = true;
|
||||
|
||||
validateShippingAddress = true;
|
||||
// validateShippingAddress = true;
|
||||
|
||||
agbValidatorFns = [Validators.requiredTrue];
|
||||
// agbValidatorFns = [Validators.requiredTrue];
|
||||
|
||||
birthDateValidatorFns = [Validators.required, this.minBirthDateValidator()];
|
||||
// birthDateValidatorFns = [Validators.required, this.minBirthDateValidator()];
|
||||
|
||||
nameRequiredMarks: (keyof NameFormBlockData)[] = ['gender', 'firstName', 'lastName'];
|
||||
// nameRequiredMarks: (keyof NameFormBlockData)[] = ['gender', 'firstName', 'lastName'];
|
||||
|
||||
nameValidationFns: Record<keyof NameFormBlockData, ValidatorFn[]> = {
|
||||
firstName: [Validators.required],
|
||||
lastName: [Validators.required],
|
||||
gender: [Validators.required],
|
||||
title: [],
|
||||
};
|
||||
// nameValidationFns: Record<keyof NameFormBlockData, ValidatorFn[]> = {
|
||||
// firstName: [Validators.required],
|
||||
// lastName: [Validators.required],
|
||||
// gender: [Validators.required],
|
||||
// title: [],
|
||||
// };
|
||||
|
||||
addressRequiredMarks: (keyof AddressFormBlockData)[] = ['street', 'streetNumber', 'zipCode', 'city', 'country'];
|
||||
// addressRequiredMarks: (keyof AddressFormBlockData)[] = ['street', 'streetNumber', 'zipCode', 'city', 'country'];
|
||||
|
||||
addressValidatorFns: Record<string, ValidatorFn[]> = {
|
||||
street: [Validators.required],
|
||||
streetNumber: [Validators.required],
|
||||
zipCode: [Validators.required],
|
||||
city: [Validators.required],
|
||||
country: [Validators.required],
|
||||
};
|
||||
// addressValidatorFns: Record<string, ValidatorFn[]> = {
|
||||
// street: [Validators.required],
|
||||
// streetNumber: [Validators.required],
|
||||
// zipCode: [Validators.required],
|
||||
// city: [Validators.required],
|
||||
// country: [Validators.required],
|
||||
// };
|
||||
|
||||
asyncLoyaltyCardValidatorFn: AsyncValidatorFn[] = [this.checkLoyalityCardValidator];
|
||||
// asyncLoyaltyCardValidatorFn: AsyncValidatorFn[] = [this.checkLoyalityCardValidator];
|
||||
|
||||
get billingAddress(): PayerDTO | undefined {
|
||||
const payers = this.formData?._meta?.customerDto?.payers;
|
||||
// get billingAddress(): PayerDTO | undefined {
|
||||
// const payers = this.formData?._meta?.customerDto?.payers;
|
||||
|
||||
if (!payers || payers.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
// if (!payers || payers.length === 0) {
|
||||
// return undefined;
|
||||
// }
|
||||
|
||||
// the default payer is the payer with the latest isDefault(Date) value
|
||||
const defaultPayer = payers.reduce((prev, curr) =>
|
||||
new Date(prev.isDefault) > new Date(curr.isDefault) ? prev : curr,
|
||||
);
|
||||
// // the default payer is the payer with the latest isDefault(Date) value
|
||||
// const defaultPayer = payers.reduce((prev, curr) =>
|
||||
// new Date(prev.isDefault) > new Date(curr.isDefault) ? prev : curr,
|
||||
// );
|
||||
|
||||
return defaultPayer.payer.data;
|
||||
}
|
||||
// return defaultPayer.payer.data;
|
||||
// }
|
||||
|
||||
get shippingAddress() {
|
||||
const shippingAddresses = this.formData?._meta?.customerDto?.shippingAddresses;
|
||||
// get shippingAddress() {
|
||||
// const shippingAddresses = this.formData?._meta?.customerDto?.shippingAddresses;
|
||||
|
||||
if (!shippingAddresses || shippingAddresses.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
// if (!shippingAddresses || shippingAddresses.length === 0) {
|
||||
// return undefined;
|
||||
// }
|
||||
|
||||
// the default shipping address is the shipping address with the latest isDefault(Date) value
|
||||
const defaultShippingAddress = shippingAddresses.reduce((prev, curr) =>
|
||||
new Date(prev.data.isDefault) > new Date(curr.data.isDefault) ? prev : curr,
|
||||
);
|
||||
// // the default shipping address is the shipping address with the latest isDefault(Date) value
|
||||
// const defaultShippingAddress = shippingAddresses.reduce((prev, curr) =>
|
||||
// new Date(prev.data.isDefault) > new Date(curr.data.isDefault) ? prev : curr,
|
||||
// );
|
||||
|
||||
return defaultShippingAddress.data;
|
||||
}
|
||||
// return defaultShippingAddress.data;
|
||||
// }
|
||||
|
||||
ngOnInit() {
|
||||
super.ngOnInit();
|
||||
}
|
||||
// ngOnInit() {
|
||||
// super.ngOnInit();
|
||||
// }
|
||||
|
||||
getInterests(): KeyValueDTOOfStringAndString[] {
|
||||
const interests: KeyValueDTOOfStringAndString[] = [];
|
||||
// getInterests(): KeyValueDTOOfStringAndString[] {
|
||||
// const interests: KeyValueDTOOfStringAndString[] = [];
|
||||
|
||||
for (const key in this.formData.interests) {
|
||||
if (this.formData.interests[key]) {
|
||||
interests.push({ key, group: 'KUBI_INTERESSEN' });
|
||||
}
|
||||
}
|
||||
// for (const key in this.formData.interests) {
|
||||
// if (this.formData.interests[key]) {
|
||||
// interests.push({ key, group: 'KUBI_INTERESSEN' });
|
||||
// }
|
||||
// }
|
||||
|
||||
return interests;
|
||||
}
|
||||
// return interests;
|
||||
// }
|
||||
|
||||
getNewsletter(): KeyValueDTOOfStringAndString | undefined {
|
||||
if (this.formData.newsletter) {
|
||||
return { key: 'kubi_newsletter', group: 'KUBI_NEWSLETTER' };
|
||||
}
|
||||
}
|
||||
// getNewsletter(): KeyValueDTOOfStringAndString | undefined {
|
||||
// if (this.formData.newsletter) {
|
||||
// return { key: 'kubi_newsletter', group: 'KUBI_NEWSLETTER' };
|
||||
// }
|
||||
// }
|
||||
|
||||
async saveCustomer(customer: CustomerDTO): Promise<CustomerDTO> {
|
||||
let res: Result<CustomerDTO>;
|
||||
// async saveCustomer(customer: CustomerDTO): Promise<CustomerDTO> {
|
||||
// let res: Result<CustomerDTO>;
|
||||
|
||||
const { customerDto, customerInfoDto } = this.formData?._meta ?? {};
|
||||
// const { customerDto, customerInfoDto } = this.formData?._meta ?? {};
|
||||
|
||||
if (customerDto) {
|
||||
customer = { ...customerDto, shippingAddresses: [], payers: [], ...customer };
|
||||
// if (customerDto) {
|
||||
// customer = { ...customerDto, shippingAddresses: [], payers: [], ...customer };
|
||||
|
||||
if (customerDto.shippingAddresses?.length) {
|
||||
customer.shippingAddresses.unshift(...customerDto.shippingAddresses);
|
||||
}
|
||||
if (customerDto.payers?.length) {
|
||||
customer.payers.unshift(...customerDto.payers);
|
||||
}
|
||||
} else if (customerInfoDto) {
|
||||
customer = { ...CreateP4MCustomerComponent.MapCustomerInfoDtoToCustomerDto(customerInfoDto), ...customer };
|
||||
}
|
||||
// if (customerDto.shippingAddresses?.length) {
|
||||
// customer.shippingAddresses.unshift(...customerDto.shippingAddresses);
|
||||
// }
|
||||
// if (customerDto.payers?.length) {
|
||||
// customer.payers.unshift(...customerDto.payers);
|
||||
// }
|
||||
// } else if (customerInfoDto) {
|
||||
// customer = { ...CreateP4MCustomerComponent.MapCustomerInfoDtoToCustomerDto(customerInfoDto), ...customer };
|
||||
// }
|
||||
|
||||
const p4mFeature = customer.features?.find((attr) => attr.key === 'p4mUser');
|
||||
if (p4mFeature) {
|
||||
p4mFeature.value = this.formData.p4m;
|
||||
} else {
|
||||
customer.features.push({
|
||||
key: 'p4mUser',
|
||||
value: this.formData.p4m,
|
||||
});
|
||||
}
|
||||
// const p4mFeature = customer.features?.find((attr) => attr.key === 'p4mUser');
|
||||
// if (p4mFeature) {
|
||||
// p4mFeature.value = this.formData.p4m;
|
||||
// } else {
|
||||
// customer.features.push({
|
||||
// key: 'p4mUser',
|
||||
// value: this.formData.p4m,
|
||||
// });
|
||||
// }
|
||||
|
||||
const interests = this.getInterests();
|
||||
// const interests = this.getInterests();
|
||||
|
||||
if (interests.length > 0) {
|
||||
customer.features?.push(...interests);
|
||||
// TODO: Klärung wie Interessen zukünftig gespeichert werden
|
||||
// await this._loyaltyCardService
|
||||
// .LoyaltyCardSaveInteressen({
|
||||
// customerId: res.result.id,
|
||||
// interessen: this.getInterests(),
|
||||
// })
|
||||
// .toPromise();
|
||||
}
|
||||
// if (interests.length > 0) {
|
||||
// customer.features?.push(...interests);
|
||||
// // TODO: Klärung wie Interessen zukünftig gespeichert werden
|
||||
// // await this._loyaltyCardService
|
||||
// // .LoyaltyCardSaveInteressen({
|
||||
// // customerId: res.result.id,
|
||||
// // interessen: this.getInterests(),
|
||||
// // })
|
||||
// // .toPromise();
|
||||
// }
|
||||
|
||||
const newsletter = this.getNewsletter();
|
||||
// const newsletter = this.getNewsletter();
|
||||
|
||||
if (newsletter) {
|
||||
customer.features.push(newsletter);
|
||||
} else {
|
||||
customer.features = customer.features.filter(
|
||||
(feature) => feature.key !== 'kubi_newsletter' && feature.group !== 'KUBI_NEWSLETTER',
|
||||
);
|
||||
}
|
||||
// if (newsletter) {
|
||||
// customer.features.push(newsletter);
|
||||
// } else {
|
||||
// customer.features = customer.features.filter(
|
||||
// (feature) => feature.key !== 'kubi_newsletter' && feature.group !== 'KUBI_NEWSLETTER',
|
||||
// );
|
||||
// }
|
||||
|
||||
res = await this.customerService.updateToP4MOnlineCustomer(customer);
|
||||
// res = await this.customerService.updateToP4MOnlineCustomer(customer);
|
||||
|
||||
return res.result;
|
||||
}
|
||||
}
|
||||
// return res.result;
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -1,48 +1,48 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
// import { NgModule } from '@angular/core';
|
||||
// import { CommonModule } from '@angular/common';
|
||||
|
||||
import { UpdateP4MWebshopCustomerComponent } from './update-p4m-webshop-customer.component';
|
||||
// import { UpdateP4MWebshopCustomerComponent } from './update-p4m-webshop-customer.component';
|
||||
|
||||
import {
|
||||
AddressFormBlockModule,
|
||||
BirthDateFormBlockModule,
|
||||
InterestsFormBlockModule,
|
||||
NameFormBlockModule,
|
||||
OrganisationFormBlockModule,
|
||||
P4mNumberFormBlockModule,
|
||||
NewsletterFormBlockModule,
|
||||
DeviatingAddressFormBlockComponentModule,
|
||||
AcceptAGBFormBlockModule,
|
||||
EmailFormBlockModule,
|
||||
PhoneNumbersFormBlockModule,
|
||||
} from '../../components/form-blocks';
|
||||
import { UiFormControlModule } from '@ui/form-control';
|
||||
import { UiInputModule } from '@ui/input';
|
||||
import { CustomerPipesModule } from '@shared/pipes/customer';
|
||||
import { CustomerTypeSelectorModule } from '../../components/customer-type-selector';
|
||||
import { UiSpinnerModule } from '@ui/spinner';
|
||||
// import {
|
||||
// AddressFormBlockModule,
|
||||
// BirthDateFormBlockModule,
|
||||
// InterestsFormBlockModule,
|
||||
// NameFormBlockModule,
|
||||
// OrganisationFormBlockModule,
|
||||
// P4mNumberFormBlockModule,
|
||||
// NewsletterFormBlockModule,
|
||||
// DeviatingAddressFormBlockComponentModule,
|
||||
// AcceptAGBFormBlockModule,
|
||||
// EmailFormBlockModule,
|
||||
// PhoneNumbersFormBlockModule,
|
||||
// } from '../../components/form-blocks';
|
||||
// import { UiFormControlModule } from '@ui/form-control';
|
||||
// import { UiInputModule } from '@ui/input';
|
||||
// import { CustomerPipesModule } from '@shared/pipes/customer';
|
||||
// import { CustomerTypeSelectorModule } from '../../components/customer-type-selector';
|
||||
// import { UiSpinnerModule } from '@ui/spinner';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
CustomerTypeSelectorModule,
|
||||
AddressFormBlockModule,
|
||||
BirthDateFormBlockModule,
|
||||
InterestsFormBlockModule,
|
||||
NameFormBlockModule,
|
||||
OrganisationFormBlockModule,
|
||||
P4mNumberFormBlockModule,
|
||||
NewsletterFormBlockModule,
|
||||
DeviatingAddressFormBlockComponentModule,
|
||||
AcceptAGBFormBlockModule,
|
||||
EmailFormBlockModule,
|
||||
PhoneNumbersFormBlockModule,
|
||||
UiFormControlModule,
|
||||
UiInputModule,
|
||||
CustomerPipesModule,
|
||||
UiSpinnerModule,
|
||||
],
|
||||
exports: [UpdateP4MWebshopCustomerComponent],
|
||||
declarations: [UpdateP4MWebshopCustomerComponent],
|
||||
})
|
||||
export class UpdateP4MWebshopCustomerModule {}
|
||||
// @NgModule({
|
||||
// imports: [
|
||||
// CommonModule,
|
||||
// CustomerTypeSelectorModule,
|
||||
// AddressFormBlockModule,
|
||||
// BirthDateFormBlockModule,
|
||||
// InterestsFormBlockModule,
|
||||
// NameFormBlockModule,
|
||||
// OrganisationFormBlockModule,
|
||||
// P4mNumberFormBlockModule,
|
||||
// NewsletterFormBlockModule,
|
||||
// DeviatingAddressFormBlockComponentModule,
|
||||
// AcceptAGBFormBlockModule,
|
||||
// EmailFormBlockModule,
|
||||
// PhoneNumbersFormBlockModule,
|
||||
// UiFormControlModule,
|
||||
// UiInputModule,
|
||||
// CustomerPipesModule,
|
||||
// UiSpinnerModule,
|
||||
// ],
|
||||
// exports: [UpdateP4MWebshopCustomerComponent],
|
||||
// declarations: [UpdateP4MWebshopCustomerComponent],
|
||||
// })
|
||||
// export class UpdateP4MWebshopCustomerModule {}
|
||||
|
||||
@@ -1,15 +1,33 @@
|
||||
import { Component, ChangeDetectionStrategy, OnInit, OnDestroy, inject, effect, untracked } from '@angular/core';
|
||||
import {
|
||||
Component,
|
||||
ChangeDetectionStrategy,
|
||||
OnInit,
|
||||
OnDestroy,
|
||||
inject,
|
||||
effect,
|
||||
untracked,
|
||||
} from '@angular/core';
|
||||
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
||||
import { BehaviorSubject, Subject, Subscription, fromEvent } from 'rxjs';
|
||||
import {
|
||||
BehaviorSubject,
|
||||
Subject,
|
||||
Subscription,
|
||||
firstValueFrom,
|
||||
fromEvent,
|
||||
} from 'rxjs';
|
||||
import { CustomerSearchStore } from './store/customer-search.store';
|
||||
import { provideComponentStore } from '@ngrx/component-store';
|
||||
import { Breadcrumb, BreadcrumbService } from '@core/breadcrumb';
|
||||
import { delay, filter, first, switchMap, takeUntil } from 'rxjs/operators';
|
||||
import { CustomerCreateNavigation, CustomerSearchNavigation } from '@shared/services/navigation';
|
||||
import {
|
||||
CustomerCreateNavigation,
|
||||
CustomerSearchNavigation,
|
||||
} from '@shared/services/navigation';
|
||||
import { CustomerSearchMainAutocompleteProvider } from './providers/customer-search-main-autocomplete.provider';
|
||||
import { FilterAutocompleteProvider } from '@shared/components/filter';
|
||||
import { toSignal } from '@angular/core/rxjs-interop';
|
||||
import { provideCancelSearchSubject } from '@shared/services/cancel-subject';
|
||||
import { injectFeedbackErrorDialog } from '@isa/ui/dialog';
|
||||
|
||||
@Component({
|
||||
selector: 'page-customer-search',
|
||||
@@ -28,6 +46,7 @@ import { provideCancelSearchSubject } from '@shared/services/cancel-subject';
|
||||
standalone: false,
|
||||
})
|
||||
export class CustomerSearchComponent implements OnInit, OnDestroy {
|
||||
#errorFeedbackDialog = injectFeedbackErrorDialog();
|
||||
private _store = inject(CustomerSearchStore);
|
||||
private _activatedRoute = inject(ActivatedRoute);
|
||||
private _router = inject(Router);
|
||||
@@ -37,7 +56,11 @@ export class CustomerSearchComponent implements OnInit, OnDestroy {
|
||||
|
||||
private searchStore = inject(CustomerSearchStore);
|
||||
|
||||
keyEscPressed = toSignal(fromEvent(document, 'keydown').pipe(filter((e: KeyboardEvent) => e.key === 'Escape')));
|
||||
keyEscPressed = toSignal(
|
||||
fromEvent(document, 'keydown').pipe(
|
||||
filter((e: KeyboardEvent) => e.key === 'Escape'),
|
||||
),
|
||||
);
|
||||
|
||||
get breadcrumb() {
|
||||
let breadcrumb: string;
|
||||
@@ -53,7 +76,9 @@ export class CustomerSearchComponent implements OnInit, OnDestroy {
|
||||
|
||||
private _breadcrumbs$ = this._store.processId$.pipe(
|
||||
filter((id) => !!id),
|
||||
switchMap((id) => this._breadcrumbService.getBreadcrumbsByKeyAndTag$(id, 'customer')),
|
||||
switchMap((id) =>
|
||||
this._breadcrumbService.getBreadcrumbsByKeyAndTag$(id, 'customer'),
|
||||
),
|
||||
);
|
||||
|
||||
side$ = new BehaviorSubject<string | undefined>(undefined);
|
||||
@@ -97,53 +122,77 @@ export class CustomerSearchComponent implements OnInit, OnDestroy {
|
||||
this.checkDetailsBreadcrumb();
|
||||
});
|
||||
|
||||
this._eventsSubscription = this._router.events.pipe(takeUntil(this._onDestroy$)).subscribe((event) => {
|
||||
if (event instanceof NavigationEnd) {
|
||||
this.checkAndUpdateProcessId();
|
||||
this.checkAndUpdateSide();
|
||||
this.checkAndUpdateCustomerId();
|
||||
this.checkBreadcrumbs();
|
||||
}
|
||||
});
|
||||
|
||||
this._store.customerListResponse$
|
||||
this._eventsSubscription = this._router.events
|
||||
.pipe(takeUntil(this._onDestroy$))
|
||||
.subscribe(async ([response, filter, processId, restored, skipNavigation]) => {
|
||||
if (this._store.processId === processId) {
|
||||
if (skipNavigation) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.hits === 1) {
|
||||
// Navigate to details page
|
||||
const customer = response.result[0];
|
||||
|
||||
if (customer.id < 0) {
|
||||
// navigate to create customer
|
||||
const route = this._createNavigation.upgradeCustomerRoute({ processId, customerInfo: customer });
|
||||
await this._router.navigate(route.path, { queryParams: route.queryParams });
|
||||
return;
|
||||
} else {
|
||||
const route = this._navigation.detailsRoute({ processId, customerId: customer.id });
|
||||
await this._router.navigate(route.path, { queryParams: filter.getQueryParams() });
|
||||
}
|
||||
} else if (response.hits > 1) {
|
||||
const route = this._navigation.listRoute({ processId, filter });
|
||||
|
||||
if (
|
||||
(['details'].includes(this.breadcrumb) &&
|
||||
response?.result?.some((c) => c.id === this._store.customerId)) ||
|
||||
restored
|
||||
) {
|
||||
await this._router.navigate([], { queryParams: route.queryParams });
|
||||
} else {
|
||||
await this._router.navigate(route.path, { queryParams: route.queryParams });
|
||||
}
|
||||
}
|
||||
|
||||
.subscribe((event) => {
|
||||
if (event instanceof NavigationEnd) {
|
||||
this.checkAndUpdateProcessId();
|
||||
this.checkAndUpdateSide();
|
||||
this.checkAndUpdateCustomerId();
|
||||
this.checkBreadcrumbs();
|
||||
}
|
||||
});
|
||||
|
||||
this._store.customerListResponse$
|
||||
.pipe(takeUntil(this._onDestroy$))
|
||||
.subscribe(
|
||||
async ([response, filter, processId, restored, skipNavigation]) => {
|
||||
if (this._store.processId === processId) {
|
||||
if (skipNavigation) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.hits === 1) {
|
||||
// Navigate to details page
|
||||
const customer = response.result[0];
|
||||
|
||||
if (customer.id < 0) {
|
||||
// #5375 - Zusätzlich soll bei Kunden bei denen ein Upgrade möglich ist ein Dialog angezeigt werden, dass Kundenneuanlage mit Kundenkarte nicht möglich ist
|
||||
await firstValueFrom(
|
||||
this.#errorFeedbackDialog({
|
||||
data: {
|
||||
errorMessage:
|
||||
'Kundenneuanlage mit Kundenkarte nicht möglich',
|
||||
},
|
||||
}).closed,
|
||||
);
|
||||
// navigate to create customer
|
||||
// const route = this._createNavigation.upgradeCustomerRoute({ processId, customerInfo: customer });
|
||||
// await this._router.navigate(route.path, { queryParams: route.queryParams });
|
||||
return;
|
||||
} else {
|
||||
const route = this._navigation.detailsRoute({
|
||||
processId,
|
||||
customerId: customer.id,
|
||||
});
|
||||
await this._router.navigate(route.path, {
|
||||
queryParams: filter.getQueryParams(),
|
||||
});
|
||||
}
|
||||
} else if (response.hits > 1) {
|
||||
const route = this._navigation.listRoute({ processId, filter });
|
||||
|
||||
if (
|
||||
(['details'].includes(this.breadcrumb) &&
|
||||
response?.result?.some(
|
||||
(c) => c.id === this._store.customerId,
|
||||
)) ||
|
||||
restored
|
||||
) {
|
||||
await this._router.navigate([], {
|
||||
queryParams: route.queryParams,
|
||||
});
|
||||
} else {
|
||||
await this._router.navigate(route.path, {
|
||||
queryParams: route.queryParams,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this.checkBreadcrumbs();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
@@ -169,7 +218,11 @@ export class CustomerSearchComponent implements OnInit, OnDestroy {
|
||||
this._store.setProcessId(processId);
|
||||
this._store.reset(this._activatedRoute.snapshot.queryParams);
|
||||
if (!['main', 'filter'].some((s) => s === this.breadcrumb)) {
|
||||
const skipNavigation = ['orders', 'order-details', 'order-details-history'].includes(this.breadcrumb);
|
||||
const skipNavigation = [
|
||||
'orders',
|
||||
'order-details',
|
||||
'order-details-history',
|
||||
].includes(this.breadcrumb);
|
||||
this._store.search({ skipNavigation });
|
||||
}
|
||||
}
|
||||
@@ -229,7 +282,9 @@ export class CustomerSearchComponent implements OnInit, OnDestroy {
|
||||
const mainBreadcrumb = await this.getMainBreadcrumb();
|
||||
|
||||
if (!mainBreadcrumb) {
|
||||
const navigation = this._navigation.defaultRoute({ processId: this._store.processId });
|
||||
const navigation = this._navigation.defaultRoute({
|
||||
processId: this._store.processId,
|
||||
});
|
||||
const breadcrumb: Breadcrumb = {
|
||||
key: this._store.processId,
|
||||
tags: ['customer', 'search', 'main'],
|
||||
@@ -242,14 +297,19 @@ export class CustomerSearchComponent implements OnInit, OnDestroy {
|
||||
this._breadcrumbService.addBreadcrumb(breadcrumb);
|
||||
} else {
|
||||
this._breadcrumbService.patchBreadcrumb(mainBreadcrumb.id, {
|
||||
params: { ...this.snapshot.queryParams, ...(mainBreadcrumb.params ?? {}) },
|
||||
params: {
|
||||
...this.snapshot.queryParams,
|
||||
...(mainBreadcrumb.params ?? {}),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async getCreateCustomerBreadcrumb(): Promise<Breadcrumb | undefined> {
|
||||
const breadcrumbs = await this.getBreadcrumbs();
|
||||
return breadcrumbs.find((b) => b.tags.includes('create') && b.tags.includes('customer'));
|
||||
return breadcrumbs.find(
|
||||
(b) => b.tags.includes('create') && b.tags.includes('customer'),
|
||||
);
|
||||
}
|
||||
|
||||
async checkCreateCustomerBreadcrumb() {
|
||||
@@ -262,7 +322,9 @@ export class CustomerSearchComponent implements OnInit, OnDestroy {
|
||||
|
||||
async getSearchBreadcrumb(): Promise<Breadcrumb | undefined> {
|
||||
const breadcrumbs = await this.getBreadcrumbs();
|
||||
return breadcrumbs.find((b) => b.tags.includes('list') && b.tags.includes('search'));
|
||||
return breadcrumbs.find(
|
||||
(b) => b.tags.includes('list') && b.tags.includes('search'),
|
||||
);
|
||||
}
|
||||
|
||||
async checkSearchBreadcrumb() {
|
||||
@@ -288,7 +350,9 @@ export class CustomerSearchComponent implements OnInit, OnDestroy {
|
||||
const name = this._store.queryParams?.main_qs || 'Suche';
|
||||
|
||||
if (!searchBreadcrumb) {
|
||||
const navigation = this._navigation.listRoute({ processId: this._store.processId });
|
||||
const navigation = this._navigation.listRoute({
|
||||
processId: this._store.processId,
|
||||
});
|
||||
const breadcrumb: Breadcrumb = {
|
||||
key: this._store.processId,
|
||||
tags: ['customer', 'search', 'list'],
|
||||
@@ -300,7 +364,10 @@ export class CustomerSearchComponent implements OnInit, OnDestroy {
|
||||
|
||||
this._breadcrumbService.addBreadcrumb(breadcrumb);
|
||||
} else {
|
||||
this._breadcrumbService.patchBreadcrumb(searchBreadcrumb.id, { params: this.snapshot.queryParams, name });
|
||||
this._breadcrumbService.patchBreadcrumb(searchBreadcrumb.id, {
|
||||
params: this.snapshot.queryParams,
|
||||
name,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (searchBreadcrumb) {
|
||||
@@ -311,7 +378,9 @@ export class CustomerSearchComponent implements OnInit, OnDestroy {
|
||||
|
||||
async getDetailsBreadcrumb(): Promise<Breadcrumb | undefined> {
|
||||
const breadcrumbs = await this.getBreadcrumbs();
|
||||
return breadcrumbs.find((b) => b.tags.includes('details') && b.tags.includes('search'));
|
||||
return breadcrumbs.find(
|
||||
(b) => b.tags.includes('details') && b.tags.includes('search'),
|
||||
);
|
||||
}
|
||||
|
||||
async checkDetailsBreadcrumb() {
|
||||
@@ -333,7 +402,8 @@ export class CustomerSearchComponent implements OnInit, OnDestroy {
|
||||
].includes(this.breadcrumb)
|
||||
) {
|
||||
const customer = this._store.customer;
|
||||
const fullName = `${customer?.firstName ?? ''} ${customer?.lastName ?? ''}`.trim();
|
||||
const fullName =
|
||||
`${customer?.firstName ?? ''} ${customer?.lastName ?? ''}`.trim();
|
||||
|
||||
if (!detailsBreadcrumb) {
|
||||
const navigation = this._navigation.detailsRoute({
|
||||
@@ -515,7 +585,10 @@ export class CustomerSearchComponent implements OnInit, OnDestroy {
|
||||
async checkOrderDetailsBreadcrumb() {
|
||||
const orderDetailsBreadcrumb = await this.getOrderDetailsBreadcrumb();
|
||||
|
||||
if (this.breadcrumb === 'order-details' || this.breadcrumb === 'order-details-history') {
|
||||
if (
|
||||
this.breadcrumb === 'order-details' ||
|
||||
this.breadcrumb === 'order-details-history'
|
||||
) {
|
||||
if (!orderDetailsBreadcrumb) {
|
||||
const navigation = this._navigation.orderDetialsRoute({
|
||||
processId: this._store.processId,
|
||||
@@ -546,7 +619,8 @@ export class CustomerSearchComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
async checkOrderDetailsHistoryBreadcrumb() {
|
||||
const orderDetailsHistoryBreadcrumb = await this.getOrderDetailsHistoryBreadcrumb();
|
||||
const orderDetailsHistoryBreadcrumb =
|
||||
await this.getOrderDetailsHistoryBreadcrumb();
|
||||
|
||||
if (this.breadcrumb === 'order-details-history') {
|
||||
if (!orderDetailsHistoryBreadcrumb) {
|
||||
@@ -569,7 +643,9 @@ export class CustomerSearchComponent implements OnInit, OnDestroy {
|
||||
this._breadcrumbService.addBreadcrumb(breadcrumb);
|
||||
}
|
||||
} else if (orderDetailsHistoryBreadcrumb) {
|
||||
this._breadcrumbService.removeBreadcrumb(orderDetailsHistoryBreadcrumb.id);
|
||||
this._breadcrumbService.removeBreadcrumb(
|
||||
orderDetailsHistoryBreadcrumb.id,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Params, Router, RouterStateSnapshot } from '@angular/router';
|
||||
import {
|
||||
ActivatedRouteSnapshot,
|
||||
Params,
|
||||
Router,
|
||||
RouterStateSnapshot,
|
||||
} from '@angular/router';
|
||||
import { DomainCheckoutService } from '@domain/checkout';
|
||||
import { CustomerCreateFormData, decodeFormData } from '../create-customer';
|
||||
import { CustomerCreateNavigation } from '@shared/services/navigation';
|
||||
@@ -9,7 +14,10 @@ export class CustomerCreateGuard {
|
||||
private checkoutService = inject(DomainCheckoutService);
|
||||
private customerCreateNavigation = inject(CustomerCreateNavigation);
|
||||
|
||||
async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
|
||||
async canActivate(
|
||||
route: ActivatedRouteSnapshot,
|
||||
state: RouterStateSnapshot,
|
||||
): Promise<boolean> {
|
||||
// exit with true if canActivateChild will be called
|
||||
if (route.firstChild) {
|
||||
return true;
|
||||
@@ -19,10 +27,15 @@ export class CustomerCreateGuard {
|
||||
|
||||
const processId = this.getProcessId(route);
|
||||
const formData = this.getFormData(route);
|
||||
const canActivateCustomerType = await this.setableCustomerTypes(processId, formData);
|
||||
const canActivateCustomerType = await this.setableCustomerTypes(
|
||||
processId,
|
||||
formData,
|
||||
);
|
||||
|
||||
if (canActivateCustomerType[customerType] !== true) {
|
||||
customerType = Object.keys(canActivateCustomerType).find((key) => canActivateCustomerType[key]);
|
||||
customerType = Object.keys(canActivateCustomerType).find(
|
||||
(key) => canActivateCustomerType[key],
|
||||
);
|
||||
}
|
||||
|
||||
await this.navigate(processId, customerType, route.queryParams);
|
||||
@@ -30,9 +43,14 @@ export class CustomerCreateGuard {
|
||||
return true;
|
||||
}
|
||||
|
||||
async canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
|
||||
async canActivateChild(
|
||||
route: ActivatedRouteSnapshot,
|
||||
state: RouterStateSnapshot,
|
||||
): Promise<boolean> {
|
||||
const processId = this.getProcessId(route);
|
||||
const customerType = route.routeConfig.path?.replace('create/', '')?.replace('/update', '');
|
||||
const customerType = route.routeConfig.path
|
||||
?.replace('create/', '')
|
||||
?.replace('/update', '');
|
||||
|
||||
if (customerType === 'create-customer-main') {
|
||||
return true;
|
||||
@@ -40,29 +58,39 @@ export class CustomerCreateGuard {
|
||||
|
||||
const formData = this.getFormData(route);
|
||||
|
||||
const canActivateCustomerType = await this.setableCustomerTypes(processId, formData);
|
||||
const canActivateCustomerType = await this.setableCustomerTypes(
|
||||
processId,
|
||||
formData,
|
||||
);
|
||||
|
||||
if (canActivateCustomerType[customerType]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const activatableCustomerType = Object.keys(canActivateCustomerType)?.find((key) => canActivateCustomerType[key]);
|
||||
const activatableCustomerType = Object.keys(canActivateCustomerType)?.find(
|
||||
(key) => canActivateCustomerType[key],
|
||||
);
|
||||
|
||||
await this.navigate(processId, activatableCustomerType, route.queryParams);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async setableCustomerTypes(processId: number, formData: CustomerCreateFormData): Promise<Record<string, boolean>> {
|
||||
const res = await this.checkoutService.getSetableCustomerTypes(processId).toPromise();
|
||||
async setableCustomerTypes(
|
||||
processId: number,
|
||||
formData: CustomerCreateFormData,
|
||||
): Promise<Record<string, boolean>> {
|
||||
const res = await this.checkoutService
|
||||
.getSetableCustomerTypes(processId)
|
||||
.toPromise();
|
||||
|
||||
if (res.store) {
|
||||
res['store-p4m'] = true;
|
||||
}
|
||||
// if (res.store) {
|
||||
// res['store-p4m'] = true;
|
||||
// }
|
||||
|
||||
if (res.webshop) {
|
||||
res['webshop-p4m'] = true;
|
||||
}
|
||||
// if (res.webshop) {
|
||||
// res['webshop-p4m'] = true;
|
||||
// }
|
||||
|
||||
if (formData?._meta) {
|
||||
const customerType = formData._meta.customerType;
|
||||
@@ -107,7 +135,11 @@ export class CustomerCreateGuard {
|
||||
return {};
|
||||
}
|
||||
|
||||
navigate(processId: number, customerType: string, queryParams: Params): Promise<boolean> {
|
||||
navigate(
|
||||
processId: number,
|
||||
customerType: string,
|
||||
queryParams: Params,
|
||||
): Promise<boolean> {
|
||||
const path = this.customerCreateNavigation.createCustomerRoute({
|
||||
customerType,
|
||||
processId,
|
||||
|
||||
@@ -31,7 +31,9 @@ export class CantAddCustomerToCartModalComponent {
|
||||
get option() {
|
||||
return (
|
||||
this.ref.data.upgradeableTo?.options.values.find((upgradeOption) =>
|
||||
this.ref.data.required.options.values.some((requiredOption) => upgradeOption.key === requiredOption.key),
|
||||
this.ref.data.required.options.values.some(
|
||||
(requiredOption) => upgradeOption.key === requiredOption.key,
|
||||
),
|
||||
) || { value: this.queryParams }
|
||||
);
|
||||
}
|
||||
@@ -39,7 +41,9 @@ export class CantAddCustomerToCartModalComponent {
|
||||
get queryParams() {
|
||||
let option = this.ref.data.required?.options.values.find((f) => f.selected);
|
||||
if (!option) {
|
||||
option = this.ref.data.required?.options.values.find((f) => (isBoolean(f.enabled) ? f.enabled : true));
|
||||
option = this.ref.data.required?.options.values.find((f) =>
|
||||
isBoolean(f.enabled) ? f.enabled : true,
|
||||
);
|
||||
}
|
||||
return option ? { customertype: option.value } : {};
|
||||
}
|
||||
@@ -57,27 +61,29 @@ export class CantAddCustomerToCartModalComponent {
|
||||
const queryParams: Record<string, string> = {};
|
||||
|
||||
if (customer) {
|
||||
queryParams['formData'] = encodeFormData(mapCustomerDtoToCustomerCreateFormData(customer));
|
||||
queryParams['formData'] = encodeFormData(
|
||||
mapCustomerDtoToCustomerCreateFormData(customer),
|
||||
);
|
||||
}
|
||||
|
||||
if (option === 'webshop' && attributes.some((a) => a.key === 'p4mUser')) {
|
||||
const nav = this.customerCreateNavigation.createCustomerRoute({
|
||||
processId: this.applicationService.activatedProcessId,
|
||||
customerType: 'webshop-p4m',
|
||||
});
|
||||
this.router.navigate(nav.path, {
|
||||
queryParams: { ...nav.queryParams, ...queryParams },
|
||||
});
|
||||
} else {
|
||||
const nav = this.customerCreateNavigation.createCustomerRoute({
|
||||
processId: this.applicationService.activatedProcessId,
|
||||
customerType: option as any,
|
||||
});
|
||||
// if (option === 'webshop' && attributes.some((a) => a.key === 'p4mUser')) {
|
||||
// const nav = this.customerCreateNavigation.createCustomerRoute({
|
||||
// processId: this.applicationService.activatedProcessId,
|
||||
// customerType: 'webshop-p4m',
|
||||
// });
|
||||
// this.router.navigate(nav.path, {
|
||||
// queryParams: { ...nav.queryParams, ...queryParams },
|
||||
// });
|
||||
// } else {
|
||||
const nav = this.customerCreateNavigation.createCustomerRoute({
|
||||
processId: this.applicationService.activatedProcessId,
|
||||
customerType: option as any,
|
||||
});
|
||||
|
||||
this.router.navigate(nav.path, {
|
||||
queryParams: { ...nav.queryParams, ...queryParams },
|
||||
});
|
||||
}
|
||||
this.router.navigate(nav.path, {
|
||||
queryParams: { ...nav.queryParams, ...queryParams },
|
||||
});
|
||||
// }
|
||||
|
||||
this.ref.close();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
<div class="font-bold text-center border-t border-b border-solid border-disabled-customer -mx-4 py-4">
|
||||
<div
|
||||
class="font-bold text-center border-t border-b border-solid border-disabled-customer -mx-4 py-4"
|
||||
>
|
||||
{{ customer?.communicationDetails?.email }}
|
||||
</div>
|
||||
<div class="grid grid-flow-row gap-1 text-sm font-bold border-b border-solid border-disabled-customer -mx-4 py-4 px-14">
|
||||
<div
|
||||
class="grid grid-flow-row gap-1 text-sm font-bold border-b border-solid border-disabled-customer -mx-4 py-4 px-14"
|
||||
>
|
||||
@if (customer?.organisation?.name) {
|
||||
<span>{{ customer?.organisation?.name }}</span>
|
||||
}
|
||||
@@ -16,23 +20,26 @@
|
||||
</div>
|
||||
|
||||
<div class="grid grid-flow-col gap-4 justify-around mt-12">
|
||||
<button class="border-2 border-solid border-brand rounded-full font-bold text-brand px-6 py-3 text-lg" (click)="close(false)">
|
||||
<button
|
||||
class="border-2 border-solid border-brand rounded-full font-bold text-brand px-6 py-3 text-lg"
|
||||
(click)="close(false)"
|
||||
>
|
||||
neues Onlinekonto anlegen
|
||||
</button>
|
||||
@if (!isWebshopWithP4M) {
|
||||
<button
|
||||
class="border-2 border-solid border-brand rounded-full font-bold text-white px-6 py-3 text-lg bg-brand"
|
||||
(click)="close(true)"
|
||||
>
|
||||
>
|
||||
Daten übernehmen
|
||||
</button>
|
||||
}
|
||||
@if (isWebshopWithP4M) {
|
||||
<!-- @if (isWebshopWithP4M) {
|
||||
<button
|
||||
class="border-2 border-solid border-brand rounded-full font-bold text-white px-6 py-3 text-lg bg-brand"
|
||||
(click)="selectCustomer()"
|
||||
>
|
||||
Datensatz auswählen
|
||||
</button>
|
||||
}
|
||||
} -->
|
||||
</div>
|
||||
|
||||
@@ -9,11 +9,11 @@ import { CustomerCreateGuard } from './guards/customer-create.guard';
|
||||
import {
|
||||
CreateB2BCustomerComponent,
|
||||
CreateGuestCustomerComponent,
|
||||
CreateP4MCustomerComponent,
|
||||
// CreateP4MCustomerComponent,
|
||||
CreateStoreCustomerComponent,
|
||||
CreateWebshopCustomerComponent,
|
||||
} from './create-customer';
|
||||
import { UpdateP4MWebshopCustomerComponent } from './create-customer/update-p4m-webshop-customer';
|
||||
// import { UpdateP4MWebshopCustomerComponent } from './create-customer/update-p4m-webshop-customer';
|
||||
import { CreateCustomerComponent } from './create-customer/create-customer.component';
|
||||
import { CustomerDataEditB2BComponent } from './customer-search/edit-main-view/customer-data-edit-b2b.component';
|
||||
import { CustomerDataEditB2CComponent } from './customer-search/edit-main-view/customer-data-edit-b2c.component';
|
||||
@@ -40,8 +40,16 @@ export const routes: Routes = [
|
||||
path: '',
|
||||
component: CustomerSearchComponent,
|
||||
children: [
|
||||
{ path: 'search', component: CustomerMainViewComponent, data: { side: 'main', breadcrumb: 'main' } },
|
||||
{ path: 'search/list', component: CustomerResultsMainViewComponent, data: { breadcrumb: 'search' } },
|
||||
{
|
||||
path: 'search',
|
||||
component: CustomerMainViewComponent,
|
||||
data: { side: 'main', breadcrumb: 'main' },
|
||||
},
|
||||
{
|
||||
path: 'search/list',
|
||||
component: CustomerResultsMainViewComponent,
|
||||
data: { breadcrumb: 'search' },
|
||||
},
|
||||
{
|
||||
path: 'search/filter',
|
||||
component: CustomerFilterMainViewComponent,
|
||||
@@ -80,7 +88,10 @@ export const routes: Routes = [
|
||||
{
|
||||
path: 'search/:customerId/orders/:orderId/:orderItemId/history',
|
||||
component: CustomerOrderDetailsHistoryMainViewComponent,
|
||||
data: { side: 'order-details', breadcrumb: 'order-details-history' },
|
||||
data: {
|
||||
side: 'order-details',
|
||||
breadcrumb: 'order-details-history',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'search/:customerId/edit/b2b',
|
||||
@@ -140,13 +151,13 @@ export const routes: Routes = [
|
||||
{ path: 'create/webshop', component: CreateWebshopCustomerComponent },
|
||||
{ path: 'create/b2b', component: CreateB2BCustomerComponent },
|
||||
{ path: 'create/guest', component: CreateGuestCustomerComponent },
|
||||
{ path: 'create/webshop-p4m', component: CreateP4MCustomerComponent, data: { customerType: 'webshop' } },
|
||||
{ path: 'create/store-p4m', component: CreateP4MCustomerComponent, data: { customerType: 'store' } },
|
||||
{
|
||||
path: 'create/webshop-p4m/update',
|
||||
component: UpdateP4MWebshopCustomerComponent,
|
||||
data: { customerType: 'webshop' },
|
||||
},
|
||||
// { path: 'create/webshop-p4m', component: CreateP4MCustomerComponent, data: { customerType: 'webshop' } },
|
||||
// { path: 'create/store-p4m', component: CreateP4MCustomerComponent, data: { customerType: 'store' } },
|
||||
// {
|
||||
// path: 'create/webshop-p4m/update',
|
||||
// component: UpdateP4MWebshopCustomerComponent,
|
||||
// data: { customerType: 'webshop' },
|
||||
// },
|
||||
{
|
||||
path: 'create-customer-main',
|
||||
outlet: 'side',
|
||||
|
||||
@@ -16,13 +16,34 @@
|
||||
[deltaEnd]="150"
|
||||
[itemLength]="itemLength$ | async"
|
||||
[containerHeight]="24.5"
|
||||
>
|
||||
@for (bueryNumberGroup of items$ | async | groupBy: byBuyerNumberFn; track bueryNumberGroup) {
|
||||
>
|
||||
@for (
|
||||
bueryNumberGroup of items$ | async | groupBy: byBuyerNumberFn;
|
||||
track bueryNumberGroup
|
||||
) {
|
||||
<shared-goods-in-out-order-group>
|
||||
@for (orderNumberGroup of bueryNumberGroup.items | groupBy: byOrderNumberFn; track orderNumberGroup; let lastOrderNumber = $last) {
|
||||
@for (processingStatusGroup of orderNumberGroup.items | groupBy: byProcessingStatusFn; track processingStatusGroup; let lastProcessingStatus = $last) {
|
||||
@for (compartmentCodeGroup of processingStatusGroup.items | groupBy: byCompartmentCodeFn; track compartmentCodeGroup; let lastCompartmentCode = $last) {
|
||||
@for (item of compartmentCodeGroup.items; track item; let firstItem = $first) {
|
||||
@for (
|
||||
orderNumberGroup of bueryNumberGroup.items | groupBy: byOrderNumberFn;
|
||||
track orderNumberGroup;
|
||||
let lastOrderNumber = $last
|
||||
) {
|
||||
@for (
|
||||
processingStatusGroup of orderNumberGroup.items
|
||||
| groupBy: byProcessingStatusFn;
|
||||
track processingStatusGroup;
|
||||
let lastProcessingStatus = $last
|
||||
) {
|
||||
@for (
|
||||
compartmentCodeGroup of processingStatusGroup.items
|
||||
| groupBy: byCompartmentCodeFn;
|
||||
track compartmentCodeGroup;
|
||||
let lastCompartmentCode = $last
|
||||
) {
|
||||
@for (
|
||||
item of compartmentCodeGroup.items;
|
||||
track item;
|
||||
let firstItem = $first
|
||||
) {
|
||||
<shared-goods-in-out-order-group-item
|
||||
[item]="item"
|
||||
[showCompartmentCode]="firstItem"
|
||||
@@ -49,7 +70,6 @@
|
||||
<div class="empty-message">Es sind im Moment keine Artikel vorhanden</div>
|
||||
}
|
||||
|
||||
|
||||
<div class="actions">
|
||||
@if (actions$ | async; as actions) {
|
||||
@for (action of actions; track action) {
|
||||
@@ -57,19 +77,27 @@
|
||||
[disabled]="(changeActionLoader$ | async) || (loading$ | async)"
|
||||
class="cta-action cta-action-primary"
|
||||
(click)="handleAction(action)"
|
||||
>
|
||||
<ui-spinner
|
||||
[show]="(changeActionLoader$ | async) || (loading$ | async)"
|
||||
>{{ action.label }}</ui-spinner
|
||||
>
|
||||
<ui-spinner [show]="(changeActionLoader$ | async) || (loading$ | async)">{{ action.label }}</ui-spinner>
|
||||
</button>
|
||||
}
|
||||
}
|
||||
|
||||
@if (listEmpty$ | async) {
|
||||
<a class="cta-action cta-action-secondary" [routerLink]="['/filiale', 'goods', 'in']">
|
||||
<a
|
||||
class="cta-action cta-action-secondary"
|
||||
[routerLink]="['/filiale', 'goods', 'in']"
|
||||
>
|
||||
Zur Bestellpostensuche
|
||||
</a>
|
||||
}
|
||||
|
||||
@if (listEmpty$ | async) {
|
||||
<a class="cta-action cta-action-primary" [routerLink]="['/filiale', 'remission']">Zur Remission</a>
|
||||
<a class="cta-action cta-action-primary" [routerLink]="remissionPath()"
|
||||
>Zur Remission</a
|
||||
>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, ViewChild, inject } from '@angular/core';
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
OnDestroy,
|
||||
OnInit,
|
||||
ViewChild,
|
||||
inject,
|
||||
linkedSignal,
|
||||
} from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { BreadcrumbService } from '@core/breadcrumb';
|
||||
import { KeyValueDTOOfStringAndString, OrderItemListItemDTO } from '@generated/swagger/oms-api';
|
||||
import {
|
||||
KeyValueDTOOfStringAndString,
|
||||
OrderItemListItemDTO,
|
||||
} from '@generated/swagger/oms-api';
|
||||
import { UiErrorModalComponent, UiModalService } from '@ui/modal';
|
||||
import { UiScrollContainerComponent } from '@ui/scroll-container';
|
||||
import { BehaviorSubject, combineLatest, Subject } from 'rxjs';
|
||||
@@ -11,6 +22,7 @@ import { Config } from '@core/config';
|
||||
import { ToasterService } from '@shared/shell';
|
||||
import { PickupShelfInNavigationService } from '@shared/services/navigation';
|
||||
import { CacheService } from '@core/cache';
|
||||
import { TabService } from '@isa/core/tabs';
|
||||
|
||||
@Component({
|
||||
selector: 'page-goods-in-remission-preview',
|
||||
@@ -21,8 +33,12 @@ import { CacheService } from '@core/cache';
|
||||
standalone: false,
|
||||
})
|
||||
export class GoodsInRemissionPreviewComponent implements OnInit, OnDestroy {
|
||||
private _pickupShelfInNavigationService = inject(PickupShelfInNavigationService);
|
||||
@ViewChild(UiScrollContainerComponent) scrollContainer: UiScrollContainerComponent;
|
||||
tabService = inject(TabService);
|
||||
private _pickupShelfInNavigationService = inject(
|
||||
PickupShelfInNavigationService,
|
||||
);
|
||||
@ViewChild(UiScrollContainerComponent)
|
||||
scrollContainer: UiScrollContainerComponent;
|
||||
|
||||
items$ = this._store.results$;
|
||||
|
||||
@@ -50,10 +66,18 @@ export class GoodsInRemissionPreviewComponent implements OnInit, OnDestroy {
|
||||
byProcessingStatusFn = (item: OrderItemListItemDTO) => item.processingStatus;
|
||||
|
||||
byCompartmentCodeFn = (item: OrderItemListItemDTO) =>
|
||||
item.compartmentInfo ? `${item.compartmentCode}_${item.compartmentInfo}` : item.compartmentCode;
|
||||
item.compartmentInfo
|
||||
? `${item.compartmentCode}_${item.compartmentInfo}`
|
||||
: item.compartmentCode;
|
||||
|
||||
private readonly SCROLL_POSITION_TOKEN = 'REMISSION_PREVIEW_SCROLL_POSITION';
|
||||
|
||||
remissionPath = linkedSignal(() => [
|
||||
'/',
|
||||
this.tabService.activatedTab()?.id || this.tabService.nextId(),
|
||||
'remission',
|
||||
]);
|
||||
|
||||
constructor(
|
||||
private _breadcrumb: BreadcrumbService,
|
||||
private _store: GoodsInRemissionPreviewStore,
|
||||
@@ -78,12 +102,18 @@ export class GoodsInRemissionPreviewComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private _removeScrollPositionFromCache(): void {
|
||||
this._cache.delete({ processId: this._config.get('process.ids.goodsIn'), token: this.SCROLL_POSITION_TOKEN });
|
||||
this._cache.delete({
|
||||
processId: this._config.get('process.ids.goodsIn'),
|
||||
token: this.SCROLL_POSITION_TOKEN,
|
||||
});
|
||||
}
|
||||
|
||||
private _addScrollPositionToCache(): void {
|
||||
this._cache.set<number>(
|
||||
{ processId: this._config.get('process.ids.goodsIn'), token: this.SCROLL_POSITION_TOKEN },
|
||||
{
|
||||
processId: this._config.get('process.ids.goodsIn'),
|
||||
token: this.SCROLL_POSITION_TOKEN,
|
||||
},
|
||||
this.scrollContainer?.scrollPos,
|
||||
);
|
||||
}
|
||||
@@ -108,7 +138,10 @@ export class GoodsInRemissionPreviewComponent implements OnInit, OnDestroy {
|
||||
|
||||
async updateBreadcrumb() {
|
||||
const crumbs = await this._breadcrumb
|
||||
.getBreadcrumbsByKeyAndTags$(this._config.get('process.ids.goodsIn'), ['goods-in', 'preview'])
|
||||
.getBreadcrumbsByKeyAndTags$(this._config.get('process.ids.goodsIn'), [
|
||||
'goods-in',
|
||||
'preview',
|
||||
])
|
||||
.pipe(first())
|
||||
.toPromise();
|
||||
for (const crumb of crumbs) {
|
||||
@@ -120,12 +153,15 @@ export class GoodsInRemissionPreviewComponent implements OnInit, OnDestroy {
|
||||
|
||||
async removeBreadcrumbs() {
|
||||
let breadcrumbsToDelete = await this._breadcrumb
|
||||
.getBreadcrumbsByKeyAndTags$(this._config.get('process.ids.goodsIn'), ['goods-in'])
|
||||
.getBreadcrumbsByKeyAndTags$(this._config.get('process.ids.goodsIn'), [
|
||||
'goods-in',
|
||||
])
|
||||
.pipe(first())
|
||||
.toPromise();
|
||||
|
||||
breadcrumbsToDelete = breadcrumbsToDelete.filter(
|
||||
(crumb) => !crumb.tags.includes('preview') && !crumb.tags.includes('main'),
|
||||
(crumb) =>
|
||||
!crumb.tags.includes('preview') && !crumb.tags.includes('main'),
|
||||
);
|
||||
|
||||
breadcrumbsToDelete.forEach((crumb) => {
|
||||
@@ -133,11 +169,17 @@ export class GoodsInRemissionPreviewComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
|
||||
const detailsCrumbs = await this._breadcrumb
|
||||
.getBreadcrumbsByKeyAndTags$(this._config.get('process.ids.goodsIn'), ['goods-in', 'details'])
|
||||
.getBreadcrumbsByKeyAndTags$(this._config.get('process.ids.goodsIn'), [
|
||||
'goods-in',
|
||||
'details',
|
||||
])
|
||||
.pipe(first())
|
||||
.toPromise();
|
||||
const editCrumbs = await this._breadcrumb
|
||||
.getBreadcrumbsByKeyAndTags$(this._config.get('process.ids.goodsIn'), ['goods-in', 'edit'])
|
||||
.getBreadcrumbsByKeyAndTags$(this._config.get('process.ids.goodsIn'), [
|
||||
'goods-in',
|
||||
'edit',
|
||||
])
|
||||
.pipe(first())
|
||||
.toPromise();
|
||||
|
||||
@@ -152,32 +194,44 @@ export class GoodsInRemissionPreviewComponent implements OnInit, OnDestroy {
|
||||
|
||||
initInitialSearch() {
|
||||
if (this._store.hits === 0) {
|
||||
this._store.searchResult$.pipe(takeUntil(this._onDestroy$)).subscribe(async (result) => {
|
||||
await this.createBreadcrumb();
|
||||
this._store.searchResult$
|
||||
.pipe(takeUntil(this._onDestroy$))
|
||||
.subscribe(async (result) => {
|
||||
await this.createBreadcrumb();
|
||||
|
||||
this.scrollContainer?.scrollTo((await this._getScrollPositionFromCache()) ?? 0);
|
||||
this._removeScrollPositionFromCache();
|
||||
});
|
||||
this.scrollContainer?.scrollTo(
|
||||
(await this._getScrollPositionFromCache()) ?? 0,
|
||||
);
|
||||
this._removeScrollPositionFromCache();
|
||||
});
|
||||
}
|
||||
|
||||
this._store.search();
|
||||
}
|
||||
|
||||
async navigateToRemission() {
|
||||
await this._router.navigate(['/filiale/remission']);
|
||||
await this._router.navigate(this.remissionPath());
|
||||
}
|
||||
|
||||
navigateToDetails(orderItem: OrderItemListItemDTO) {
|
||||
const nav = this._pickupShelfInNavigationService.detailRoute({ item: orderItem, side: false });
|
||||
const nav = this._pickupShelfInNavigationService.detailRoute({
|
||||
item: orderItem,
|
||||
side: false,
|
||||
});
|
||||
|
||||
this._router.navigate(nav.path, { queryParams: { ...nav.queryParams, view: 'remission' } });
|
||||
this._router.navigate(nav.path, {
|
||||
queryParams: { ...nav.queryParams, view: 'remission' },
|
||||
});
|
||||
}
|
||||
|
||||
async handleAction(action: KeyValueDTOOfStringAndString) {
|
||||
this.changeActionLoader$.next(true);
|
||||
|
||||
try {
|
||||
const response = await this._store.createRemissionFromPreview().pipe(first()).toPromise();
|
||||
const response = await this._store
|
||||
.createRemissionFromPreview()
|
||||
.pipe(first())
|
||||
.toPromise();
|
||||
|
||||
if (!response?.dialog) {
|
||||
this._toast.open({
|
||||
|
||||
@@ -16,20 +16,20 @@ import {
|
||||
forwardRef,
|
||||
Optional,
|
||||
inject,
|
||||
} from '@angular/core';
|
||||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
||||
import { UiAutocompleteComponent } from '@ui/autocomplete';
|
||||
import { UiFormControlDirective } from '@ui/form-control';
|
||||
import { containsElement } from '@utils/common';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { ScanAdapterService } from '@adapter/scan';
|
||||
import { injectCancelSearch } from '@shared/services/cancel-subject';
|
||||
import { EnvironmentService } from '@core/environment';
|
||||
} from "@angular/core";
|
||||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from "@angular/forms";
|
||||
import { UiAutocompleteComponent } from "@ui/autocomplete";
|
||||
import { UiFormControlDirective } from "@ui/form-control";
|
||||
import { containsElement } from "@utils/common";
|
||||
import { Subscription } from "rxjs";
|
||||
import { ScanAdapterService } from "@adapter/scan";
|
||||
import { injectCancelSearch } from "@shared/services/cancel-subject";
|
||||
import { EnvironmentService } from "@core/environment";
|
||||
|
||||
@Component({
|
||||
selector: 'shared-searchbox',
|
||||
templateUrl: 'searchbox.component.html',
|
||||
styleUrls: ['searchbox.component.scss'],
|
||||
selector: "shared-searchbox",
|
||||
templateUrl: "searchbox.component.html",
|
||||
styleUrls: ["searchbox.component.scss"],
|
||||
providers: [
|
||||
{
|
||||
provide: NG_VALUE_ACCESSOR,
|
||||
@@ -49,9 +49,9 @@ export class SearchboxComponent
|
||||
cancelSearch = injectCancelSearch({ optional: true });
|
||||
|
||||
disabled: boolean;
|
||||
type = 'text';
|
||||
type = "text";
|
||||
|
||||
@ViewChild('input', { read: ElementRef, static: true })
|
||||
@ViewChild("input", { read: ElementRef, static: true })
|
||||
input: ElementRef;
|
||||
|
||||
@ContentChild(UiAutocompleteComponent)
|
||||
@@ -61,9 +61,9 @@ export class SearchboxComponent
|
||||
focusAfterViewInit = true;
|
||||
|
||||
@Input()
|
||||
placeholder = '';
|
||||
placeholder = "";
|
||||
|
||||
private _query = '';
|
||||
private _query = "";
|
||||
|
||||
@Input()
|
||||
get query() {
|
||||
@@ -94,7 +94,7 @@ export class SearchboxComponent
|
||||
scanner = false;
|
||||
|
||||
@Input()
|
||||
hint = '';
|
||||
hint = "";
|
||||
|
||||
@Input()
|
||||
autocompleteValueSelector: (item: any) => string = (item: any) => item;
|
||||
@@ -104,11 +104,11 @@ export class SearchboxComponent
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this.setQuery('');
|
||||
this.setQuery("");
|
||||
this.cancelSearch();
|
||||
}
|
||||
|
||||
@HostBinding('class.autocomplete-opend')
|
||||
@HostBinding("class.autocomplete-opend")
|
||||
get autocompleteOpen() {
|
||||
return this.autocomplete?.opend;
|
||||
}
|
||||
@@ -213,13 +213,13 @@ export class SearchboxComponent
|
||||
}
|
||||
|
||||
clearHint() {
|
||||
this.hint = '';
|
||||
this.hint = "";
|
||||
this.focused.emit(true);
|
||||
this.cdr.markForCheck();
|
||||
}
|
||||
|
||||
onKeyup(event: KeyboardEvent) {
|
||||
if (event.key === 'Enter') {
|
||||
if (event.key === "Enter") {
|
||||
if (this.autocomplete?.opend && this.autocomplete?.activeItem) {
|
||||
this.setQuery(this.autocomplete?.activeItem?.item);
|
||||
this.autocomplete?.close();
|
||||
@@ -227,7 +227,7 @@ export class SearchboxComponent
|
||||
this.search.emit(this.query);
|
||||
|
||||
event.preventDefault();
|
||||
} else if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
|
||||
} else if (event.key === "ArrowUp" || event.key === "ArrowDown") {
|
||||
this.handleArrowUpDownEvent(event);
|
||||
}
|
||||
}
|
||||
@@ -242,7 +242,7 @@ export class SearchboxComponent
|
||||
}
|
||||
}
|
||||
|
||||
@HostListener('window:click', ['$event'])
|
||||
@HostListener("window:click", ["$event"])
|
||||
focusLost(event: MouseEvent) {
|
||||
if (
|
||||
this.autocomplete?.opend &&
|
||||
@@ -256,9 +256,11 @@ export class SearchboxComponent
|
||||
this.search.emit(this.query);
|
||||
}
|
||||
|
||||
@HostListener('focusout', ['$event'])
|
||||
@HostListener("focusout", ["$event"])
|
||||
onBlur() {
|
||||
this.onTouched();
|
||||
if (typeof this.onTouched === "function") {
|
||||
this.onTouched();
|
||||
}
|
||||
this.focused.emit(false);
|
||||
this.cdr.markForCheck();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,10 @@ import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { CustomerInfoDTO } from '@generated/swagger/crm-api';
|
||||
import { NavigationRoute } from './defs/navigation-route';
|
||||
import { encodeFormData, mapCustomerInfoDtoToCustomerCreateFormData } from 'apps/isa-app/src/page/customer';
|
||||
import {
|
||||
encodeFormData,
|
||||
mapCustomerInfoDtoToCustomerCreateFormData,
|
||||
} from 'apps/isa-app/src/page/customer';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CustomerCreateNavigation {
|
||||
@@ -33,7 +36,9 @@ export class CustomerCreateNavigation {
|
||||
|
||||
navigateToDefault(params: { processId: NumberInput }): Promise<boolean> {
|
||||
const route = this.defaultRoute(params);
|
||||
return this._router.navigate(route.path, { queryParams: route.queryParams });
|
||||
return this._router.navigate(route.path, {
|
||||
queryParams: route.queryParams,
|
||||
});
|
||||
}
|
||||
|
||||
createCustomerRoute(params: {
|
||||
@@ -54,7 +59,9 @@ export class CustomerCreateNavigation {
|
||||
];
|
||||
|
||||
let formData = params?.customerInfo
|
||||
? encodeFormData(mapCustomerInfoDtoToCustomerCreateFormData(params.customerInfo))
|
||||
? encodeFormData(
|
||||
mapCustomerInfoDtoToCustomerCreateFormData(params.customerInfo),
|
||||
)
|
||||
: undefined;
|
||||
|
||||
const urlTree = this._router.createUrlTree(path, {
|
||||
@@ -79,7 +86,9 @@ export class CustomerCreateNavigation {
|
||||
processId: NumberInput;
|
||||
customerInfo: CustomerInfoDTO;
|
||||
}): NavigationRoute {
|
||||
const formData = encodeFormData(mapCustomerInfoDtoToCustomerCreateFormData(customerInfo));
|
||||
const formData = encodeFormData(
|
||||
mapCustomerInfoDtoToCustomerCreateFormData(customerInfo),
|
||||
);
|
||||
const path = [
|
||||
'/kunde',
|
||||
coerceNumberProperty(processId),
|
||||
@@ -88,14 +97,16 @@ export class CustomerCreateNavigation {
|
||||
outlets: {
|
||||
primary: [
|
||||
'create',
|
||||
customerInfo?.features?.find((feature) => feature.key === 'webshop') ? 'webshop-p4m' : 'store-p4m',
|
||||
// customerInfo?.features?.find((feature) => feature.key === 'webshop') ? 'webshop-p4m' : 'store-p4m',
|
||||
],
|
||||
side: 'create-customer-main',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const urlTree = this._router.createUrlTree(path, { queryParams: { formData } });
|
||||
const urlTree = this._router.createUrlTree(path, {
|
||||
queryParams: { formData },
|
||||
});
|
||||
|
||||
return {
|
||||
path,
|
||||
|
||||
@@ -254,20 +254,71 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (remissionNavigation$ | async; as remissionNavigation) {
|
||||
<div class="side-menu-group-sub-item-wrapper">
|
||||
<a
|
||||
class="side-menu-group-item"
|
||||
(click)="closeSideMenu()"
|
||||
[routerLink]="remissionNavigation.path"
|
||||
[queryParams]="remissionNavigation.queryParams"
|
||||
(click)="closeSideMenu(); focusSearchBox()"
|
||||
[routerLink]="[
|
||||
'/',
|
||||
processService.activatedTab()?.id || processService.nextId(),
|
||||
'remission',
|
||||
]"
|
||||
(isActiveChange)="focusSearchBox(); remissionExpanded.set($event)"
|
||||
routerLinkActive="active"
|
||||
#rlActive="routerLinkActive"
|
||||
>
|
||||
<span class="side-menu-group-item-icon">
|
||||
<shared-icon icon="assignment-return"></shared-icon>
|
||||
<span class="side-menu-group-item-icon w-[2.375rem] h-12">
|
||||
<ng-icon name="isaNavigationRemission2" size="1.5rem"></ng-icon>
|
||||
</span>
|
||||
<span class="side-menu-group-item-label">Remission</span>
|
||||
<button
|
||||
class="side-menu-group-arrow"
|
||||
[class.side-menu-item-rotate]="remissionExpanded()"
|
||||
(click)="
|
||||
$event.stopPropagation();
|
||||
$event.preventDefault();
|
||||
remissionExpanded.set(!remissionExpanded())
|
||||
"
|
||||
>
|
||||
<shared-icon icon="keyboard-arrow-down"></shared-icon>
|
||||
</button>
|
||||
</a>
|
||||
}
|
||||
@if (remissionExpanded()) {
|
||||
<div class="side-menu-group-sub-items">
|
||||
<a
|
||||
class="side-menu-group-item"
|
||||
(click)="closeSideMenu(); focusSearchBox()"
|
||||
[routerLink]="[
|
||||
'/',
|
||||
processService.activatedTab()?.id || processService.nextId(),
|
||||
'remission',
|
||||
]"
|
||||
(isActiveChange)="focusSearchBox()"
|
||||
sharedRegexRouterLinkActive="active"
|
||||
sharedRegexRouterLinkActiveTest="^\/\d*\/remission\/(mandatory|department)"
|
||||
>
|
||||
<span class="side-menu-group-item-icon"> </span>
|
||||
<span class="side-menu-group-item-label">Remission</span>
|
||||
</a>
|
||||
<a
|
||||
class="side-menu-group-item"
|
||||
(click)="closeSideMenu(); focusSearchBox()"
|
||||
[routerLink]="[
|
||||
'/',
|
||||
processService.activatedTab()?.id || processService.nextId(),
|
||||
'remission',
|
||||
'return-receipt',
|
||||
]"
|
||||
(isActiveChange)="focusSearchBox()"
|
||||
sharedRegexRouterLinkActive="active"
|
||||
sharedRegexRouterLinkActiveTest="^\/\d*\/remission\/return-receipt"
|
||||
>
|
||||
<span class="side-menu-group-item-icon"> </span>
|
||||
<span class="side-menu-group-item-label">Warenbegleitscheine</span>
|
||||
</a>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (packageInspectionNavigation$ | async; as packageInspectionNavigation) {
|
||||
<a
|
||||
@@ -283,37 +334,5 @@
|
||||
<span class="side-menu-group-item-label">Wareneingang</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
<a
|
||||
class="side-menu-group-item"
|
||||
(click)="closeSideMenu(); focusSearchBox()"
|
||||
[routerLink]="[
|
||||
'/',
|
||||
processService.activatedTab()?.id || processService.nextId(),
|
||||
'remission',
|
||||
]"
|
||||
(isActiveChange)="focusSearchBox()"
|
||||
>
|
||||
<span class="side-menu-group-item-icon w-[2.375rem] h-12">
|
||||
<ng-icon name="isaNavigationRemission2"></ng-icon>
|
||||
</span>
|
||||
<span class="side-menu-group-item-label">Remission</span>
|
||||
</a>
|
||||
<a
|
||||
class="side-menu-group-item"
|
||||
(click)="closeSideMenu(); focusSearchBox()"
|
||||
[routerLink]="[
|
||||
'/',
|
||||
processService.activatedTab()?.id || processService.nextId(),
|
||||
'remission',
|
||||
'return-receipt',
|
||||
]"
|
||||
(isActiveChange)="focusSearchBox()"
|
||||
>
|
||||
<span class="side-menu-group-item-icon w-[2.375rem] h-12">
|
||||
<ng-icon name="isaNavigationRemission2"></ng-icon>
|
||||
</span>
|
||||
<span class="side-menu-group-item-label">Warenbegleitscheine</span>
|
||||
</a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
@@ -1,435 +1,426 @@
|
||||
import {
|
||||
Component,
|
||||
ChangeDetectionStrategy,
|
||||
Inject,
|
||||
ChangeDetectorRef,
|
||||
inject,
|
||||
DOCUMENT,
|
||||
} from '@angular/core';
|
||||
import { AuthModule, AuthService } from '@core/auth';
|
||||
import { StockService } from '@generated/swagger/wws-api';
|
||||
import { first, map, retry, switchMap, take } from 'rxjs/operators';
|
||||
import { ShellService } from '../shell.service';
|
||||
import { ApplicationProcess, ApplicationService } from '@core/application';
|
||||
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
|
||||
import { EnvironmentService } from '@core/environment';
|
||||
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Config } from '@core/config';
|
||||
import { BreadcrumbService } from '@core/breadcrumb';
|
||||
import { IconComponent } from '@shared/components/icon';
|
||||
import { RegexRouterLinkActiveDirective } from '@shared/directives/router-link-active';
|
||||
import { WrongDestinationModalService } from '@modal/wrong-destination';
|
||||
import {
|
||||
CustomerCreateNavigation,
|
||||
CustomerOrdersNavigationService,
|
||||
CustomerSearchNavigation,
|
||||
PickupShelfInNavigationService,
|
||||
PickUpShelfOutNavigationService,
|
||||
ProductCatalogNavigationService,
|
||||
} from '@shared/services/navigation';
|
||||
|
||||
import { TabService } from '@isa/core/tabs';
|
||||
import { NgIconComponent, provideIcons } from '@ng-icons/core';
|
||||
import { isaNavigationRemission2, isaNavigationReturn } from '@isa/icons';
|
||||
|
||||
@Component({
|
||||
selector: 'shell-side-menu',
|
||||
templateUrl: 'side-menu.component.html',
|
||||
styleUrls: ['side-menu.component.css'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
imports: [
|
||||
CommonModule,
|
||||
NgIconComponent,
|
||||
IconComponent,
|
||||
RouterModule,
|
||||
AuthModule,
|
||||
RegexRouterLinkActiveDirective,
|
||||
],
|
||||
providers: [provideIcons({ isaNavigationReturn, isaNavigationRemission2 })],
|
||||
})
|
||||
export class ShellSideMenuComponent {
|
||||
processService = inject(TabService);
|
||||
|
||||
branchKey$ = this._stockService.StockCurrentBranch().pipe(
|
||||
retry(3),
|
||||
map((x) => x.result.key),
|
||||
);
|
||||
|
||||
section$ = this._app.getSection$();
|
||||
|
||||
processes$ = this.section$.pipe(
|
||||
switchMap((section) => this._app.getProcesses$(section)),
|
||||
);
|
||||
|
||||
processesCount$ = this.processes$.pipe(
|
||||
map((processes) => processes?.length ?? 0),
|
||||
);
|
||||
|
||||
activeProcess$ = this._app.activatedProcessId$.pipe(
|
||||
switchMap((processId) => this._app.getProcessById$(processId)),
|
||||
);
|
||||
|
||||
get isTablet() {
|
||||
return this._environment.matchTablet();
|
||||
}
|
||||
|
||||
customerBasePath$ = this.activeProcess$.pipe(
|
||||
map((process) => {
|
||||
if (
|
||||
!!process &&
|
||||
process.section === 'customer' &&
|
||||
process.type !== 'cart-checkout'
|
||||
) {
|
||||
// Übernehme aktiven Prozess
|
||||
return `/kunde/${process.id}`;
|
||||
} else {
|
||||
// Über Guards wird ein neuer Prozess erstellt
|
||||
return '/kunde';
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
customerSearchRoute$ = this.getLastActivatedCustomerProcessId$().pipe(
|
||||
map((processId) => {
|
||||
return this._customerSearchNavigation.defaultRoute({ processId });
|
||||
}),
|
||||
);
|
||||
|
||||
customerCreateRoute$ = this.getLastActivatedCustomerProcessId$().pipe(
|
||||
map((processId) => {
|
||||
return this._customerCreateNavigation.defaultRoute({ processId });
|
||||
}),
|
||||
);
|
||||
|
||||
pickUpShelfOutRoutePath$ = this.getLastActivatedCustomerProcessId$().pipe(
|
||||
map((processId) => {
|
||||
if (processId) {
|
||||
// Übernehme aktiven Prozess
|
||||
return this._pickUpShelfOutNavigation.defaultRoute({ processId }).path;
|
||||
} else {
|
||||
// Über Guards wird ein neuer Prozess erstellt
|
||||
return this._pickUpShelfOutNavigation.defaultRoute({}).path;
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
productRoutePath$ = this.getLastActivatedCustomerProcessId$().pipe(
|
||||
map((processId) => {
|
||||
if (processId) {
|
||||
// Übernehme aktiven Prozess
|
||||
return this._catalogNavigationService.getArticleSearchBasePath(
|
||||
processId,
|
||||
).path;
|
||||
} else {
|
||||
// Über Guards wird ein neuer Prozess erstellt
|
||||
return this._catalogNavigationService.getArticleSearchBasePath().path;
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
customerOrdersRoutePath$ = this.getLastActivatedCustomerProcessId$().pipe(
|
||||
map((processId) => {
|
||||
if (processId) {
|
||||
// Übernehme aktiven Prozess
|
||||
return this._customerOrdersNavigationService.getCustomerOrdersBasePath(
|
||||
processId,
|
||||
).path;
|
||||
} else {
|
||||
// Über Guards wird ein neuer Prozess erstellt
|
||||
return this._customerOrdersNavigationService.getCustomerOrdersBasePath()
|
||||
.path;
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
taskCalenderNavigation$ = this.getLastNavigationByProcessId(
|
||||
this._config.get('process.ids.taskCalendar'),
|
||||
{
|
||||
path: ['/filiale', 'task-calendar'],
|
||||
queryParams: {},
|
||||
},
|
||||
'/filiale/task-calendar',
|
||||
);
|
||||
|
||||
assortmentNavigation$ = this.getLastNavigationByProcessId(
|
||||
this._config.get('process.ids.assortment'),
|
||||
{
|
||||
path: ['/filiale', 'assortment'],
|
||||
queryParams: {},
|
||||
},
|
||||
);
|
||||
|
||||
pickUpShelfInRoutePath$ = this.getLastNavigationByProcessId(
|
||||
this._config.get('process.ids.pickupShelf'),
|
||||
this._pickUpShelfInNavigation.defaultRoute(),
|
||||
'/filiale/pickup-shelf',
|
||||
);
|
||||
|
||||
// #4478 - RD // Abholfach - Routing löst Suche aus
|
||||
// pickUpShelfInListRoutePath$ = this.getLastNavigationByProcessId(
|
||||
// this._config.get('process.ids.pickupShelf'),
|
||||
// this._pickUpShelfInNavigation.listRoute()
|
||||
// );
|
||||
|
||||
remissionNavigation$ = this.getLastNavigationByProcessId(
|
||||
this._config.get('process.ids.remission'),
|
||||
{
|
||||
path: ['/filiale', 'remission'],
|
||||
queryParams: {},
|
||||
},
|
||||
);
|
||||
|
||||
packageInspectionNavigation$ = this.getLastNavigationByProcessId(
|
||||
this._config.get('process.ids.packageInspection'),
|
||||
{
|
||||
path: ['/filiale', 'package-inspection'],
|
||||
queryParams: {},
|
||||
},
|
||||
);
|
||||
|
||||
get currentShelfView$() {
|
||||
return this._route.queryParams.pipe(map((params) => params.view));
|
||||
}
|
||||
|
||||
shelfExpanded = false;
|
||||
customerExpanded = false;
|
||||
|
||||
constructor(
|
||||
private _shellService: ShellService,
|
||||
private _authService: AuthService,
|
||||
private _stockService: StockService,
|
||||
private _app: ApplicationService,
|
||||
private _router: Router,
|
||||
private _route: ActivatedRoute,
|
||||
private readonly _wrongDestinationModalService: WrongDestinationModalService,
|
||||
private _environment: EnvironmentService,
|
||||
private _catalogNavigationService: ProductCatalogNavigationService,
|
||||
private _customerOrdersNavigationService: CustomerOrdersNavigationService,
|
||||
private _config: Config,
|
||||
private _breadcrumbService: BreadcrumbService,
|
||||
private _customerSearchNavigation: CustomerSearchNavigation,
|
||||
private _customerCreateNavigation: CustomerCreateNavigation,
|
||||
private _pickUpShelfOutNavigation: PickUpShelfOutNavigationService,
|
||||
private _pickUpShelfInNavigation: PickupShelfInNavigationService,
|
||||
private _cdr: ChangeDetectorRef,
|
||||
@Inject(DOCUMENT) private readonly _document: Document,
|
||||
) {}
|
||||
|
||||
customerActive(isActive: boolean) {
|
||||
if (isActive) {
|
||||
this.expandCustomer();
|
||||
}
|
||||
}
|
||||
|
||||
shelfActive(isActive: boolean) {
|
||||
if (isActive) {
|
||||
this.expandShelf();
|
||||
}
|
||||
}
|
||||
|
||||
expandCustomer() {
|
||||
this.customerExpanded = true;
|
||||
this._cdr.markForCheck();
|
||||
}
|
||||
|
||||
expandShelf() {
|
||||
this.shelfExpanded = true;
|
||||
this._cdr.markForCheck();
|
||||
}
|
||||
|
||||
getLastNavigationByProcessId(
|
||||
id: number,
|
||||
fallback?: { path: string[]; queryParams: unknown },
|
||||
pathContainsString?: string,
|
||||
) {
|
||||
return this._breadcrumbService.getBreadcrumbByKey$(id)?.pipe(
|
||||
map((breadcrumbs) => {
|
||||
const lastCrumb = breadcrumbs
|
||||
.filter((breadcrumb) => {
|
||||
/**
|
||||
* #4532 - Der optionale Filter wurde hinzugefügt Breadcrumbs mit fehlerhaften Pfad auszuschließen.
|
||||
* Dieser Filter kann entfernt werden, sobald die Breadcrumbs korrekt gesetzt werden. Jedoch konnte man bisher nicht feststellen,
|
||||
* woher die fehlerhaften Breadcrumbs kommen.
|
||||
*/
|
||||
if (!pathContainsString) {
|
||||
// Wenn kein Filter gesetzt ist, dann wird der letzte Breadcrumb zurückgegeben
|
||||
return true;
|
||||
}
|
||||
|
||||
const pathStr = Array.isArray(breadcrumb.path)
|
||||
? breadcrumb.path.join('/')
|
||||
: breadcrumb.path;
|
||||
return pathStr.includes(pathContainsString);
|
||||
})
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
.filter((breadcrumb) => !breadcrumb?.params?.hasOwnProperty('view'))
|
||||
.filter((breadcrumb) => !breadcrumb?.tags?.includes('reservation'))
|
||||
.filter((breadcrumb) => !breadcrumb?.tags?.includes('cleanup'))
|
||||
.filter(
|
||||
(breadcrumb) => !breadcrumb?.tags?.includes('wareneingangsliste'),
|
||||
)
|
||||
.filter((breadcrumb) => !breadcrumb?.tags?.includes('preview'))
|
||||
.reduce((last, current) => {
|
||||
if (!last) return current;
|
||||
|
||||
if (last.changed > current.changed) {
|
||||
return last;
|
||||
} else {
|
||||
return current;
|
||||
}
|
||||
}, undefined);
|
||||
|
||||
if (!lastCrumb) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
// #4692 Return Fallback if Values contain undefined or null values, regardless if path is from type string or array
|
||||
if (typeof lastCrumb?.path === 'string') {
|
||||
if (
|
||||
lastCrumb?.path?.includes('undefined') ||
|
||||
lastCrumb?.path?.includes('null')
|
||||
) {
|
||||
return fallback;
|
||||
}
|
||||
} else {
|
||||
const valuesToCheck = [];
|
||||
|
||||
// eslint-disable-next-line no-unsafe-optional-chaining
|
||||
for (const value of lastCrumb?.path) {
|
||||
if (
|
||||
value?.outlets &&
|
||||
value?.outlets?.primary &&
|
||||
value?.outlets?.side
|
||||
) {
|
||||
valuesToCheck.push(
|
||||
...Object.values(value?.outlets?.primary),
|
||||
...Object.values(value?.outlets?.side),
|
||||
);
|
||||
} else {
|
||||
valuesToCheck.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.checkIfArrayContainsUndefinedOrNull(valuesToCheck)) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
return { path: lastCrumb.path, queryParams: lastCrumb.params };
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
checkIfArrayContainsUndefinedOrNull(array: unknown[]) {
|
||||
return (
|
||||
array?.includes(undefined) ||
|
||||
array?.includes('undefined') ||
|
||||
array?.includes(null) ||
|
||||
array?.includes('null')
|
||||
);
|
||||
}
|
||||
|
||||
getLastActivatedCustomerProcessId$() {
|
||||
return this._app.getProcesses$('customer').pipe(
|
||||
map((processes) => {
|
||||
const lastCustomerProcess = processes
|
||||
.filter((process) => process.type === 'cart')
|
||||
.reduce((last, current) => {
|
||||
if (!last) return current;
|
||||
|
||||
if (last.activated > current.activated) {
|
||||
return last;
|
||||
} else {
|
||||
return current;
|
||||
}
|
||||
}, undefined);
|
||||
|
||||
return lastCustomerProcess?.id ?? Date.now();
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
closeSideMenu() {
|
||||
this._shellService.closeSideMenu();
|
||||
}
|
||||
|
||||
logout() {
|
||||
this._authService.logout();
|
||||
}
|
||||
|
||||
async resetBranch() {
|
||||
const process = await this.activeProcess$.pipe(first()).toPromise();
|
||||
if (process?.id) {
|
||||
this._app.patchProcessData(process.id, { selectedBranch: undefined });
|
||||
}
|
||||
}
|
||||
|
||||
focusSearchBox() {
|
||||
setTimeout(() => this._document.getElementById('searchbox')?.focus(), 0);
|
||||
}
|
||||
|
||||
async createProcess() {
|
||||
const process = await this.createCartProcess();
|
||||
this.navigateToCatalog(process);
|
||||
}
|
||||
|
||||
async createCartProcess() {
|
||||
const nextProcessName = await this.getNextProcessName();
|
||||
|
||||
const process: ApplicationProcess = {
|
||||
id: this.getNextProcessId(),
|
||||
type: 'cart',
|
||||
name: nextProcessName,
|
||||
section: 'customer',
|
||||
closeable: true,
|
||||
};
|
||||
|
||||
this._app.createProcess(process);
|
||||
|
||||
return process;
|
||||
}
|
||||
|
||||
async getNextProcessName() {
|
||||
let processes = await this._app
|
||||
.getProcesses$('customer')
|
||||
.pipe(first())
|
||||
.toPromise();
|
||||
|
||||
processes = processes.filter(
|
||||
(x) => x.type === 'cart' && x.name.startsWith('Vorgang '),
|
||||
);
|
||||
|
||||
const maxProcessNumber = processes.reduce((max, process) => {
|
||||
const number = parseInt(process.name.replace('Vorgang ', ''), 10);
|
||||
return number > max ? number : max;
|
||||
}, 0);
|
||||
|
||||
return `Vorgang ${maxProcessNumber + 1}`;
|
||||
}
|
||||
|
||||
getNextProcessId() {
|
||||
return Date.now();
|
||||
}
|
||||
|
||||
async navigateToCatalog(process: ApplicationProcess) {
|
||||
await this._catalogNavigationService
|
||||
.getArticleSearchBasePath(process.id)
|
||||
.navigate();
|
||||
}
|
||||
|
||||
navigateToDashboard() {
|
||||
this._router.navigate(['/kunde', 'dashboard']);
|
||||
}
|
||||
|
||||
async closeAllProcesses() {
|
||||
const processes = await this.processes$.pipe(take(1)).toPromise();
|
||||
|
||||
processes.forEach((process) => this._app.removeProcess(process.id));
|
||||
|
||||
this.navigateToDashboard();
|
||||
}
|
||||
|
||||
fetchAndOpenPackages = () =>
|
||||
this._wrongDestinationModalService.fetchAndOpen();
|
||||
}
|
||||
import {
|
||||
Component,
|
||||
ChangeDetectionStrategy,
|
||||
Inject,
|
||||
ChangeDetectorRef,
|
||||
inject,
|
||||
DOCUMENT,
|
||||
signal,
|
||||
} from '@angular/core';
|
||||
import { AuthModule, AuthService } from '@core/auth';
|
||||
import { StockService } from '@generated/swagger/wws-api';
|
||||
import { first, map, retry, switchMap, take } from 'rxjs/operators';
|
||||
import { ShellService } from '../shell.service';
|
||||
import { ApplicationProcess, ApplicationService } from '@core/application';
|
||||
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
|
||||
import { EnvironmentService } from '@core/environment';
|
||||
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Config } from '@core/config';
|
||||
import { BreadcrumbService } from '@core/breadcrumb';
|
||||
import { IconComponent } from '@shared/components/icon';
|
||||
import { RegexRouterLinkActiveDirective } from '@shared/directives/router-link-active';
|
||||
import { WrongDestinationModalService } from '@modal/wrong-destination';
|
||||
import {
|
||||
CustomerCreateNavigation,
|
||||
CustomerOrdersNavigationService,
|
||||
CustomerSearchNavigation,
|
||||
PickupShelfInNavigationService,
|
||||
PickUpShelfOutNavigationService,
|
||||
ProductCatalogNavigationService,
|
||||
} from '@shared/services/navigation';
|
||||
|
||||
import { TabService } from '@isa/core/tabs';
|
||||
import { NgIconComponent, provideIcons } from '@ng-icons/core';
|
||||
import { isaNavigationRemission2, isaNavigationReturn } from '@isa/icons';
|
||||
|
||||
@Component({
|
||||
selector: 'shell-side-menu',
|
||||
templateUrl: 'side-menu.component.html',
|
||||
styleUrls: ['side-menu.component.css'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
imports: [
|
||||
CommonModule,
|
||||
NgIconComponent,
|
||||
IconComponent,
|
||||
RouterModule,
|
||||
AuthModule,
|
||||
RegexRouterLinkActiveDirective,
|
||||
],
|
||||
providers: [provideIcons({ isaNavigationReturn, isaNavigationRemission2 })],
|
||||
})
|
||||
export class ShellSideMenuComponent {
|
||||
#shellService = inject(ShellService);
|
||||
#authService = inject(AuthService);
|
||||
#stockService = inject(StockService);
|
||||
#app = inject(ApplicationService);
|
||||
#router = inject(Router);
|
||||
#route = inject(ActivatedRoute);
|
||||
#wrongDestinationModalService = inject(WrongDestinationModalService);
|
||||
#environment = inject(EnvironmentService);
|
||||
#catalogNavigationService = inject(ProductCatalogNavigationService);
|
||||
#customerOrdersNavigationService = inject(CustomerOrdersNavigationService);
|
||||
#config = inject(Config);
|
||||
#breadcrumbService = inject(BreadcrumbService);
|
||||
#customerSearchNavigation = inject(CustomerSearchNavigation);
|
||||
#customerCreateNavigation = inject(CustomerCreateNavigation);
|
||||
#pickUpShelfOutNavigation = inject(PickUpShelfOutNavigationService);
|
||||
#pickUpShelfInNavigation = inject(PickupShelfInNavigationService);
|
||||
#cdr = inject(ChangeDetectorRef);
|
||||
#document = inject(DOCUMENT);
|
||||
processService = inject(TabService);
|
||||
|
||||
branchKey$ = this.#stockService.StockCurrentBranch().pipe(
|
||||
retry(3),
|
||||
map((x) => x.result.key),
|
||||
);
|
||||
|
||||
section$ = this.#app.getSection$();
|
||||
|
||||
processes$ = this.section$.pipe(
|
||||
switchMap((section) => this.#app.getProcesses$(section)),
|
||||
);
|
||||
|
||||
processesCount$ = this.processes$.pipe(
|
||||
map((processes) => processes?.length ?? 0),
|
||||
);
|
||||
|
||||
activeProcess$ = this.#app.activatedProcessId$.pipe(
|
||||
switchMap((processId) => this.#app.getProcessById$(processId)),
|
||||
);
|
||||
|
||||
get isTablet() {
|
||||
return this.#environment.matchTablet();
|
||||
}
|
||||
|
||||
customerBasePath$ = this.activeProcess$.pipe(
|
||||
map((process) => {
|
||||
if (
|
||||
!!process &&
|
||||
process.section === 'customer' &&
|
||||
process.type !== 'cart-checkout'
|
||||
) {
|
||||
// Übernehme aktiven Prozess
|
||||
return `/kunde/${process.id}`;
|
||||
} else {
|
||||
// Über Guards wird ein neuer Prozess erstellt
|
||||
return '/kunde';
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
customerSearchRoute$ = this.getLastActivatedCustomerProcessId$().pipe(
|
||||
map((processId) => {
|
||||
return this.#customerSearchNavigation.defaultRoute({ processId });
|
||||
}),
|
||||
);
|
||||
|
||||
customerCreateRoute$ = this.getLastActivatedCustomerProcessId$().pipe(
|
||||
map((processId) => {
|
||||
return this.#customerCreateNavigation.defaultRoute({ processId });
|
||||
}),
|
||||
);
|
||||
|
||||
pickUpShelfOutRoutePath$ = this.getLastActivatedCustomerProcessId$().pipe(
|
||||
map((processId) => {
|
||||
if (processId) {
|
||||
// Übernehme aktiven Prozess
|
||||
return this.#pickUpShelfOutNavigation.defaultRoute({ processId }).path;
|
||||
} else {
|
||||
// Über Guards wird ein neuer Prozess erstellt
|
||||
return this.#pickUpShelfOutNavigation.defaultRoute({}).path;
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
productRoutePath$ = this.getLastActivatedCustomerProcessId$().pipe(
|
||||
map((processId) => {
|
||||
if (processId) {
|
||||
// Übernehme aktiven Prozess
|
||||
return this.#catalogNavigationService.getArticleSearchBasePath(
|
||||
processId,
|
||||
).path;
|
||||
} else {
|
||||
// Über Guards wird ein neuer Prozess erstellt
|
||||
return this.#catalogNavigationService.getArticleSearchBasePath().path;
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
customerOrdersRoutePath$ = this.getLastActivatedCustomerProcessId$().pipe(
|
||||
map((processId) => {
|
||||
if (processId) {
|
||||
// Übernehme aktiven Prozess
|
||||
return this.#customerOrdersNavigationService.getCustomerOrdersBasePath(
|
||||
processId,
|
||||
).path;
|
||||
} else {
|
||||
// Über Guards wird ein neuer Prozess erstellt
|
||||
return this.#customerOrdersNavigationService.getCustomerOrdersBasePath()
|
||||
.path;
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
taskCalenderNavigation$ = this.getLastNavigationByProcessId(
|
||||
this.#config.get('process.ids.taskCalendar'),
|
||||
{
|
||||
path: ['/filiale', 'task-calendar'],
|
||||
queryParams: {},
|
||||
},
|
||||
'/filiale/task-calendar',
|
||||
);
|
||||
|
||||
assortmentNavigation$ = this.getLastNavigationByProcessId(
|
||||
this.#config.get('process.ids.assortment'),
|
||||
{
|
||||
path: ['/filiale', 'assortment'],
|
||||
queryParams: {},
|
||||
},
|
||||
);
|
||||
|
||||
pickUpShelfInRoutePath$ = this.getLastNavigationByProcessId(
|
||||
this.#config.get('process.ids.pickupShelf'),
|
||||
this.#pickUpShelfInNavigation.defaultRoute(),
|
||||
'/filiale/pickup-shelf',
|
||||
);
|
||||
|
||||
// #4478 - RD // Abholfach - Routing löst Suche aus
|
||||
// pickUpShelfInListRoutePath$ = this.getLastNavigationByProcessId(
|
||||
// this._config.get('process.ids.pickupShelf'),
|
||||
// this._pickUpShelfInNavigation.listRoute()
|
||||
// );
|
||||
|
||||
packageInspectionNavigation$ = this.getLastNavigationByProcessId(
|
||||
this.#config.get('process.ids.packageInspection'),
|
||||
{
|
||||
path: ['/filiale', 'package-inspection'],
|
||||
queryParams: {},
|
||||
},
|
||||
);
|
||||
|
||||
get currentShelfView$() {
|
||||
return this.#route.queryParams.pipe(map((params) => params.view));
|
||||
}
|
||||
|
||||
shelfExpanded = false;
|
||||
customerExpanded = false;
|
||||
remissionExpanded = signal(false);
|
||||
|
||||
customerActive(isActive: boolean) {
|
||||
if (isActive) {
|
||||
this.expandCustomer();
|
||||
}
|
||||
}
|
||||
|
||||
shelfActive(isActive: boolean) {
|
||||
if (isActive) {
|
||||
this.expandShelf();
|
||||
}
|
||||
}
|
||||
|
||||
expandCustomer() {
|
||||
this.customerExpanded = true;
|
||||
this.#cdr.markForCheck();
|
||||
}
|
||||
|
||||
expandShelf() {
|
||||
this.shelfExpanded = true;
|
||||
this.#cdr.markForCheck();
|
||||
}
|
||||
|
||||
getLastNavigationByProcessId(
|
||||
id: number,
|
||||
fallback?: { path: string[]; queryParams: unknown },
|
||||
pathContainsString?: string,
|
||||
) {
|
||||
return this.#breadcrumbService.getBreadcrumbByKey$(id)?.pipe(
|
||||
map((breadcrumbs) => {
|
||||
const lastCrumb = breadcrumbs
|
||||
.filter((breadcrumb) => {
|
||||
/**
|
||||
* #4532 - Der optionale Filter wurde hinzugefügt Breadcrumbs mit fehlerhaften Pfad auszuschließen.
|
||||
* Dieser Filter kann entfernt werden, sobald die Breadcrumbs korrekt gesetzt werden. Jedoch konnte man bisher nicht feststellen,
|
||||
* woher die fehlerhaften Breadcrumbs kommen.
|
||||
*/
|
||||
if (!pathContainsString) {
|
||||
// Wenn kein Filter gesetzt ist, dann wird der letzte Breadcrumb zurückgegeben
|
||||
return true;
|
||||
}
|
||||
|
||||
const pathStr = Array.isArray(breadcrumb.path)
|
||||
? breadcrumb.path.join('/')
|
||||
: breadcrumb.path;
|
||||
return pathStr.includes(pathContainsString);
|
||||
})
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
.filter((breadcrumb) => !breadcrumb?.params?.hasOwnProperty('view'))
|
||||
.filter((breadcrumb) => !breadcrumb?.tags?.includes('reservation'))
|
||||
.filter((breadcrumb) => !breadcrumb?.tags?.includes('cleanup'))
|
||||
.filter(
|
||||
(breadcrumb) => !breadcrumb?.tags?.includes('wareneingangsliste'),
|
||||
)
|
||||
.filter((breadcrumb) => !breadcrumb?.tags?.includes('preview'))
|
||||
.reduce((last, current) => {
|
||||
if (!last) return current;
|
||||
|
||||
if (last.changed > current.changed) {
|
||||
return last;
|
||||
} else {
|
||||
return current;
|
||||
}
|
||||
}, undefined);
|
||||
|
||||
if (!lastCrumb) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
// #4692 Return Fallback if Values contain undefined or null values, regardless if path is from type string or array
|
||||
if (typeof lastCrumb?.path === 'string') {
|
||||
if (
|
||||
lastCrumb?.path?.includes('undefined') ||
|
||||
lastCrumb?.path?.includes('null')
|
||||
) {
|
||||
return fallback;
|
||||
}
|
||||
} else {
|
||||
const valuesToCheck = [];
|
||||
|
||||
// eslint-disable-next-line no-unsafe-optional-chaining
|
||||
for (const value of lastCrumb?.path) {
|
||||
if (
|
||||
value?.outlets &&
|
||||
value?.outlets?.primary &&
|
||||
value?.outlets?.side
|
||||
) {
|
||||
valuesToCheck.push(
|
||||
...Object.values(value?.outlets?.primary),
|
||||
...Object.values(value?.outlets?.side),
|
||||
);
|
||||
} else {
|
||||
valuesToCheck.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.checkIfArrayContainsUndefinedOrNull(valuesToCheck)) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
return { path: lastCrumb.path, queryParams: lastCrumb.params };
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
checkIfArrayContainsUndefinedOrNull(array: unknown[]) {
|
||||
return (
|
||||
array?.includes(undefined) ||
|
||||
array?.includes('undefined') ||
|
||||
array?.includes(null) ||
|
||||
array?.includes('null')
|
||||
);
|
||||
}
|
||||
|
||||
getLastActivatedCustomerProcessId$() {
|
||||
return this.#app.getProcesses$('customer').pipe(
|
||||
map((processes) => {
|
||||
const lastCustomerProcess = processes
|
||||
.filter((process) => process.type === 'cart')
|
||||
.reduce((last, current) => {
|
||||
if (!last) return current;
|
||||
|
||||
if (last.activated > current.activated) {
|
||||
return last;
|
||||
} else {
|
||||
return current;
|
||||
}
|
||||
}, undefined);
|
||||
|
||||
return lastCustomerProcess?.id ?? Date.now();
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
closeSideMenu() {
|
||||
this.#shellService.closeSideMenu();
|
||||
}
|
||||
|
||||
logout() {
|
||||
this.#authService.logout();
|
||||
}
|
||||
|
||||
async resetBranch() {
|
||||
const process = await this.activeProcess$.pipe(first()).toPromise();
|
||||
if (process?.id) {
|
||||
this.#app.patchProcessData(process.id, { selectedBranch: undefined });
|
||||
}
|
||||
}
|
||||
|
||||
focusSearchBox() {
|
||||
setTimeout(() => this.#document.getElementById('searchbox')?.focus(), 0);
|
||||
}
|
||||
|
||||
async createProcess() {
|
||||
const process = await this.createCartProcess();
|
||||
this.navigateToCatalog(process);
|
||||
}
|
||||
|
||||
async createCartProcess() {
|
||||
const nextProcessName = await this.getNextProcessName();
|
||||
|
||||
const process: ApplicationProcess = {
|
||||
id: this.getNextProcessId(),
|
||||
type: 'cart',
|
||||
name: nextProcessName,
|
||||
section: 'customer',
|
||||
closeable: true,
|
||||
};
|
||||
|
||||
this.#app.createProcess(process);
|
||||
|
||||
return process;
|
||||
}
|
||||
|
||||
async getNextProcessName() {
|
||||
let processes = await this.#app
|
||||
.getProcesses$('customer')
|
||||
.pipe(first())
|
||||
.toPromise();
|
||||
|
||||
processes = processes.filter(
|
||||
(x) => x.type === 'cart' && x.name.startsWith('Vorgang '),
|
||||
);
|
||||
|
||||
const maxProcessNumber = processes.reduce((max, process) => {
|
||||
const number = parseInt(process.name.replace('Vorgang ', ''), 10);
|
||||
return number > max ? number : max;
|
||||
}, 0);
|
||||
|
||||
return `Vorgang ${maxProcessNumber + 1}`;
|
||||
}
|
||||
|
||||
getNextProcessId() {
|
||||
return Date.now();
|
||||
}
|
||||
|
||||
async navigateToCatalog(process: ApplicationProcess) {
|
||||
await this.#catalogNavigationService
|
||||
.getArticleSearchBasePath(process.id)
|
||||
.navigate();
|
||||
}
|
||||
|
||||
navigateToDashboard() {
|
||||
this.#router.navigate(['/kunde', 'dashboard']);
|
||||
}
|
||||
|
||||
async closeAllProcesses() {
|
||||
const processes = await this.processes$.pipe(take(1)).toPromise();
|
||||
|
||||
processes.forEach((process) => this.#app.removeProcess(process.id));
|
||||
|
||||
this.navigateToDashboard();
|
||||
}
|
||||
|
||||
fetchAndOpenPackages = () =>
|
||||
this.#wrongDestinationModalService.fetchAndOpen();
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
@import "../../../libs/ui/search-bar/src/search-bar.scss";
|
||||
@import "../../../libs/ui/skeleton-loader/src/skeleton-loader.scss";
|
||||
@import "../../../libs/ui/tooltip/src/tooltip.scss";
|
||||
@import "../../../libs/ui/label/src/label.scss";
|
||||
|
||||
.input-control {
|
||||
@apply rounded border border-solid border-[#AEB7C1] px-4 py-[1.125rem] outline-none;
|
||||
|
||||
@@ -16,20 +16,20 @@ import {
|
||||
forwardRef,
|
||||
Optional,
|
||||
inject,
|
||||
} from '@angular/core';
|
||||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
||||
import { UiAutocompleteComponent } from '@ui/autocomplete';
|
||||
import { UiFormControlDirective } from '@ui/form-control';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { ScanAdapterService } from '@adapter/scan';
|
||||
import { injectCancelSearch } from '@shared/services/cancel-subject';
|
||||
import { containsElement } from '@utils/common';
|
||||
import { EnvironmentService } from '@core/environment';
|
||||
} from "@angular/core";
|
||||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from "@angular/forms";
|
||||
import { UiAutocompleteComponent } from "@ui/autocomplete";
|
||||
import { UiFormControlDirective } from "@ui/form-control";
|
||||
import { Subscription } from "rxjs";
|
||||
import { ScanAdapterService } from "@adapter/scan";
|
||||
import { injectCancelSearch } from "@shared/services/cancel-subject";
|
||||
import { containsElement } from "@utils/common";
|
||||
import { EnvironmentService } from "@core/environment";
|
||||
|
||||
@Component({
|
||||
selector: 'ui-searchbox',
|
||||
templateUrl: 'searchbox.component.html',
|
||||
styleUrls: ['searchbox.component.scss'],
|
||||
selector: "ui-searchbox",
|
||||
templateUrl: "searchbox.component.html",
|
||||
styleUrls: ["searchbox.component.scss"],
|
||||
providers: [
|
||||
{
|
||||
provide: NG_VALUE_ACCESSOR,
|
||||
@@ -49,9 +49,9 @@ export class UiSearchboxNextComponent
|
||||
private readonly _cancelSearch = injectCancelSearch({ optional: true });
|
||||
|
||||
disabled: boolean;
|
||||
type = 'text';
|
||||
type = "text";
|
||||
|
||||
@ViewChild('input', { read: ElementRef, static: true })
|
||||
@ViewChild("input", { read: ElementRef, static: true })
|
||||
input: ElementRef;
|
||||
|
||||
@ContentChild(UiAutocompleteComponent)
|
||||
@@ -61,9 +61,9 @@ export class UiSearchboxNextComponent
|
||||
focusAfterViewInit: boolean = true;
|
||||
|
||||
@Input()
|
||||
placeholder: string = '';
|
||||
placeholder: string = "";
|
||||
|
||||
private _query = '';
|
||||
private _query = "";
|
||||
|
||||
@Input()
|
||||
get query() {
|
||||
@@ -94,7 +94,7 @@ export class UiSearchboxNextComponent
|
||||
scanner = false;
|
||||
|
||||
@Input()
|
||||
hint: string = '';
|
||||
hint: string = "";
|
||||
|
||||
@Output()
|
||||
hintCleared = new EventEmitter<void>();
|
||||
@@ -107,11 +107,11 @@ export class UiSearchboxNextComponent
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this.setQuery('');
|
||||
this.setQuery("");
|
||||
this._cancelSearch();
|
||||
}
|
||||
|
||||
@HostBinding('class.autocomplete-opend')
|
||||
@HostBinding("class.autocomplete-opend")
|
||||
get autocompleteOpen() {
|
||||
return this.autocomplete?.opend;
|
||||
}
|
||||
@@ -212,14 +212,14 @@ export class UiSearchboxNextComponent
|
||||
}
|
||||
|
||||
clearHint() {
|
||||
this.hint = '';
|
||||
this.hint = "";
|
||||
this.focused.emit(true);
|
||||
this.hintCleared.emit();
|
||||
this.cdr.markForCheck();
|
||||
}
|
||||
|
||||
onKeyup(event: KeyboardEvent) {
|
||||
if (event.key === 'Enter') {
|
||||
if (event.key === "Enter") {
|
||||
if (this.autocomplete?.opend && this.autocomplete?.activeItem) {
|
||||
this.setQuery(this.autocomplete?.activeItem?.item);
|
||||
this.autocomplete?.close();
|
||||
@@ -227,7 +227,7 @@ export class UiSearchboxNextComponent
|
||||
this.search.emit(this.query);
|
||||
|
||||
event.preventDefault();
|
||||
} else if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
|
||||
} else if (event.key === "ArrowUp" || event.key === "ArrowDown") {
|
||||
this.handleArrowUpDownEvent(event);
|
||||
}
|
||||
}
|
||||
@@ -235,12 +235,14 @@ export class UiSearchboxNextComponent
|
||||
handleArrowUpDownEvent(event: KeyboardEvent) {
|
||||
this.autocomplete?.handleKeyboardEvent(event);
|
||||
if (this.autocomplete?.activeItem) {
|
||||
const query = this.autocompleteValueSelector(this.autocomplete.activeItem.item);
|
||||
const query = this.autocompleteValueSelector(
|
||||
this.autocomplete.activeItem.item,
|
||||
);
|
||||
this.setQuery(query, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
@HostListener('window:click', ['$event'])
|
||||
@HostListener("window:click", ["$event"])
|
||||
focusLost(event: MouseEvent) {
|
||||
if (
|
||||
this.autocomplete?.opend &&
|
||||
@@ -254,9 +256,11 @@ export class UiSearchboxNextComponent
|
||||
this.search.emit(this.query);
|
||||
}
|
||||
|
||||
@HostListener('focusout', ['$event'])
|
||||
@HostListener("focusout", ["$event"])
|
||||
onBlur() {
|
||||
this.onTouched();
|
||||
if (typeof this.onTouched === "function") {
|
||||
this.onTouched();
|
||||
}
|
||||
this.focused.emit(false);
|
||||
this.cdr.markForCheck();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
}
|
||||
|
||||
.ui-tooltip-panel {
|
||||
@apply pointer-events-auto;
|
||||
|
||||
.triangle {
|
||||
width: 30px;
|
||||
polygon {
|
||||
|
||||
@@ -17,6 +17,7 @@ import { provideRouter } from '@angular/router';
|
||||
type ProductInfoInputs = {
|
||||
item: ProductInfoItem;
|
||||
orientation: ProductInfoOrientation;
|
||||
innerGridClass: string;
|
||||
};
|
||||
|
||||
const meta: Meta<ProductInfoInputs> = {
|
||||
@@ -50,8 +51,10 @@ const meta: Meta<ProductInfoInputs> = {
|
||||
value: 19.99,
|
||||
},
|
||||
},
|
||||
tag: 'Prio 2',
|
||||
},
|
||||
orientation: 'horizontal',
|
||||
innerGridClass: 'grid-cols-[minmax(20rem,1fr),auto]',
|
||||
},
|
||||
argTypes: {
|
||||
item: {
|
||||
@@ -68,6 +71,16 @@ const meta: Meta<ProductInfoInputs> = {
|
||||
},
|
||||
},
|
||||
},
|
||||
innerGridClass: {
|
||||
control: 'text',
|
||||
description:
|
||||
'Custom CSS classes for the inner grid layout. (Applies on vertical layout only)',
|
||||
table: {
|
||||
defaultValue: {
|
||||
summary: 'grid-cols-[minmax(20rem,1fr),auto]',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
render: (args) => ({
|
||||
props: args,
|
||||
@@ -95,6 +108,7 @@ export const Default: Story = {
|
||||
value: 29.99,
|
||||
},
|
||||
},
|
||||
tag: 'Prio 2',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import { type Meta, type StoryObj, argsToTemplate } from '@storybook/angular';
|
||||
import { ProductShelfMetaInfoComponent } from '@isa/remission/shared/product';
|
||||
|
||||
const meta: Meta<ProductShelfMetaInfoComponent> = {
|
||||
component: ProductShelfMetaInfoComponent,
|
||||
title: 'remission/shared/product/ProductShelfMetaInfoComponent',
|
||||
args: {
|
||||
department: 'Reise',
|
||||
shelfLabel: 'Europa',
|
||||
productGroupKey: '311',
|
||||
productGroupValue: 'Romane TB',
|
||||
assortment: 'Basissortiment|BPrämienartikel|n',
|
||||
returnReason: 'Beschädigt',
|
||||
},
|
||||
argTypes: {
|
||||
department: {
|
||||
control: { type: 'text' },
|
||||
description: 'The department of the product.',
|
||||
defaultValue: undefined,
|
||||
},
|
||||
shelfLabel: {
|
||||
control: { type: 'text' },
|
||||
description: 'The shelf label of the product.',
|
||||
defaultValue: undefined,
|
||||
},
|
||||
productGroupKey: {
|
||||
control: { type: 'text' },
|
||||
description: 'The key of the product group.',
|
||||
defaultValue: undefined,
|
||||
},
|
||||
productGroupValue: {
|
||||
control: { type: 'text' },
|
||||
description: 'The value of the product group.',
|
||||
defaultValue: undefined,
|
||||
},
|
||||
assortment: {
|
||||
control: { type: 'text' },
|
||||
description: 'The assortment of the product.',
|
||||
defaultValue: undefined,
|
||||
},
|
||||
returnReason: {
|
||||
control: { type: 'text' },
|
||||
description: 'The reason for the return of the product.',
|
||||
defaultValue: undefined,
|
||||
},
|
||||
},
|
||||
render: (args) => ({
|
||||
props: args,
|
||||
template: `<remi-product-shelf-meta-info ${argsToTemplate(args)}></remi-product-shelf-meta-info>`,
|
||||
}),
|
||||
};
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<ProductShelfMetaInfoComponent>;
|
||||
|
||||
export const Default: Story = {
|
||||
args: {
|
||||
department: 'Reise',
|
||||
shelfLabel: 'Europa',
|
||||
productGroupKey: '311',
|
||||
productGroupValue: 'Romane TB',
|
||||
assortment: 'Basissortiment|BPrämienartikel|n',
|
||||
returnReason: 'Beschädigt',
|
||||
},
|
||||
};
|
||||
@@ -1,74 +1,64 @@
|
||||
import {
|
||||
type Meta,
|
||||
type StoryObj,
|
||||
argsToTemplate,
|
||||
moduleMetadata,
|
||||
} from '@storybook/angular';
|
||||
import { ProductStockInfoComponent } from '@isa/remission/shared/product';
|
||||
import { provideProductImageUrl } from '@isa/shared/product-image';
|
||||
import { provideProductRouterLinkBuilder } from '@isa/shared/product-router-link';
|
||||
|
||||
const meta: Meta<ProductStockInfoComponent> = {
|
||||
component: ProductStockInfoComponent,
|
||||
title: 'remission/shared/product/ProductStockInfoComponent',
|
||||
decorators: [
|
||||
moduleMetadata({
|
||||
providers: [
|
||||
provideProductImageUrl('https://produktbilder-test.paragon-data.net'),
|
||||
provideProductRouterLinkBuilder((ean: string) => ean),
|
||||
],
|
||||
}),
|
||||
],
|
||||
args: {
|
||||
stock: 92,
|
||||
removedFromStock: 0,
|
||||
predefinedReturnQuantity: 4,
|
||||
remainingQuantityInStock: 0,
|
||||
zob: 0,
|
||||
},
|
||||
argTypes: {
|
||||
stock: {
|
||||
control: { type: 'number' },
|
||||
description: 'The current stock of the product.',
|
||||
defaultValue: 0,
|
||||
},
|
||||
removedFromStock: {
|
||||
control: { type: 'number' },
|
||||
description: 'The amount of stock that has been removed.',
|
||||
defaultValue: 0,
|
||||
},
|
||||
predefinedReturnQuantity: {
|
||||
control: { type: 'number' },
|
||||
description: 'The predefined return quantity for the product.',
|
||||
defaultValue: 0,
|
||||
},
|
||||
remainingQuantityInStock: {
|
||||
control: { type: 'number' },
|
||||
description: 'The remaining quantity in stock after returns.',
|
||||
defaultValue: 0,
|
||||
},
|
||||
zob: {
|
||||
control: { type: 'number' },
|
||||
description: 'Min Stock Category Management Information.',
|
||||
defaultValue: 0,
|
||||
},
|
||||
},
|
||||
render: (args) => ({
|
||||
props: args,
|
||||
template: `<remi-product-stock-info ${argsToTemplate(args)}></remi-product-stock-info>`,
|
||||
}),
|
||||
};
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<ProductStockInfoComponent>;
|
||||
|
||||
export const Default: Story = {
|
||||
args: {
|
||||
stock: 92,
|
||||
removedFromStock: 0,
|
||||
predefinedReturnQuantity: 4,
|
||||
remainingQuantityInStock: 0,
|
||||
zob: 0,
|
||||
},
|
||||
};
|
||||
import {
|
||||
type Meta,
|
||||
type StoryObj,
|
||||
argsToTemplate,
|
||||
moduleMetadata,
|
||||
} from '@storybook/angular';
|
||||
import { ProductStockInfoComponent } from '@isa/remission/shared/product';
|
||||
import { provideProductImageUrl } from '@isa/shared/product-image';
|
||||
import { provideProductRouterLinkBuilder } from '@isa/shared/product-router-link';
|
||||
|
||||
const meta: Meta<ProductStockInfoComponent> = {
|
||||
component: ProductStockInfoComponent,
|
||||
title: 'remission/shared/product/ProductStockInfoComponent',
|
||||
decorators: [
|
||||
moduleMetadata({
|
||||
providers: [
|
||||
provideProductImageUrl('https://produktbilder-test.paragon-data.net'),
|
||||
provideProductRouterLinkBuilder((ean: string) => ean),
|
||||
],
|
||||
}),
|
||||
],
|
||||
args: {
|
||||
availableStock: 92,
|
||||
stockToRemit: 91,
|
||||
targetStock: 1,
|
||||
zob: 0,
|
||||
},
|
||||
argTypes: {
|
||||
availableStock: {
|
||||
control: { type: 'number' },
|
||||
description: 'Total available stock for the product.',
|
||||
},
|
||||
stockToRemit: {
|
||||
control: { type: 'number' },
|
||||
description: 'Stock quantity to remit.',
|
||||
},
|
||||
targetStock: {
|
||||
control: { type: 'number' },
|
||||
description: 'Target stock level after remittance.',
|
||||
},
|
||||
zob: {
|
||||
control: { type: 'number' },
|
||||
description: 'Min Stock Category Management Information.',
|
||||
defaultValue: 0,
|
||||
},
|
||||
},
|
||||
render: (args) => ({
|
||||
props: args,
|
||||
template: `<remi-product-stock-info ${argsToTemplate(args)}></remi-product-stock-info>`,
|
||||
}),
|
||||
};
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<ProductStockInfoComponent>;
|
||||
|
||||
export const Default: Story = {
|
||||
args: {
|
||||
availableStock: 92,
|
||||
stockToRemit: 91,
|
||||
targetStock: 1,
|
||||
zob: 0,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import { argsToTemplate, type Meta, type StoryObj, moduleMetadata } from '@storybook/angular';
|
||||
import { EmptyStateComponent } from '@isa/ui/empty-state';
|
||||
import {
|
||||
argsToTemplate,
|
||||
type Meta,
|
||||
type StoryObj,
|
||||
moduleMetadata,
|
||||
} from '@storybook/angular';
|
||||
import { EmptyStateAppearance, EmptyStateComponent } from '@isa/ui/empty-state';
|
||||
import { ButtonComponent } from '@isa/ui/buttons';
|
||||
|
||||
type EmptyStateComponentInputs = {
|
||||
title: string;
|
||||
description: string;
|
||||
appearance: EmptyStateAppearance;
|
||||
};
|
||||
|
||||
const meta: Meta<EmptyStateComponentInputs> = {
|
||||
@@ -22,6 +28,10 @@ const meta: Meta<EmptyStateComponentInputs> = {
|
||||
description: {
|
||||
control: 'text',
|
||||
},
|
||||
appearance: {
|
||||
control: 'select',
|
||||
options: Object.values(EmptyStateAppearance),
|
||||
},
|
||||
},
|
||||
render: (args) => ({
|
||||
props: args,
|
||||
@@ -40,5 +50,6 @@ export const Default: Story = {
|
||||
args: {
|
||||
title: 'Keine Suchergebnisse',
|
||||
description: 'Suchen Sie nach einer Rechnungsnummer oder Kundennamen.',
|
||||
appearance: EmptyStateAppearance.NoResults,
|
||||
},
|
||||
};
|
||||
|
||||
39
apps/isa-app/stories/ui/label/ui-label.stories.ts
Normal file
39
apps/isa-app/stories/ui/label/ui-label.stories.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { argsToTemplate, type Meta, type StoryObj } from '@storybook/angular';
|
||||
import { Labeltype, LabelPriority, LabelComponent } from '@isa/ui/label';
|
||||
|
||||
type UiLabelInputs = {
|
||||
type: Labeltype;
|
||||
priority: LabelPriority;
|
||||
};
|
||||
|
||||
const meta: Meta<UiLabelInputs> = {
|
||||
component: LabelComponent,
|
||||
title: 'ui/label/Label',
|
||||
argTypes: {
|
||||
type: {
|
||||
control: { type: 'select' },
|
||||
options: Object.values(Labeltype),
|
||||
description: 'Determines the label type',
|
||||
},
|
||||
priority: {
|
||||
control: { type: 'select' },
|
||||
options: Object.values(LabelPriority),
|
||||
description: 'Determines the label priority',
|
||||
},
|
||||
},
|
||||
args: {
|
||||
type: 'tag',
|
||||
priority: 'high',
|
||||
},
|
||||
render: (args) => ({
|
||||
props: args,
|
||||
template: `<ui-label ${argsToTemplate(args)}>Prio 1</ui-label>`,
|
||||
}),
|
||||
};
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<LabelComponent>;
|
||||
|
||||
export const Default: Story = {
|
||||
args: {},
|
||||
};
|
||||
@@ -12,7 +12,7 @@ variables:
|
||||
value: '4'
|
||||
# Minor Version einstellen
|
||||
- name: 'Minor'
|
||||
value: '0'
|
||||
value: '1'
|
||||
- name: 'Patch'
|
||||
value: "$[counter(format('{0}.{1}', variables['Major'], variables['Minor']),0)]"
|
||||
- name: 'BuildUniqueID'
|
||||
@@ -89,7 +89,7 @@ jobs:
|
||||
condition: and(ne(variables['Build.SourceBranch'], 'refs/heads/integration'), ne(variables['Build.SourceBranch'], 'refs/heads/master'), not(startsWith(variables['Build.SourceBranch'], 'refs/heads/hotfix/')), not(startsWith(variables['Build.SourceBranch'], 'refs/heads/release/')))
|
||||
variables:
|
||||
- name: DockerTagSourceBranch
|
||||
value: $[replace(variables['Build.SourceBranch'], '/', '_')]
|
||||
value: $[replace(variables['Build.SourceBranch'], '/', '-')]
|
||||
- name: 'DockerTag'
|
||||
value: |
|
||||
$(Build.BuildNumber)-$(Build.SourceVersion)
|
||||
|
||||
3
libs/catalogue/data-access/src/lib/index.ts
Normal file
3
libs/catalogue/data-access/src/lib/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './models';
|
||||
export * from './schemas';
|
||||
export * from './services';
|
||||
@@ -0,0 +1,222 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { of } from 'rxjs';
|
||||
import { CatalougeSearchService } from './catalouge-search.service';
|
||||
import { SearchService } from '@generated/swagger/cat-search-api';
|
||||
import { Item } from '../models';
|
||||
import { SearchByTermInput } from '../schemas/catalouge-search.schemas';
|
||||
|
||||
describe('CatalougeSearchService', () => {
|
||||
let service: CatalougeSearchService;
|
||||
let searchServiceSpy: jest.Mocked<SearchService>;
|
||||
|
||||
beforeEach(() => {
|
||||
const searchServiceMock = {
|
||||
SearchByEAN: jest.fn(),
|
||||
SearchSearch: jest.fn(),
|
||||
};
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
CatalougeSearchService,
|
||||
{ provide: SearchService, useValue: searchServiceMock },
|
||||
],
|
||||
});
|
||||
|
||||
service = TestBed.inject(CatalougeSearchService);
|
||||
searchServiceSpy = TestBed.inject(SearchService) as jest.Mocked<SearchService>;
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
|
||||
describe('searchByEans', () => {
|
||||
it('should return items when search is successful', (done) => {
|
||||
// Arrange
|
||||
const mockItems: Item[] = [
|
||||
{ id: 1, product: { name: 'Item 1' }, catalogAvailability: { available: true } } as unknown as Item,
|
||||
{ id: 2, product: { name: 'Item 2' }, catalogAvailability: { available: true } } as unknown as Item,
|
||||
];
|
||||
const mockResponse = {
|
||||
error: false,
|
||||
result: mockItems,
|
||||
};
|
||||
searchServiceSpy.SearchByEAN.mockReturnValue(of(mockResponse));
|
||||
|
||||
// Act
|
||||
service.searchByEans('123456789', '987654321').subscribe({
|
||||
next: (result) => {
|
||||
// Assert
|
||||
expect(result).toEqual(mockItems);
|
||||
expect(searchServiceSpy.SearchByEAN).toHaveBeenCalledWith(['123456789', '987654321']);
|
||||
done();
|
||||
},
|
||||
error: done.fail,
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw error when response has error', (done) => {
|
||||
// Arrange
|
||||
const mockResponse = {
|
||||
error: true,
|
||||
message: 'Search failed',
|
||||
};
|
||||
searchServiceSpy.SearchByEAN.mockReturnValue(of(mockResponse));
|
||||
|
||||
// Act
|
||||
service.searchByEans('123456789').subscribe({
|
||||
next: () => done.fail('Should have thrown error'),
|
||||
error: (error) => {
|
||||
// Assert
|
||||
expect(error).toBeInstanceOf(Error);
|
||||
expect(error.message).toBe('Search failed');
|
||||
done();
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle single EAN', (done) => {
|
||||
// Arrange
|
||||
const mockItems: Item[] = [{ id: 1, product: { name: 'Item 1' }, catalogAvailability: { available: true } } as unknown as Item];
|
||||
const mockResponse = {
|
||||
error: false,
|
||||
result: mockItems,
|
||||
};
|
||||
searchServiceSpy.SearchByEAN.mockReturnValue(of(mockResponse));
|
||||
|
||||
// Act
|
||||
service.searchByEans('123456789').subscribe({
|
||||
next: (result) => {
|
||||
// Assert
|
||||
expect(result).toEqual(mockItems);
|
||||
expect(searchServiceSpy.SearchByEAN).toHaveBeenCalledWith(['123456789']);
|
||||
done();
|
||||
},
|
||||
error: done.fail,
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle empty EAN array', (done) => {
|
||||
// Arrange
|
||||
const mockResponse = {
|
||||
error: false,
|
||||
result: [],
|
||||
};
|
||||
searchServiceSpy.SearchByEAN.mockReturnValue(of(mockResponse));
|
||||
|
||||
// Act
|
||||
service.searchByEans().subscribe({
|
||||
next: (result) => {
|
||||
// Assert
|
||||
expect(result).toEqual([]);
|
||||
expect(searchServiceSpy.SearchByEAN).toHaveBeenCalledWith([]);
|
||||
done();
|
||||
},
|
||||
error: done.fail,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('searchByTerm', () => {
|
||||
it('should return search results when successful', async () => {
|
||||
// Arrange
|
||||
const mockItems: Item[] = [
|
||||
{ id: 1, product: { name: 'Test Item' }, catalogAvailability: { available: true } } as unknown as Item,
|
||||
];
|
||||
const mockResponse = {
|
||||
error: false,
|
||||
result: mockItems,
|
||||
total: 1,
|
||||
};
|
||||
searchServiceSpy.SearchSearch.mockReturnValue(of(mockResponse));
|
||||
|
||||
const params: SearchByTermInput = {
|
||||
searchTerm: 'test',
|
||||
skip: 0,
|
||||
take: 10,
|
||||
};
|
||||
const abortController = new AbortController();
|
||||
|
||||
// Act
|
||||
const result = await service.searchByTerm(params, abortController.signal);
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual(mockResponse);
|
||||
expect(searchServiceSpy.SearchSearch).toHaveBeenCalledWith({
|
||||
input: { qs: 'test' },
|
||||
skip: 0,
|
||||
take: 10,
|
||||
doNotTrack: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw error when response has error', async () => {
|
||||
// Arrange
|
||||
const mockResponse = {
|
||||
error: true,
|
||||
message: 'Search failed',
|
||||
};
|
||||
searchServiceSpy.SearchSearch.mockReturnValue(of(mockResponse));
|
||||
|
||||
const params: SearchByTermInput = {
|
||||
searchTerm: 'test',
|
||||
skip: 0,
|
||||
take: 10,
|
||||
};
|
||||
const abortController = new AbortController();
|
||||
|
||||
// Act & Assert
|
||||
await expect(service.searchByTerm(params, abortController.signal))
|
||||
.rejects
|
||||
.toThrow('Search failed');
|
||||
});
|
||||
|
||||
it('should handle abort signal', async () => {
|
||||
// Arrange
|
||||
const abortController = new AbortController();
|
||||
const mockResponse = {
|
||||
error: false,
|
||||
result: [],
|
||||
};
|
||||
searchServiceSpy.SearchSearch.mockReturnValue(of(mockResponse));
|
||||
|
||||
const params: SearchByTermInput = {
|
||||
searchTerm: 'test',
|
||||
skip: 0,
|
||||
take: 10,
|
||||
};
|
||||
|
||||
// Act
|
||||
const result = await service.searchByTerm(params, abortController.signal);
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual(mockResponse);
|
||||
expect(searchServiceSpy.SearchSearch).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should use default values when not provided', async () => {
|
||||
// Arrange
|
||||
const mockResponse = {
|
||||
error: false,
|
||||
result: [],
|
||||
};
|
||||
searchServiceSpy.SearchSearch.mockReturnValue(of(mockResponse));
|
||||
|
||||
const params: SearchByTermInput = {
|
||||
searchTerm: 'test',
|
||||
};
|
||||
const abortController = new AbortController();
|
||||
|
||||
// Act
|
||||
await service.searchByTerm(params, abortController.signal);
|
||||
|
||||
// Assert
|
||||
expect(searchServiceSpy.SearchSearch).toHaveBeenCalledWith({
|
||||
input: { qs: 'test' },
|
||||
skip: 0,
|
||||
take: 20,
|
||||
doNotTrack: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,52 +1,53 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { SearchService } from '@generated/swagger/cat-search-api';
|
||||
import { firstValueFrom, map, Observable } from 'rxjs';
|
||||
import { takeUntilAborted } from '@isa/common/data-access';
|
||||
import { Item } from '../models';
|
||||
import {
|
||||
SearchByTermInput,
|
||||
SearchByTermSchema,
|
||||
} from '../schemas/catalouge-search.schemas';
|
||||
import { ListResponseArgs } from '@isa/common/data-access';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CatalougeSearchService {
|
||||
#searchService = inject(SearchService);
|
||||
|
||||
searchByEans(...ean: string[]): Observable<Item[]> {
|
||||
return this.#searchService.SearchByEAN(ean).pipe(
|
||||
map((res) => {
|
||||
if (res.error) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
|
||||
return res.result as Item[];
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async searchByTerm(
|
||||
params: SearchByTermInput,
|
||||
abortSignal: AbortSignal,
|
||||
): Promise<ListResponseArgs<Item>> {
|
||||
const { searchTerm, skip, take } = SearchByTermSchema.parse(params);
|
||||
|
||||
const req$ = this.#searchService
|
||||
.SearchSearch({
|
||||
filter: {
|
||||
qs: searchTerm,
|
||||
},
|
||||
skip,
|
||||
take,
|
||||
})
|
||||
.pipe(takeUntilAborted(abortSignal));
|
||||
|
||||
const res = await firstValueFrom(req$);
|
||||
|
||||
if (res.error) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
|
||||
return res as ListResponseArgs<Item>;
|
||||
}
|
||||
}
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { SearchService } from '@generated/swagger/cat-search-api';
|
||||
import { firstValueFrom, map, Observable } from 'rxjs';
|
||||
import { takeUntilAborted } from '@isa/common/data-access';
|
||||
import { Item } from '../models';
|
||||
import {
|
||||
SearchByTermInput,
|
||||
SearchByTermSchema,
|
||||
} from '../schemas/catalouge-search.schemas';
|
||||
import { ListResponseArgs } from '@isa/common/data-access';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CatalougeSearchService {
|
||||
#searchService = inject(SearchService);
|
||||
|
||||
searchByEans(...ean: string[]): Observable<Item[]> {
|
||||
return this.#searchService.SearchByEAN(ean).pipe(
|
||||
map((res) => {
|
||||
if (res.error) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
|
||||
return res.result as Item[];
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async searchByTerm(
|
||||
params: SearchByTermInput,
|
||||
abortSignal: AbortSignal,
|
||||
): Promise<ListResponseArgs<Item>> {
|
||||
const { searchTerm, skip, take } = SearchByTermSchema.parse(params);
|
||||
|
||||
const req$ = this.#searchService
|
||||
.SearchSearch({
|
||||
input: {
|
||||
qs: searchTerm,
|
||||
},
|
||||
skip,
|
||||
take,
|
||||
doNotTrack: true,
|
||||
})
|
||||
.pipe(takeUntilAborted(abortSignal));
|
||||
|
||||
const res = await firstValueFrom(req$);
|
||||
|
||||
if (res.error) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
|
||||
return res as ListResponseArgs<Item>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,5 +44,8 @@ export class DataAccessError<TCode extends string, TData = void> extends Error {
|
||||
public readonly data: TData,
|
||||
) {
|
||||
super(message);
|
||||
// Set the prototype explicitly to maintain the correct prototype chain
|
||||
Object.setPrototypeOf(this, new.target.prototype);
|
||||
this.name = this.constructor.name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
export * from './errors';
|
||||
export * from './models';
|
||||
export * from './errors';
|
||||
export * from './helpers';
|
||||
export * from './models';
|
||||
export * from './operators';
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
import { BatchResponseArgs } from './batch-response-args';
|
||||
import { ReturnValue } from './return-value';
|
||||
|
||||
describe('BatchResponseArgs', () => {
|
||||
describe('interface structure', () => {
|
||||
it('should support all properties', () => {
|
||||
// Arrange
|
||||
const testData: BatchResponseArgs<string> = {
|
||||
alreadyProcessed: [
|
||||
{ error: false, result: 'processed1' },
|
||||
{ error: false, result: 'processed2' },
|
||||
],
|
||||
ambiguous: ['ambiguous1', 'ambiguous2'],
|
||||
completed: true,
|
||||
duplicates: [
|
||||
{ key: 'key1', value: 1 },
|
||||
{ key: 'key2', value: 2 },
|
||||
],
|
||||
error: false,
|
||||
failed: [
|
||||
{ error: true, message: 'Failed', result: 'failed1' },
|
||||
],
|
||||
invalidProperties: { field1: 'Invalid value' },
|
||||
message: 'Success',
|
||||
requestId: 12345,
|
||||
successful: [
|
||||
{ key: 'key1', value: 'value1' },
|
||||
{ key: 'key2', value: 'value2' },
|
||||
],
|
||||
total: 10,
|
||||
unknown: [
|
||||
{ error: false, result: 'unknown1' },
|
||||
],
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.alreadyProcessed).toHaveLength(2);
|
||||
expect(testData.ambiguous).toHaveLength(2);
|
||||
expect(testData.completed).toBe(true);
|
||||
expect(testData.duplicates).toHaveLength(2);
|
||||
expect(testData.error).toBe(false);
|
||||
expect(testData.failed).toHaveLength(1);
|
||||
expect(testData.invalidProperties).toEqual({ field1: 'Invalid value' });
|
||||
expect(testData.message).toBe('Success');
|
||||
expect(testData.requestId).toBe(12345);
|
||||
expect(testData.successful).toHaveLength(2);
|
||||
expect(testData.total).toBe(10);
|
||||
expect(testData.unknown).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should support required properties only', () => {
|
||||
// Arrange
|
||||
const testData: BatchResponseArgs<number> = {
|
||||
completed: false,
|
||||
error: true,
|
||||
total: 0,
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.completed).toBe(false);
|
||||
expect(testData.error).toBe(true);
|
||||
expect(testData.total).toBe(0);
|
||||
expect(testData.alreadyProcessed).toBeUndefined();
|
||||
expect(testData.ambiguous).toBeUndefined();
|
||||
expect(testData.duplicates).toBeUndefined();
|
||||
expect(testData.failed).toBeUndefined();
|
||||
expect(testData.invalidProperties).toBeUndefined();
|
||||
expect(testData.message).toBeUndefined();
|
||||
expect(testData.requestId).toBeUndefined();
|
||||
expect(testData.successful).toBeUndefined();
|
||||
expect(testData.unknown).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should support generic type parameter', () => {
|
||||
// Arrange
|
||||
interface TestObject {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
const testData: BatchResponseArgs<TestObject> = {
|
||||
completed: true,
|
||||
error: false,
|
||||
total: 1,
|
||||
successful: [
|
||||
{ key: { id: 1, name: 'test' }, value: { id: 1, name: 'test' } },
|
||||
],
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.successful?.[0].key.id).toBe(1);
|
||||
expect(testData.successful?.[0].key.name).toBe('test');
|
||||
expect(testData.successful?.[0].value.id).toBe(1);
|
||||
expect(testData.successful?.[0].value.name).toBe('test');
|
||||
});
|
||||
|
||||
it('should support ReturnValue arrays', () => {
|
||||
// Arrange
|
||||
const returnValue: ReturnValue<string> = {
|
||||
error: false,
|
||||
result: 'test result',
|
||||
message: 'Success',
|
||||
};
|
||||
|
||||
const testData: BatchResponseArgs<string> = {
|
||||
completed: true,
|
||||
error: false,
|
||||
total: 1,
|
||||
alreadyProcessed: [returnValue],
|
||||
failed: [returnValue],
|
||||
unknown: [returnValue],
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.alreadyProcessed?.[0]).toEqual(returnValue);
|
||||
expect(testData.failed?.[0]).toEqual(returnValue);
|
||||
expect(testData.unknown?.[0]).toEqual(returnValue);
|
||||
});
|
||||
|
||||
it('should support empty arrays', () => {
|
||||
// Arrange
|
||||
const testData: BatchResponseArgs<string> = {
|
||||
completed: true,
|
||||
error: false,
|
||||
total: 0,
|
||||
alreadyProcessed: [],
|
||||
ambiguous: [],
|
||||
duplicates: [],
|
||||
failed: [],
|
||||
successful: [],
|
||||
unknown: [],
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.alreadyProcessed).toHaveLength(0);
|
||||
expect(testData.ambiguous).toHaveLength(0);
|
||||
expect(testData.duplicates).toHaveLength(0);
|
||||
expect(testData.failed).toHaveLength(0);
|
||||
expect(testData.successful).toHaveLength(0);
|
||||
expect(testData.unknown).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import { ReturnValue } from './return-value';
|
||||
|
||||
export interface BatchResponseArgs<T> {
|
||||
alreadyProcessed?: Array<ReturnValue<T>>;
|
||||
ambiguous?: Array<T>;
|
||||
completed: boolean;
|
||||
duplicates?: Array<{ key: T; value: number }>;
|
||||
error: boolean;
|
||||
failed?: Array<ReturnValue<T>>;
|
||||
invalidProperties?: { [key: string]: string };
|
||||
message?: string;
|
||||
requestId?: number;
|
||||
successful?: Array<{ key: T; value: T }>;
|
||||
total: number;
|
||||
unknown?: Array<ReturnValue<T>>;
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
export * from './async-result';
|
||||
export * from './callback-result';
|
||||
export * from './entity-cotnainer';
|
||||
export * from './list-response-args';
|
||||
export * from './response-args';
|
||||
export * from './async-result';
|
||||
export * from './batch-response-args';
|
||||
export * from './callback-result';
|
||||
export * from './entity-cotnainer';
|
||||
export * from './list-response-args';
|
||||
export * from './response-args';
|
||||
export * from './return-value';
|
||||
|
||||
128
libs/common/data-access/src/lib/models/return-value.spec.ts
Normal file
128
libs/common/data-access/src/lib/models/return-value.spec.ts
Normal file
@@ -0,0 +1,128 @@
|
||||
import { ReturnValue } from './return-value';
|
||||
|
||||
describe('ReturnValue', () => {
|
||||
describe('interface structure', () => {
|
||||
it('should support all properties', () => {
|
||||
// Arrange
|
||||
const testData: ReturnValue<string> = {
|
||||
error: false,
|
||||
invalidProperties: { field1: 'Invalid value', field2: 'Another error' },
|
||||
message: 'Operation successful',
|
||||
result: 'test result',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.error).toBe(false);
|
||||
expect(testData.invalidProperties).toEqual({
|
||||
field1: 'Invalid value',
|
||||
field2: 'Another error'
|
||||
});
|
||||
expect(testData.message).toBe('Operation successful');
|
||||
expect(testData.result).toBe('test result');
|
||||
});
|
||||
|
||||
it('should support required properties only', () => {
|
||||
// Arrange
|
||||
const testData: ReturnValue<number> = {
|
||||
error: true,
|
||||
result: 42,
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.error).toBe(true);
|
||||
expect(testData.result).toBe(42);
|
||||
expect(testData.invalidProperties).toBeUndefined();
|
||||
expect(testData.message).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should support generic type parameter', () => {
|
||||
// Arrange
|
||||
interface TestObject {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
const testObject: TestObject = { id: 1, name: 'test' };
|
||||
const testData: ReturnValue<TestObject> = {
|
||||
error: false,
|
||||
result: testObject,
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.result.id).toBe(1);
|
||||
expect(testData.result.name).toBe('test');
|
||||
});
|
||||
|
||||
it('should support arrays as generic type', () => {
|
||||
// Arrange
|
||||
const testData: ReturnValue<string[]> = {
|
||||
error: false,
|
||||
result: ['item1', 'item2', 'item3'],
|
||||
message: 'Array operation successful',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.result).toHaveLength(3);
|
||||
expect(testData.result[0]).toBe('item1');
|
||||
expect(testData.result[1]).toBe('item2');
|
||||
expect(testData.result[2]).toBe('item3');
|
||||
});
|
||||
|
||||
it('should support null result', () => {
|
||||
// Arrange
|
||||
const testData: ReturnValue<string | null> = {
|
||||
error: false,
|
||||
result: null,
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.result).toBeNull();
|
||||
});
|
||||
|
||||
it('should support error state with message', () => {
|
||||
// Arrange
|
||||
const testData: ReturnValue<string> = {
|
||||
error: true,
|
||||
message: 'Operation failed',
|
||||
result: '',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.error).toBe(true);
|
||||
expect(testData.message).toBe('Operation failed');
|
||||
expect(testData.result).toBe('');
|
||||
});
|
||||
|
||||
it('should support complex invalidProperties', () => {
|
||||
// Arrange
|
||||
const testData: ReturnValue<any> = {
|
||||
error: true,
|
||||
invalidProperties: {
|
||||
'user.email': 'Invalid email format',
|
||||
'user.age': 'Age must be a positive number',
|
||||
'nested.field.value': 'Required field missing',
|
||||
},
|
||||
result: null,
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.invalidProperties).toEqual({
|
||||
'user.email': 'Invalid email format',
|
||||
'user.age': 'Age must be a positive number',
|
||||
'nested.field.value': 'Required field missing',
|
||||
});
|
||||
});
|
||||
|
||||
it('should support empty invalidProperties', () => {
|
||||
// Arrange
|
||||
const testData: ReturnValue<string> = {
|
||||
error: false,
|
||||
invalidProperties: {},
|
||||
result: 'success',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(testData.invalidProperties).toEqual({});
|
||||
});
|
||||
});
|
||||
});
|
||||
6
libs/common/data-access/src/lib/models/return-value.ts
Normal file
6
libs/common/data-access/src/lib/models/return-value.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export interface ReturnValue<T> {
|
||||
error: boolean;
|
||||
invalidProperties?: { [key: string]: string };
|
||||
message?: string;
|
||||
result: T;
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
export * from './lib/in-flight.decorator';
|
||||
export * from './lib/in-flight.decorator';
|
||||
export * from './lib/cache.decorator';
|
||||
383
libs/common/decorators/src/lib/cache.decorator.spec.ts
Normal file
383
libs/common/decorators/src/lib/cache.decorator.spec.ts
Normal file
@@ -0,0 +1,383 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { Cache } from './cache.decorator';
|
||||
|
||||
describe('Cache Decorator', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
vi.clearAllTimers();
|
||||
});
|
||||
|
||||
describe('Cache', () => {
|
||||
class DataService {
|
||||
callCount = 0;
|
||||
|
||||
@Cache({
|
||||
ttl: 1000, // 1 second cache
|
||||
keyGenerator: (query: string) => query
|
||||
})
|
||||
async search(query: string): Promise<string[]> {
|
||||
this.callCount++;
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
return [`result-${query}-${this.callCount}`];
|
||||
}
|
||||
|
||||
@Cache({
|
||||
ttl: 500
|
||||
})
|
||||
async fetchWithExpiry(id: number): Promise<string> {
|
||||
this.callCount++;
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
return `data-${id}-${this.callCount}`;
|
||||
}
|
||||
|
||||
@Cache()
|
||||
async fetchWithNoExpiry(value: string): Promise<string> {
|
||||
this.callCount++;
|
||||
return `permanent-${value}-${this.callCount}`;
|
||||
}
|
||||
}
|
||||
|
||||
it('should cache results for specified time', async () => {
|
||||
const service = new DataService();
|
||||
|
||||
// First call
|
||||
const promise1 = service.search('test');
|
||||
await vi.runAllTimersAsync();
|
||||
const result1 = await promise1;
|
||||
expect(result1).toEqual(['result-test-1']);
|
||||
expect(service.callCount).toBe(1);
|
||||
|
||||
// Second call within cache time - should return cached result
|
||||
const result2 = await service.search('test');
|
||||
expect(result2).toEqual(['result-test-1']);
|
||||
expect(service.callCount).toBe(1); // No new call
|
||||
|
||||
// Advance time past cache expiry
|
||||
vi.advanceTimersByTime(1100);
|
||||
|
||||
// Third call after cache expiry - should make new call
|
||||
const promise3 = service.search('test');
|
||||
await vi.runAllTimersAsync();
|
||||
const result3 = await promise3;
|
||||
expect(result3).toEqual(['result-test-2']);
|
||||
expect(service.callCount).toBe(2);
|
||||
});
|
||||
|
||||
it('should cache without expiry when no ttl specified', async () => {
|
||||
const service = new DataService();
|
||||
|
||||
// First call
|
||||
const result1 = await service.fetchWithNoExpiry('test');
|
||||
expect(result1).toBe('permanent-test-1');
|
||||
expect(service.callCount).toBe(1);
|
||||
|
||||
// Advance time significantly
|
||||
vi.advanceTimersByTime(10000);
|
||||
|
||||
// Second call should still use cache
|
||||
const result2 = await service.fetchWithNoExpiry('test');
|
||||
expect(result2).toBe('permanent-test-1');
|
||||
expect(service.callCount).toBe(1);
|
||||
});
|
||||
|
||||
it('should cache different keys separately', async () => {
|
||||
const service = new DataService();
|
||||
|
||||
// First call
|
||||
const promise1 = service.search('query1');
|
||||
await vi.runAllTimersAsync();
|
||||
const result1 = await promise1;
|
||||
expect(result1).toEqual(['result-query1-1']);
|
||||
expect(service.callCount).toBe(1);
|
||||
|
||||
// Second call with different key
|
||||
const promise2 = service.search('query2');
|
||||
await vi.runAllTimersAsync();
|
||||
const result2 = await promise2;
|
||||
expect(result2).toEqual(['result-query2-2']);
|
||||
expect(service.callCount).toBe(2);
|
||||
|
||||
// Subsequent calls should use cache
|
||||
const result3 = await service.search('query1');
|
||||
const result4 = await service.search('query2');
|
||||
expect(result3).toEqual(['result-query1-1']);
|
||||
expect(result4).toEqual(['result-query2-2']);
|
||||
expect(service.callCount).toBe(2); // No new calls
|
||||
});
|
||||
|
||||
it('should clean up expired cache entries', async () => {
|
||||
const service = new DataService();
|
||||
|
||||
// Make a call
|
||||
const promise1 = service.fetchWithExpiry(1);
|
||||
await vi.runAllTimersAsync();
|
||||
await promise1;
|
||||
|
||||
// Advance time past cache expiry
|
||||
vi.advanceTimersByTime(600);
|
||||
|
||||
// Make another call - should not use expired cache
|
||||
service.callCount = 0; // Reset for clarity
|
||||
const promise2 = service.fetchWithExpiry(1);
|
||||
await vi.runAllTimersAsync();
|
||||
const result2 = await promise2;
|
||||
|
||||
expect(result2).toBe('data-1-1');
|
||||
expect(service.callCount).toBe(1); // New call was made
|
||||
});
|
||||
|
||||
it('should not cache errors', async () => {
|
||||
class ErrorService {
|
||||
callCount = 0;
|
||||
|
||||
@Cache({ ttl: 1000 })
|
||||
async fetchWithError(): Promise<string> {
|
||||
this.callCount++;
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
throw new Error('API Error');
|
||||
}
|
||||
}
|
||||
|
||||
const service = new ErrorService();
|
||||
|
||||
// First call that errors
|
||||
try {
|
||||
const promise1 = service.fetchWithError();
|
||||
await vi.runAllTimersAsync();
|
||||
await promise1;
|
||||
expect.fail('Should have thrown an error');
|
||||
} catch (error) {
|
||||
expect(error).toBeInstanceOf(Error);
|
||||
expect((error as Error).message).toBe('API Error');
|
||||
}
|
||||
expect(service.callCount).toBe(1);
|
||||
|
||||
// Second call should not use cache (errors aren't cached)
|
||||
try {
|
||||
const promise2 = service.fetchWithError();
|
||||
await vi.runAllTimersAsync();
|
||||
await promise2;
|
||||
expect.fail('Should have thrown an error');
|
||||
} catch (error) {
|
||||
expect(error).toBeInstanceOf(Error);
|
||||
expect((error as Error).message).toBe('API Error');
|
||||
}
|
||||
expect(service.callCount).toBe(2);
|
||||
});
|
||||
|
||||
it('should use JSON.stringify as default key generator', async () => {
|
||||
class DefaultKeyService {
|
||||
callCount = 0;
|
||||
|
||||
@Cache({ ttl: 1000 })
|
||||
async fetch(_param1: string, _param2: number): Promise<string> {
|
||||
this.callCount++;
|
||||
return `result-${this.callCount}`;
|
||||
}
|
||||
}
|
||||
|
||||
const service = new DefaultKeyService();
|
||||
|
||||
// First call with specific args
|
||||
const result1 = await service.fetch('test', 123);
|
||||
expect(result1).toBe('result-1');
|
||||
|
||||
// Same args should use cache
|
||||
const result2 = await service.fetch('test', 123);
|
||||
expect(result2).toBe('result-1');
|
||||
expect(service.callCount).toBe(1);
|
||||
|
||||
// Different args should make new call
|
||||
const result3 = await service.fetch('test', 456);
|
||||
expect(result3).toBe('result-2');
|
||||
expect(service.callCount).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Sync function caching', () => {
|
||||
class MathService {
|
||||
callCount = 0;
|
||||
|
||||
@Cache({
|
||||
ttl: 1000,
|
||||
keyGenerator: (n: number) => n.toString()
|
||||
})
|
||||
fibonacci(n: number): number {
|
||||
this.callCount++;
|
||||
if (n <= 1) return n;
|
||||
return this.fibonacci(n - 1) + this.fibonacci(n - 2);
|
||||
}
|
||||
|
||||
@Cache({
|
||||
ttl: 500
|
||||
})
|
||||
expensiveCalculation(a: number, b: number): number {
|
||||
this.callCount++;
|
||||
// Simulate expensive calculation
|
||||
return a * b + Math.sqrt(a + b);
|
||||
}
|
||||
|
||||
@Cache()
|
||||
permanentCalculation(value: number): number {
|
||||
this.callCount++;
|
||||
return value * 2;
|
||||
}
|
||||
}
|
||||
|
||||
it('should cache sync function results', () => {
|
||||
const service = new MathService();
|
||||
|
||||
// First call
|
||||
const result1 = service.fibonacci(5);
|
||||
expect(result1).toBe(5);
|
||||
expect(service.callCount).toBe(6); // fibonacci(5) calls fibonacci(4), fibonacci(3), etc.
|
||||
|
||||
// Second call should use cache
|
||||
const result2 = service.fibonacci(5);
|
||||
expect(result2).toBe(5);
|
||||
expect(service.callCount).toBe(6); // No new calls
|
||||
});
|
||||
|
||||
it('should cache sync functions with multiple arguments', () => {
|
||||
const service = new MathService();
|
||||
|
||||
// First call
|
||||
const result1 = service.expensiveCalculation(10, 20);
|
||||
expect(result1).toBe(10 * 20 + Math.sqrt(10 + 20));
|
||||
expect(service.callCount).toBe(1);
|
||||
|
||||
// Second call with same arguments should use cache
|
||||
const result2 = service.expensiveCalculation(10, 20);
|
||||
expect(result2).toBe(result1);
|
||||
expect(service.callCount).toBe(1);
|
||||
|
||||
// Call with different arguments should execute
|
||||
const result3 = service.expensiveCalculation(5, 10);
|
||||
expect(result3).toBe(5 * 10 + Math.sqrt(5 + 10));
|
||||
expect(service.callCount).toBe(2);
|
||||
});
|
||||
|
||||
it('should handle sync function cache expiry', () => {
|
||||
const service = new MathService();
|
||||
|
||||
// First call
|
||||
const result1 = service.expensiveCalculation(3, 4);
|
||||
expect(result1).toBe(3 * 4 + Math.sqrt(3 + 4));
|
||||
expect(service.callCount).toBe(1);
|
||||
|
||||
// Second call within TTL should use cache
|
||||
const result2 = service.expensiveCalculation(3, 4);
|
||||
expect(result2).toBe(result1);
|
||||
expect(service.callCount).toBe(1);
|
||||
|
||||
// Advance time past TTL
|
||||
vi.advanceTimersByTime(600);
|
||||
|
||||
// Call after expiry should execute again
|
||||
const result3 = service.expensiveCalculation(3, 4);
|
||||
expect(result3).toBe(3 * 4 + Math.sqrt(3 + 4));
|
||||
expect(service.callCount).toBe(2);
|
||||
});
|
||||
|
||||
it('should cache sync functions without expiry', () => {
|
||||
const service = new MathService();
|
||||
|
||||
// First call
|
||||
const result1 = service.permanentCalculation(42);
|
||||
expect(result1).toBe(84);
|
||||
expect(service.callCount).toBe(1);
|
||||
|
||||
// Advance time significantly
|
||||
vi.advanceTimersByTime(10000);
|
||||
|
||||
// Second call should still use cache
|
||||
const result2 = service.permanentCalculation(42);
|
||||
expect(result2).toBe(84);
|
||||
expect(service.callCount).toBe(1);
|
||||
});
|
||||
|
||||
it('should not cache sync function errors', () => {
|
||||
class ErrorService {
|
||||
callCount = 0;
|
||||
|
||||
@Cache({ ttl: 1000 })
|
||||
errorFunction(shouldError: boolean): string {
|
||||
this.callCount++;
|
||||
if (shouldError) {
|
||||
throw new Error('Sync Error');
|
||||
}
|
||||
return 'success';
|
||||
}
|
||||
}
|
||||
|
||||
const service = new ErrorService();
|
||||
|
||||
// First call that errors
|
||||
expect(() => service.errorFunction(true)).toThrow('Sync Error');
|
||||
expect(service.callCount).toBe(1);
|
||||
|
||||
// Second call should not use cache (errors aren't cached)
|
||||
expect(() => service.errorFunction(true)).toThrow('Sync Error');
|
||||
expect(service.callCount).toBe(2);
|
||||
|
||||
// Call with success should work
|
||||
const result = service.errorFunction(false);
|
||||
expect(result).toBe('success');
|
||||
expect(service.callCount).toBe(3);
|
||||
|
||||
// Subsequent success call should use cache
|
||||
const result2 = service.errorFunction(false);
|
||||
expect(result2).toBe('success');
|
||||
expect(service.callCount).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Mixed sync/async usage', () => {
|
||||
class MixedService {
|
||||
callCount = 0;
|
||||
|
||||
@Cache({ ttl: 1000 })
|
||||
async asyncMethod(value: string): Promise<string> {
|
||||
this.callCount++;
|
||||
await new Promise(resolve => setTimeout(resolve, 10));
|
||||
return `async-${value}`;
|
||||
}
|
||||
|
||||
@Cache({ ttl: 1000 })
|
||||
syncMethod(value: string): string {
|
||||
this.callCount++;
|
||||
return `sync-${value}`;
|
||||
}
|
||||
}
|
||||
|
||||
it('should handle mixed sync and async methods in same class', async () => {
|
||||
const service = new MixedService();
|
||||
|
||||
// Test async method
|
||||
const promise1 = service.asyncMethod('test');
|
||||
await vi.runAllTimersAsync();
|
||||
const result1 = await promise1;
|
||||
expect(result1).toBe('async-test');
|
||||
expect(service.callCount).toBe(1);
|
||||
|
||||
// Test sync method
|
||||
const result2 = service.syncMethod('test');
|
||||
expect(result2).toBe('sync-test');
|
||||
expect(service.callCount).toBe(2);
|
||||
|
||||
// Test caching for both
|
||||
const result3 = await service.asyncMethod('test');
|
||||
expect(result3).toBe('async-test');
|
||||
expect(service.callCount).toBe(2); // No new call
|
||||
|
||||
const result4 = service.syncMethod('test');
|
||||
expect(result4).toBe('sync-test');
|
||||
expect(service.callCount).toBe(2); // No new call
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
149
libs/common/decorators/src/lib/cache.decorator.ts
Normal file
149
libs/common/decorators/src/lib/cache.decorator.ts
Normal file
@@ -0,0 +1,149 @@
|
||||
export const CacheTimeToLive = {
|
||||
oneMinute: 60 * 1000, // 1 minute
|
||||
fiveMinutes: 5 * 60 * 1000, // 5 minutes
|
||||
tenMinutes: 10 * 60 * 1000, // 10 minutes
|
||||
thirtyMinutes: 30 * 60 * 1000, // 30 minutes
|
||||
oneHour: 60 * 60 * 1000, // 1 hour
|
||||
} as const;
|
||||
|
||||
export type CacheTimeToLive =
|
||||
(typeof CacheTimeToLive)[keyof typeof CacheTimeToLive];
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/**
|
||||
* Options for configuring the Cache decorator
|
||||
*/
|
||||
export interface CacheOptions<T extends (...args: any[]) => any> {
|
||||
/**
|
||||
* Generate a cache key from the method arguments.
|
||||
* If not provided, uses JSON.stringify on all arguments.
|
||||
*/
|
||||
keyGenerator?: (...args: Parameters<T>) => string;
|
||||
|
||||
/**
|
||||
* Time in milliseconds to keep the result cached.
|
||||
* If not provided, cache never expires.
|
||||
*/
|
||||
ttl?: number | CacheTimeToLive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorator that caches the results of both sync and async method calls.
|
||||
* Results are cached based on method arguments and expire after the specified TTL.
|
||||
*
|
||||
* @param options Configuration options for the decorator
|
||||
* @example
|
||||
* ```typescript
|
||||
* class DataService {
|
||||
* // Async function caching
|
||||
* @Cache({
|
||||
* ttl: 5 * 60 * 1000, // Cache for 5 minutes
|
||||
* keyGenerator: (params: QueryParams) => params.query
|
||||
* })
|
||||
* async searchData(params: QueryParams): Promise<SearchResult> {
|
||||
* return await api.search(params);
|
||||
* }
|
||||
*
|
||||
* // Sync function caching (heavy calculations)
|
||||
* @Cache({
|
||||
* ttl: 10 * 60 * 1000, // Cache for 10 minutes
|
||||
* keyGenerator: (n: number) => n.toString()
|
||||
* })
|
||||
* fibonacci(n: number): number {
|
||||
* if (n <= 1) return n;
|
||||
* return this.fibonacci(n - 1) + this.fibonacci(n - 2);
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export function Cache<T extends (...args: any[]) => any>(
|
||||
options: CacheOptions<T> = {},
|
||||
): MethodDecorator {
|
||||
const cacheMap = new WeakMap<
|
||||
object,
|
||||
Map<string, { result: any; expiry?: number; isAsync: boolean }>
|
||||
>();
|
||||
|
||||
return function (
|
||||
_target: any,
|
||||
_propertyKey: string | symbol,
|
||||
descriptor: PropertyDescriptor,
|
||||
): PropertyDescriptor {
|
||||
const originalMethod = descriptor.value;
|
||||
|
||||
descriptor.value = function (
|
||||
this: any,
|
||||
...args: Parameters<T>
|
||||
): ReturnType<T> {
|
||||
// Initialize cache for this instance if needed
|
||||
if (!cacheMap.has(this)) {
|
||||
cacheMap.set(this, new Map());
|
||||
}
|
||||
const instanceCache = cacheMap.get(this);
|
||||
if (!instanceCache) {
|
||||
throw new Error('Cache map not initialized properly');
|
||||
}
|
||||
|
||||
// Generate cache key
|
||||
const key = options.keyGenerator
|
||||
? options.keyGenerator(...args)
|
||||
: JSON.stringify(args);
|
||||
|
||||
// Check cache first
|
||||
const cached = instanceCache.get(key);
|
||||
if (cached) {
|
||||
// If no TTL or not expired, return cached result
|
||||
if (!cached.expiry || cached.expiry > Date.now()) {
|
||||
// For async functions, wrap cached result in a Promise
|
||||
if (cached.isAsync) {
|
||||
return Promise.resolve(cached.result) as ReturnType<T>;
|
||||
}
|
||||
return cached.result;
|
||||
}
|
||||
// Clean up expired cache entry
|
||||
instanceCache.delete(key);
|
||||
}
|
||||
|
||||
// Execute original method
|
||||
const result = originalMethod.apply(this, args);
|
||||
|
||||
// Handle both sync and async functions
|
||||
// Use more robust Promise detection for testing environments
|
||||
const isPromise =
|
||||
result instanceof Promise ||
|
||||
(result &&
|
||||
typeof result.then === 'function' &&
|
||||
typeof result.catch === 'function');
|
||||
|
||||
if (isPromise) {
|
||||
// Async function: only cache successful results
|
||||
const promise = result
|
||||
.then((value: any) => {
|
||||
instanceCache.set(key, {
|
||||
result: value,
|
||||
expiry: options.ttl ? Date.now() + options.ttl : undefined,
|
||||
isAsync: true,
|
||||
});
|
||||
return value;
|
||||
})
|
||||
.catch((error: any) => {
|
||||
// Don't cache errors - ensure cache is clean
|
||||
instanceCache.delete(key);
|
||||
throw error;
|
||||
});
|
||||
|
||||
return promise as ReturnType<T>;
|
||||
} else {
|
||||
// Sync function: cache result directly
|
||||
instanceCache.set(key, {
|
||||
result,
|
||||
expiry: options.ttl ? Date.now() + options.ttl : undefined,
|
||||
isAsync: false,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
return descriptor;
|
||||
};
|
||||
}
|
||||
@@ -1,321 +1,202 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { InFlight, InFlightWithKey, InFlightWithCache } from './in-flight.decorator';
|
||||
|
||||
describe('InFlight Decorators', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
vi.clearAllTimers();
|
||||
});
|
||||
|
||||
describe('InFlight', () => {
|
||||
class TestService {
|
||||
callCount = 0;
|
||||
|
||||
@InFlight()
|
||||
async fetchData(delay = 100): Promise<string> {
|
||||
this.callCount++;
|
||||
await new Promise(resolve => setTimeout(resolve, delay));
|
||||
return `result-${this.callCount}`;
|
||||
}
|
||||
|
||||
@InFlight()
|
||||
async fetchWithError(delay = 100): Promise<string> {
|
||||
this.callCount++;
|
||||
await new Promise(resolve => setTimeout(resolve, delay));
|
||||
throw new Error('Test error');
|
||||
}
|
||||
}
|
||||
|
||||
it('should prevent multiple simultaneous calls', async () => {
|
||||
const service = new TestService();
|
||||
|
||||
// Make three simultaneous calls
|
||||
const promise1 = service.fetchData();
|
||||
const promise2 = service.fetchData();
|
||||
const promise3 = service.fetchData();
|
||||
|
||||
// Advance timers to complete the async operation
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
// All promises should resolve to the same value
|
||||
const [result1, result2, result3] = await Promise.all([promise1, promise2, promise3]);
|
||||
|
||||
expect(result1).toBe('result-1');
|
||||
expect(result2).toBe('result-1');
|
||||
expect(result3).toBe('result-1');
|
||||
expect(service.callCount).toBe(1);
|
||||
});
|
||||
|
||||
it('should allow subsequent calls after completion', async () => {
|
||||
const service = new TestService();
|
||||
|
||||
// First call
|
||||
const promise1 = service.fetchData();
|
||||
await vi.runAllTimersAsync();
|
||||
const result1 = await promise1;
|
||||
expect(result1).toBe('result-1');
|
||||
|
||||
// Second call after first completes
|
||||
const promise2 = service.fetchData();
|
||||
await vi.runAllTimersAsync();
|
||||
const result2 = await promise2;
|
||||
expect(result2).toBe('result-2');
|
||||
|
||||
expect(service.callCount).toBe(2);
|
||||
});
|
||||
|
||||
it('should handle errors properly', async () => {
|
||||
const service = new TestService();
|
||||
|
||||
// Make multiple calls that will error
|
||||
const promise1 = service.fetchWithError();
|
||||
const promise2 = service.fetchWithError();
|
||||
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
// Both should reject with the same error
|
||||
await expect(promise1).rejects.toThrow('Test error');
|
||||
await expect(promise2).rejects.toThrow('Test error');
|
||||
expect(service.callCount).toBe(1);
|
||||
|
||||
// Should allow new call after error
|
||||
const promise3 = service.fetchWithError();
|
||||
await vi.runAllTimersAsync();
|
||||
await expect(promise3).rejects.toThrow('Test error');
|
||||
expect(service.callCount).toBe(2);
|
||||
});
|
||||
|
||||
it('should maintain separate state per instance', async () => {
|
||||
const service1 = new TestService();
|
||||
const service2 = new TestService();
|
||||
|
||||
// Make simultaneous calls on different instances
|
||||
const promise1 = service1.fetchData();
|
||||
const promise2 = service2.fetchData();
|
||||
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
const [result1, result2] = await Promise.all([promise1, promise2]);
|
||||
|
||||
// Each instance should have made its own call
|
||||
expect(result1).toBe('result-1');
|
||||
expect(result2).toBe('result-1');
|
||||
expect(service1.callCount).toBe(1);
|
||||
expect(service2.callCount).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('InFlightWithKey', () => {
|
||||
class UserService {
|
||||
callCounts = new Map<string, number>();
|
||||
|
||||
@InFlightWithKey({
|
||||
keyGenerator: (userId: string) => userId
|
||||
})
|
||||
async fetchUser(userId: string, delay = 100): Promise<{ id: string; name: string }> {
|
||||
const count = (this.callCounts.get(userId) || 0) + 1;
|
||||
this.callCounts.set(userId, count);
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, delay));
|
||||
return { id: userId, name: `User ${userId} - Call ${count}` };
|
||||
}
|
||||
|
||||
@InFlightWithKey()
|
||||
async fetchWithDefaultKey(param1: string, param2: number): Promise<string> {
|
||||
const key = `${param1}-${param2}`;
|
||||
const count = (this.callCounts.get(key) || 0) + 1;
|
||||
this.callCounts.set(key, count);
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
return `Result ${count}`;
|
||||
}
|
||||
}
|
||||
|
||||
it('should deduplicate calls with same key', async () => {
|
||||
const service = new UserService();
|
||||
|
||||
// Multiple calls with same userId
|
||||
const promise1 = service.fetchUser('user1');
|
||||
const promise2 = service.fetchUser('user1');
|
||||
const promise3 = service.fetchUser('user1');
|
||||
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
const [result1, result2, result3] = await Promise.all([promise1, promise2, promise3]);
|
||||
|
||||
expect(result1).toEqual({ id: 'user1', name: 'User user1 - Call 1' });
|
||||
expect(result2).toEqual(result1);
|
||||
expect(result3).toEqual(result1);
|
||||
expect(service.callCounts.get('user1')).toBe(1);
|
||||
});
|
||||
|
||||
it('should allow simultaneous calls with different keys', async () => {
|
||||
const service = new UserService();
|
||||
|
||||
// Calls with different userIds
|
||||
const promise1 = service.fetchUser('user1');
|
||||
const promise2 = service.fetchUser('user2');
|
||||
const promise3 = service.fetchUser('user1'); // Duplicate of first
|
||||
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
const [result1, result2, result3] = await Promise.all([promise1, promise2, promise3]);
|
||||
|
||||
expect(result1).toEqual({ id: 'user1', name: 'User user1 - Call 1' });
|
||||
expect(result2).toEqual({ id: 'user2', name: 'User user2 - Call 1' });
|
||||
expect(result3).toEqual(result1); // Same as first call
|
||||
|
||||
expect(service.callCounts.get('user1')).toBe(1);
|
||||
expect(service.callCounts.get('user2')).toBe(1);
|
||||
});
|
||||
|
||||
it('should use JSON.stringify as default key generator', async () => {
|
||||
const service = new UserService();
|
||||
|
||||
// Multiple calls with same arguments
|
||||
const promise1 = service.fetchWithDefaultKey('test', 123);
|
||||
const promise2 = service.fetchWithDefaultKey('test', 123);
|
||||
|
||||
// Different arguments
|
||||
const promise3 = service.fetchWithDefaultKey('test', 456);
|
||||
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
const [result1, result2, result3] = await Promise.all([promise1, promise2, promise3]);
|
||||
|
||||
expect(result1).toBe('Result 1');
|
||||
expect(result2).toBe('Result 1'); // Same as first
|
||||
expect(result3).toBe('Result 1'); // Different key, separate call
|
||||
|
||||
expect(service.callCounts.get('test-123')).toBe(1);
|
||||
expect(service.callCounts.get('test-456')).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('InFlightWithCache', () => {
|
||||
class DataService {
|
||||
callCount = 0;
|
||||
|
||||
@InFlightWithCache({
|
||||
cacheTime: 1000, // 1 second cache
|
||||
keyGenerator: (query: string) => query
|
||||
})
|
||||
async search(query: string): Promise<string[]> {
|
||||
this.callCount++;
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
return [`result-${query}-${this.callCount}`];
|
||||
}
|
||||
|
||||
@InFlightWithCache({
|
||||
cacheTime: 500
|
||||
})
|
||||
async fetchWithExpiry(id: number): Promise<string> {
|
||||
this.callCount++;
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
return `data-${id}-${this.callCount}`;
|
||||
}
|
||||
}
|
||||
|
||||
it('should cache results for specified time', async () => {
|
||||
const service = new DataService();
|
||||
|
||||
// First call
|
||||
const promise1 = service.search('test');
|
||||
await vi.runAllTimersAsync();
|
||||
const result1 = await promise1;
|
||||
expect(result1).toEqual(['result-test-1']);
|
||||
expect(service.callCount).toBe(1);
|
||||
|
||||
// Second call within cache time - should return cached result
|
||||
const result2 = await service.search('test');
|
||||
expect(result2).toEqual(['result-test-1']);
|
||||
expect(service.callCount).toBe(1); // No new call
|
||||
|
||||
// Advance time past cache expiry
|
||||
vi.advanceTimersByTime(1100);
|
||||
|
||||
// Third call after cache expiry - should make new call
|
||||
const promise3 = service.search('test');
|
||||
await vi.runAllTimersAsync();
|
||||
const result3 = await promise3;
|
||||
expect(result3).toEqual(['result-test-2']);
|
||||
expect(service.callCount).toBe(2);
|
||||
});
|
||||
|
||||
it('should handle in-flight deduplication with caching', async () => {
|
||||
const service = new DataService();
|
||||
|
||||
// Multiple simultaneous calls
|
||||
const promise1 = service.search('query1');
|
||||
const promise2 = service.search('query1');
|
||||
const promise3 = service.search('query1');
|
||||
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
const [result1, result2, result3] = await Promise.all([promise1, promise2, promise3]);
|
||||
|
||||
// All should get same result
|
||||
expect(result1).toEqual(['result-query1-1']);
|
||||
expect(result2).toEqual(result1);
|
||||
expect(result3).toEqual(result1);
|
||||
expect(service.callCount).toBe(1);
|
||||
|
||||
// Subsequent call should use cache
|
||||
const result4 = await service.search('query1');
|
||||
expect(result4).toEqual(['result-query1-1']);
|
||||
expect(service.callCount).toBe(1);
|
||||
});
|
||||
|
||||
it('should clean up expired cache entries', async () => {
|
||||
const service = new DataService();
|
||||
|
||||
// Make a call
|
||||
const promise1 = service.fetchWithExpiry(1);
|
||||
await vi.runAllTimersAsync();
|
||||
await promise1;
|
||||
|
||||
// Advance time past cache expiry
|
||||
vi.advanceTimersByTime(600);
|
||||
|
||||
// Make another call - should not use expired cache
|
||||
service.callCount = 0; // Reset for clarity
|
||||
const promise2 = service.fetchWithExpiry(1);
|
||||
await vi.runAllTimersAsync();
|
||||
const result2 = await promise2;
|
||||
|
||||
expect(result2).toBe('data-1-1');
|
||||
expect(service.callCount).toBe(1); // New call was made
|
||||
});
|
||||
|
||||
it('should handle errors without caching them', async () => {
|
||||
class ErrorService {
|
||||
callCount = 0;
|
||||
|
||||
@InFlightWithCache({ cacheTime: 1000 })
|
||||
async fetchWithError(): Promise<string> {
|
||||
this.callCount++;
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
throw new Error('API Error');
|
||||
}
|
||||
}
|
||||
|
||||
const service = new ErrorService();
|
||||
|
||||
// First call that errors
|
||||
const promise1 = service.fetchWithError();
|
||||
await vi.runAllTimersAsync();
|
||||
await expect(promise1).rejects.toThrow('API Error');
|
||||
expect(service.callCount).toBe(1);
|
||||
|
||||
// Second call should not use cache (errors aren't cached)
|
||||
const promise2 = service.fetchWithError();
|
||||
await vi.runAllTimersAsync();
|
||||
await expect(promise2).rejects.toThrow('API Error');
|
||||
expect(service.callCount).toBe(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { InFlight } from './in-flight.decorator';
|
||||
|
||||
describe('InFlight Decorator', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
vi.clearAllTimers();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
describe('Basic usage (no options)', () => {
|
||||
class TestService {
|
||||
callCount = 0;
|
||||
|
||||
@InFlight()
|
||||
async fetchData(delay = 100): Promise<string> {
|
||||
this.callCount++;
|
||||
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||
return `result-${this.callCount}`;
|
||||
}
|
||||
|
||||
@InFlight()
|
||||
async fetchWithError(delay = 100): Promise<string> {
|
||||
this.callCount++;
|
||||
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||
throw new Error('Test error');
|
||||
}
|
||||
}
|
||||
|
||||
it('should prevent multiple simultaneous calls', async () => {
|
||||
const service = new TestService();
|
||||
|
||||
// Make three simultaneous calls
|
||||
const promise1 = service.fetchData();
|
||||
const promise2 = service.fetchData();
|
||||
const promise3 = service.fetchData();
|
||||
|
||||
// Advance timers to complete the async operation
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
// All promises should resolve to the same value
|
||||
const [result1, result2, result3] = await Promise.all([
|
||||
promise1,
|
||||
promise2,
|
||||
promise3,
|
||||
]);
|
||||
|
||||
expect(result1).toBe('result-1');
|
||||
expect(result2).toBe('result-1');
|
||||
expect(result3).toBe('result-1');
|
||||
expect(service.callCount).toBe(1);
|
||||
});
|
||||
|
||||
it('should allow subsequent calls after completion', async () => {
|
||||
const service = new TestService();
|
||||
|
||||
// First call
|
||||
const promise1 = service.fetchData();
|
||||
await vi.runAllTimersAsync();
|
||||
const result1 = await promise1;
|
||||
expect(result1).toBe('result-1');
|
||||
|
||||
// Second call after first completes
|
||||
const promise2 = service.fetchData();
|
||||
await vi.runAllTimersAsync();
|
||||
const result2 = await promise2;
|
||||
expect(result2).toBe('result-2');
|
||||
|
||||
expect(service.callCount).toBe(2);
|
||||
});
|
||||
|
||||
it('should maintain separate state per instance', async () => {
|
||||
const service1 = new TestService();
|
||||
const service2 = new TestService();
|
||||
|
||||
// Make simultaneous calls on different instances
|
||||
const promise1 = service1.fetchData();
|
||||
const promise2 = service2.fetchData();
|
||||
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
const [result1, result2] = await Promise.all([promise1, promise2]);
|
||||
|
||||
// Each instance should have made its own call
|
||||
expect(result1).toBe('result-1');
|
||||
expect(result2).toBe('result-1');
|
||||
expect(service1.callCount).toBe(1);
|
||||
expect(service2.callCount).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('With key generator', () => {
|
||||
class UserService {
|
||||
callCounts = new Map<string, number>();
|
||||
|
||||
@InFlight({
|
||||
keyGenerator: (userId: string) => userId,
|
||||
})
|
||||
async fetchUser(
|
||||
userId: string,
|
||||
delay = 100,
|
||||
): Promise<{ id: string; name: string }> {
|
||||
const count = (this.callCounts.get(userId) || 0) + 1;
|
||||
this.callCounts.set(userId, count);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||
return { id: userId, name: `User ${userId} - Call ${count}` };
|
||||
}
|
||||
|
||||
@InFlight({
|
||||
keyGenerator: undefined, // Uses JSON.stringify
|
||||
})
|
||||
async fetchWithDefaultKey(
|
||||
param1: string,
|
||||
param2: number,
|
||||
): Promise<string> {
|
||||
const key = `${param1}-${param2}`;
|
||||
const count = (this.callCounts.get(key) || 0) + 1;
|
||||
this.callCounts.set(key, count);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
return `Result ${count}`;
|
||||
}
|
||||
}
|
||||
|
||||
it('should deduplicate calls with same key', async () => {
|
||||
const service = new UserService();
|
||||
|
||||
// Multiple calls with same userId
|
||||
const promise1 = service.fetchUser('user1');
|
||||
const promise2 = service.fetchUser('user1');
|
||||
const promise3 = service.fetchUser('user1');
|
||||
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
const [result1, result2, result3] = await Promise.all([
|
||||
promise1,
|
||||
promise2,
|
||||
promise3,
|
||||
]);
|
||||
|
||||
expect(result1).toEqual({ id: 'user1', name: 'User user1 - Call 1' });
|
||||
expect(result2).toEqual(result1);
|
||||
expect(result3).toEqual(result1);
|
||||
expect(service.callCounts.get('user1')).toBe(1);
|
||||
});
|
||||
|
||||
it('should allow simultaneous calls with different keys', async () => {
|
||||
const service = new UserService();
|
||||
|
||||
// Calls with different userIds
|
||||
const promise1 = service.fetchUser('user1');
|
||||
const promise2 = service.fetchUser('user2');
|
||||
const promise3 = service.fetchUser('user1'); // Duplicate of first
|
||||
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
const [result1, result2, result3] = await Promise.all([
|
||||
promise1,
|
||||
promise2,
|
||||
promise3,
|
||||
]);
|
||||
|
||||
expect(result1).toEqual({ id: 'user1', name: 'User user1 - Call 1' });
|
||||
expect(result2).toEqual({ id: 'user2', name: 'User user2 - Call 1' });
|
||||
expect(result3).toEqual(result1); // Same as first call
|
||||
|
||||
expect(service.callCounts.get('user1')).toBe(1);
|
||||
expect(service.callCounts.get('user2')).toBe(1);
|
||||
});
|
||||
|
||||
it('should use JSON.stringify as default key generator when keyGenerator is undefined', async () => {
|
||||
const service = new UserService();
|
||||
|
||||
// Multiple calls with same arguments
|
||||
const promise1 = service.fetchWithDefaultKey('test', 123);
|
||||
const promise2 = service.fetchWithDefaultKey('test', 123);
|
||||
|
||||
// Different arguments
|
||||
const promise3 = service.fetchWithDefaultKey('test', 456);
|
||||
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
const [result1, result2, result3] = await Promise.all([
|
||||
promise1,
|
||||
promise2,
|
||||
promise3,
|
||||
]);
|
||||
|
||||
expect(result1).toBe('Result 1');
|
||||
expect(result2).toBe('Result 1'); // Same as first
|
||||
expect(result3).toBe('Result 1'); // Different key, separate call
|
||||
|
||||
expect(service.callCounts.get('test-123')).toBe(1);
|
||||
expect(service.callCounts.get('test-456')).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,99 +1,52 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/**
|
||||
* Options for configuring the InFlight decorator
|
||||
*/
|
||||
export interface InFlightOptions<T extends (...args: any[]) => any> {
|
||||
/**
|
||||
* Generate a cache key from the method arguments.
|
||||
* If not provided, uses JSON.stringify on all arguments.
|
||||
* If omitted entirely, the decorator will not differentiate between calls with different arguments.
|
||||
*/
|
||||
keyGenerator?: (...args: Parameters<T>) => string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorator that prevents multiple simultaneous calls to the same async method.
|
||||
* All concurrent calls will receive the same Promise result.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* class MyService {
|
||||
* @InFlight()
|
||||
* async fetchData(): Promise<Data> {
|
||||
* // This method will only execute once even if called multiple times simultaneously
|
||||
* return await api.getData();
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export function InFlight<
|
||||
T extends (...args: any[]) => Promise<any>,
|
||||
>(): MethodDecorator {
|
||||
const inFlightMap = new WeakMap<object, Promise<any>>();
|
||||
|
||||
return function (
|
||||
target: any,
|
||||
propertyKey: string | symbol,
|
||||
descriptor: PropertyDescriptor,
|
||||
): PropertyDescriptor {
|
||||
const originalMethod = descriptor.value;
|
||||
|
||||
descriptor.value = async function (
|
||||
this: any,
|
||||
...args: Parameters<T>
|
||||
): Promise<ReturnType<T>> {
|
||||
// Check if there's already an in-flight request for this instance
|
||||
const existingRequest = inFlightMap.get(this);
|
||||
if (existingRequest) {
|
||||
return existingRequest;
|
||||
}
|
||||
|
||||
// Create new request and store it
|
||||
const promise = originalMethod
|
||||
.apply(this, args)
|
||||
.then((result: any) => {
|
||||
// Clean up after successful completion
|
||||
inFlightMap.delete(this);
|
||||
return result;
|
||||
})
|
||||
.catch((error: any) => {
|
||||
// Clean up after error
|
||||
inFlightMap.delete(this);
|
||||
throw error;
|
||||
});
|
||||
|
||||
inFlightMap.set(this, promise);
|
||||
return promise;
|
||||
};
|
||||
|
||||
return descriptor;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorator that prevents multiple simultaneous calls to the same async method
|
||||
* while considering method arguments. Each unique set of arguments gets its own
|
||||
* in-flight tracking.
|
||||
*
|
||||
* @param options Configuration options for the decorator
|
||||
* @example
|
||||
* ```typescript
|
||||
* class UserService {
|
||||
* @InFlightWithKey({
|
||||
* class MyService {
|
||||
* // Basic usage - all calls share the same in-flight request
|
||||
* @InFlight()
|
||||
* async fetchData(): Promise<Data> {
|
||||
* return await api.getData();
|
||||
* }
|
||||
*
|
||||
* // With key generator - calls with different arguments can execute simultaneously
|
||||
* @InFlight({
|
||||
* keyGenerator: (userId: string) => userId
|
||||
* })
|
||||
* async fetchUser(userId: string): Promise<User> {
|
||||
* // Calls with different userIds can execute simultaneously
|
||||
* // Calls with the same userId will share the same promise
|
||||
* return await api.getUser(userId);
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export interface InFlightWithKeyOptions<T extends (...args: any[]) => any> {
|
||||
/**
|
||||
* Generate a cache key from the method arguments.
|
||||
* If not provided, uses JSON.stringify on all arguments.
|
||||
*/
|
||||
keyGenerator?: (...args: Parameters<T>) => string;
|
||||
}
|
||||
|
||||
export function InFlightWithKey<T extends (...args: any[]) => Promise<any>>(
|
||||
options: InFlightWithKeyOptions<T> = {},
|
||||
export function InFlight<T extends (...args: any[]) => Promise<any>>(
|
||||
options: InFlightOptions<T> = {},
|
||||
): MethodDecorator {
|
||||
const inFlightMap = new WeakMap<object, Map<string, Promise<any>>>();
|
||||
// If keyGenerator is explicitly provided (even if undefined), use keyed mode
|
||||
const useKeys = 'keyGenerator' in options;
|
||||
|
||||
const simpleInFlightMap = new WeakMap<object, Promise<any>>();
|
||||
const keyedInFlightMap = new WeakMap<object, Map<string, Promise<any>>>();
|
||||
|
||||
return function (
|
||||
target: any,
|
||||
propertyKey: string | symbol,
|
||||
_target: any,
|
||||
_propertyKey: string | symbol,
|
||||
descriptor: PropertyDescriptor,
|
||||
): PropertyDescriptor {
|
||||
const originalMethod = descriptor.value;
|
||||
@@ -102,148 +55,59 @@ export function InFlightWithKey<T extends (...args: any[]) => Promise<any>>(
|
||||
this: any,
|
||||
...args: Parameters<T>
|
||||
): Promise<ReturnType<T>> {
|
||||
// Initialize map for this instance if needed
|
||||
if (!inFlightMap.has(this)) {
|
||||
inFlightMap.set(this, new Map());
|
||||
if (!useKeys) {
|
||||
// Simple mode: one in-flight request per instance
|
||||
const existingRequest = simpleInFlightMap.get(this);
|
||||
if (existingRequest) {
|
||||
return existingRequest;
|
||||
}
|
||||
|
||||
const promise = originalMethod
|
||||
.apply(this, args)
|
||||
.then((result: any) => {
|
||||
simpleInFlightMap.delete(this);
|
||||
return result;
|
||||
})
|
||||
.catch((error: any) => {
|
||||
simpleInFlightMap.delete(this);
|
||||
throw error;
|
||||
});
|
||||
|
||||
simpleInFlightMap.set(this, promise);
|
||||
return promise;
|
||||
} else {
|
||||
// Keyed mode: separate in-flight requests per key
|
||||
if (!keyedInFlightMap.has(this)) {
|
||||
keyedInFlightMap.set(this, new Map());
|
||||
}
|
||||
const instanceMap = keyedInFlightMap.get(this);
|
||||
if (!instanceMap) {
|
||||
throw new Error('In-flight map not initialized properly');
|
||||
}
|
||||
|
||||
const key = options.keyGenerator
|
||||
? options.keyGenerator(...args)
|
||||
: JSON.stringify(args);
|
||||
|
||||
const existingRequest = instanceMap.get(key);
|
||||
if (existingRequest) {
|
||||
return existingRequest;
|
||||
}
|
||||
|
||||
const promise = originalMethod
|
||||
.apply(this, args)
|
||||
.then((result: any) => {
|
||||
instanceMap.delete(key);
|
||||
return result;
|
||||
})
|
||||
.catch((error: any) => {
|
||||
instanceMap.delete(key);
|
||||
throw error;
|
||||
});
|
||||
|
||||
instanceMap.set(key, promise);
|
||||
return promise;
|
||||
}
|
||||
const instanceMap = inFlightMap.get(this)!;
|
||||
|
||||
// Generate cache key
|
||||
const key = options.keyGenerator
|
||||
? options.keyGenerator(...args)
|
||||
: JSON.stringify(args);
|
||||
|
||||
// Check if there's already an in-flight request for this key
|
||||
const existingRequest = instanceMap.get(key);
|
||||
if (existingRequest) {
|
||||
return existingRequest;
|
||||
}
|
||||
|
||||
// Create new request and store it
|
||||
const promise = originalMethod
|
||||
.apply(this, args)
|
||||
.then((result: any) => {
|
||||
// Clean up after successful completion
|
||||
instanceMap.delete(key);
|
||||
return result;
|
||||
})
|
||||
.catch((error: any) => {
|
||||
// Clean up after error
|
||||
instanceMap.delete(key);
|
||||
throw error;
|
||||
});
|
||||
|
||||
instanceMap.set(key, promise);
|
||||
return promise;
|
||||
};
|
||||
|
||||
return descriptor;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorator that prevents multiple simultaneous calls to the same async method
|
||||
* with additional caching capabilities.
|
||||
*
|
||||
* @param options Configuration options for the decorator
|
||||
* @example
|
||||
* ```typescript
|
||||
* class DataService {
|
||||
* @InFlightWithCache({
|
||||
* cacheTime: 5 * 60 * 1000, // Cache for 5 minutes
|
||||
* keyGenerator: (params: QueryParams) => params.query
|
||||
* })
|
||||
* async searchData(params: QueryParams): Promise<SearchResult> {
|
||||
* return await api.search(params);
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export interface InFlightWithCacheOptions<T extends (...args: any[]) => any> {
|
||||
/**
|
||||
* Generate a cache key from the method arguments.
|
||||
* If not provided, uses JSON.stringify on all arguments.
|
||||
*/
|
||||
keyGenerator?: (...args: Parameters<T>) => string;
|
||||
|
||||
/**
|
||||
* Time in milliseconds to keep the result cached after completion.
|
||||
* If not provided, result is not cached after completion.
|
||||
*/
|
||||
cacheTime?: number;
|
||||
}
|
||||
|
||||
export function InFlightWithCache<T extends (...args: any[]) => Promise<any>>(
|
||||
options: InFlightWithCacheOptions<T> = {},
|
||||
): MethodDecorator {
|
||||
const inFlightMap = new WeakMap<object, Map<string, Promise<any>>>();
|
||||
const cacheMap = new WeakMap<
|
||||
object,
|
||||
Map<string, { result: any; expiry: number }>
|
||||
>();
|
||||
|
||||
return function (
|
||||
target: any,
|
||||
propertyKey: string | symbol,
|
||||
descriptor: PropertyDescriptor,
|
||||
): PropertyDescriptor {
|
||||
const originalMethod = descriptor.value;
|
||||
|
||||
descriptor.value = async function (
|
||||
this: any,
|
||||
...args: Parameters<T>
|
||||
): Promise<ReturnType<T>> {
|
||||
// Initialize maps for this instance if needed
|
||||
if (!inFlightMap.has(this)) {
|
||||
inFlightMap.set(this, new Map());
|
||||
cacheMap.set(this, new Map());
|
||||
}
|
||||
const instanceInFlight = inFlightMap.get(this)!;
|
||||
const instanceCache = cacheMap.get(this)!;
|
||||
|
||||
// Generate cache key
|
||||
const key = options.keyGenerator
|
||||
? options.keyGenerator(...args)
|
||||
: JSON.stringify(args);
|
||||
|
||||
// Check cache first (if cacheTime is set)
|
||||
if (options.cacheTime) {
|
||||
const cached = instanceCache.get(key);
|
||||
if (cached && cached.expiry > Date.now()) {
|
||||
return Promise.resolve(cached.result);
|
||||
}
|
||||
// Clean up expired cache entry
|
||||
if (cached) {
|
||||
instanceCache.delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if there's already an in-flight request
|
||||
const existingRequest = instanceInFlight.get(key);
|
||||
if (existingRequest) {
|
||||
return existingRequest;
|
||||
}
|
||||
|
||||
// Create new request
|
||||
const promise = originalMethod
|
||||
.apply(this, args)
|
||||
.then((result: any) => {
|
||||
// Cache result if cacheTime is set
|
||||
if (options.cacheTime) {
|
||||
instanceCache.set(key, {
|
||||
result,
|
||||
expiry: Date.now() + options.cacheTime,
|
||||
});
|
||||
}
|
||||
return result;
|
||||
})
|
||||
.finally(() => {
|
||||
// Always clean up in-flight request
|
||||
instanceInFlight.delete(key);
|
||||
});
|
||||
|
||||
instanceInFlight.set(key, promise);
|
||||
return promise;
|
||||
};
|
||||
|
||||
return descriptor;
|
||||
|
||||
@@ -1,166 +1,166 @@
|
||||
import { LogLevel } from './log-level.enum';
|
||||
import { Type } from '@angular/core';
|
||||
|
||||
/**
|
||||
* Represents a destination where log messages are sent.
|
||||
* Implement this interface to create custom logging destinations like
|
||||
* console logging, remote logging services, or file logging.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* @Injectable()
|
||||
* export class CustomLogSink implements Sink {
|
||||
* log(
|
||||
* level: LogLevel,
|
||||
* message: string,
|
||||
* context?: LoggerContext,
|
||||
* error?: Error
|
||||
* ): void {
|
||||
* // Custom logging implementation
|
||||
* if (level === LogLevel.Error) {
|
||||
* // Send to monitoring service
|
||||
* this.monitoringService.reportError(message, error, context);
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export interface Sink {
|
||||
/**
|
||||
* Method called by the LoggingService to send a log entry to this sink.
|
||||
*
|
||||
* @param level - The severity level of the log message
|
||||
* @param message - The main log message content
|
||||
* @param context - Optional structured data or metadata about the log event
|
||||
* @param error - Optional error object when logging errors
|
||||
*/
|
||||
log(
|
||||
level: LogLevel,
|
||||
message: string,
|
||||
context?: LoggerContext,
|
||||
error?: Error,
|
||||
): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* A factory function that creates a logging sink function.
|
||||
* Useful when the sink needs access to injected dependencies or
|
||||
* requires initialization logic.
|
||||
*
|
||||
* @returns A function matching the Sink.log method signature
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* export const httpLogSink: SinkFn = () => {
|
||||
* const http = inject(HttpClient);
|
||||
* const config = inject(ConfigService);
|
||||
*
|
||||
* return (level, message, context?, error?) => {
|
||||
* http.post(config.loggingEndpoint, {
|
||||
* level,
|
||||
* message,
|
||||
* context,
|
||||
* error: error && {
|
||||
* name: error.name,
|
||||
* message: error.message,
|
||||
* stack: error.stack
|
||||
* }
|
||||
* }).subscribe();
|
||||
* };
|
||||
* };
|
||||
* ```
|
||||
*/
|
||||
export type SinkFn = () => (
|
||||
level: LogLevel,
|
||||
message: string,
|
||||
context?: LoggerContext,
|
||||
error?: Error,
|
||||
) => void;
|
||||
|
||||
/**
|
||||
* Configuration options for the logging service.
|
||||
* Used to set up the logging behavior during application initialization.
|
||||
*/
|
||||
export interface LoggingConfig {
|
||||
/** The minimum log level to process. Messages below this level are ignored. */
|
||||
level: LogLevel;
|
||||
|
||||
/**
|
||||
* An array of logging destinations where messages will be sent.
|
||||
* Can be sink instances, classes, or factory functions.
|
||||
*/
|
||||
sinks: (Sink | SinkFn | Type<Sink>)[];
|
||||
|
||||
/**
|
||||
* Optional global context included with every log message.
|
||||
* Useful for adding application-wide metadata like version or environment.
|
||||
*/
|
||||
context?: LoggerContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the public API for logging operations.
|
||||
* This interface is returned by the logger factory and provides
|
||||
* methods for logging at different severity levels.
|
||||
*/
|
||||
export interface LoggerApi {
|
||||
/**
|
||||
* Logs a trace message with optional context.
|
||||
* Use for fine-grained debugging information.
|
||||
*/
|
||||
trace(message: string, context?: () => LoggerContext): void;
|
||||
|
||||
/**
|
||||
* Logs a debug message with optional context.
|
||||
* Use for development-time debugging information.
|
||||
*/
|
||||
debug(message: string, context?: () => LoggerContext): void;
|
||||
|
||||
/**
|
||||
* Logs an info message with optional context.
|
||||
* Use for general runtime information.
|
||||
*/
|
||||
info(message: string, context?: () => LoggerContext): void;
|
||||
|
||||
/**
|
||||
* Logs a warning message with optional context.
|
||||
* Use for potentially harmful situations.
|
||||
*/
|
||||
warn(message: string, context?: () => LoggerContext): void;
|
||||
|
||||
/**
|
||||
* Logs an error message with an optional error object and context.
|
||||
* Use for error conditions that affect functionality.
|
||||
*
|
||||
* @param message - The error message to log
|
||||
* @param error - Optional error object that caused this error condition
|
||||
* @param context - Optional context data associated with the error
|
||||
*/
|
||||
error(message: string, error?: Error, context?: () => LoggerContext): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents context data associated with a log message.
|
||||
* Context allows adding structured metadata to log messages,
|
||||
* making them more informative and easier to filter/analyze.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Component context
|
||||
* const context: LoggerContext = {
|
||||
* component: 'UserProfile',
|
||||
* userId: '12345',
|
||||
* action: 'save'
|
||||
* };
|
||||
*
|
||||
* // Error context
|
||||
* const errorContext: LoggerContext = {
|
||||
* operationId: 'op-123',
|
||||
* attemptNumber: 3,
|
||||
* inputData: { ... }
|
||||
* };
|
||||
* ```
|
||||
*/
|
||||
export interface LoggerContext {
|
||||
[key: string]: unknown;
|
||||
}
|
||||
import { LogLevel } from './log-level.enum';
|
||||
import { Type } from '@angular/core';
|
||||
|
||||
/**
|
||||
* Represents a destination where log messages are sent.
|
||||
* Implement this interface to create custom logging destinations like
|
||||
* console logging, remote logging services, or file logging.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* @Injectable()
|
||||
* export class CustomLogSink implements Sink {
|
||||
* log(
|
||||
* level: LogLevel,
|
||||
* message: string,
|
||||
* context?: LoggerContext,
|
||||
* error?: Error
|
||||
* ): void {
|
||||
* // Custom logging implementation
|
||||
* if (level === LogLevel.Error) {
|
||||
* // Send to monitoring service
|
||||
* this.monitoringService.reportError(message, error, context);
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export interface Sink {
|
||||
/**
|
||||
* Method called by the LoggingService to send a log entry to this sink.
|
||||
*
|
||||
* @param level - The severity level of the log message
|
||||
* @param message - The main log message content
|
||||
* @param context - Optional structured data or metadata about the log event
|
||||
* @param error - Optional error object when logging errors
|
||||
*/
|
||||
log(
|
||||
level: LogLevel,
|
||||
message: string,
|
||||
context?: LoggerContext,
|
||||
error?: Error,
|
||||
): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* A factory function that creates a logging sink function.
|
||||
* Useful when the sink needs access to injected dependencies or
|
||||
* requires initialization logic.
|
||||
*
|
||||
* @returns A function matching the Sink.log method signature
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* export const httpLogSink: SinkFn = () => {
|
||||
* const http = inject(HttpClient);
|
||||
* const config = inject(ConfigService);
|
||||
*
|
||||
* return (level, message, context?, error?) => {
|
||||
* http.post(config.loggingEndpoint, {
|
||||
* level,
|
||||
* message,
|
||||
* context,
|
||||
* error: error && {
|
||||
* name: error.name,
|
||||
* message: error.message,
|
||||
* stack: error.stack
|
||||
* }
|
||||
* }).subscribe();
|
||||
* };
|
||||
* };
|
||||
* ```
|
||||
*/
|
||||
export type SinkFn = () => (
|
||||
level: LogLevel,
|
||||
message: string,
|
||||
context?: LoggerContext,
|
||||
error?: Error,
|
||||
) => void;
|
||||
|
||||
/**
|
||||
* Configuration options for the logging service.
|
||||
* Used to set up the logging behavior during application initialization.
|
||||
*/
|
||||
export interface LoggingConfig {
|
||||
/** The minimum log level to process. Messages below this level are ignored. */
|
||||
level: LogLevel;
|
||||
|
||||
/**
|
||||
* An array of logging destinations where messages will be sent.
|
||||
* Can be sink instances, classes, or factory functions.
|
||||
*/
|
||||
sinks: (Sink | SinkFn | Type<Sink>)[];
|
||||
|
||||
/**
|
||||
* Optional global context included with every log message.
|
||||
* Useful for adding application-wide metadata like version or environment.
|
||||
*/
|
||||
context?: LoggerContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the public API for logging operations.
|
||||
* This interface is returned by the logger factory and provides
|
||||
* methods for logging at different severity levels.
|
||||
*/
|
||||
export interface LoggerApi {
|
||||
/**
|
||||
* Logs a trace message with optional context.
|
||||
* Use for fine-grained debugging information.
|
||||
*/
|
||||
trace(message: string, context?: () => LoggerContext): void;
|
||||
|
||||
/**
|
||||
* Logs a debug message with optional context.
|
||||
* Use for development-time debugging information.
|
||||
*/
|
||||
debug(message: string, context?: () => LoggerContext): void;
|
||||
|
||||
/**
|
||||
* Logs an info message with optional context.
|
||||
* Use for general runtime information.
|
||||
*/
|
||||
info(message: string, context?: () => LoggerContext): void;
|
||||
|
||||
/**
|
||||
* Logs a warning message with optional context.
|
||||
* Use for potentially harmful situations.
|
||||
*/
|
||||
warn(message: string, context?: () => LoggerContext): void;
|
||||
|
||||
/**
|
||||
* Logs an error message with an optional error object and context.
|
||||
* Use for error conditions that affect functionality.
|
||||
*
|
||||
* @param message - The error message to log
|
||||
* @param error - Optional error object that caused this error condition
|
||||
* @param context - Optional context data associated with the error
|
||||
*/
|
||||
error(message: string, error?: unknown, context?: () => LoggerContext): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents context data associated with a log message.
|
||||
* Context allows adding structured metadata to log messages,
|
||||
* making them more informative and easier to filter/analyze.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Component context
|
||||
* const context: LoggerContext = {
|
||||
* component: 'UserProfile',
|
||||
* userId: '12345',
|
||||
* action: 'save'
|
||||
* };
|
||||
*
|
||||
* // Error context
|
||||
* const errorContext: LoggerContext = {
|
||||
* operationId: 'op-123',
|
||||
* attemptNumber: 3,
|
||||
* inputData: { ... }
|
||||
* };
|
||||
* ```
|
||||
*/
|
||||
export interface LoggerContext {
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
import { Type } from '@angular/core';
|
||||
import { getState, patchState, signalStoreFeature, withHooks, withMethods } from '@ngrx/signals';
|
||||
import {
|
||||
getState,
|
||||
patchState,
|
||||
signalStoreFeature,
|
||||
withHooks,
|
||||
withMethods,
|
||||
} from '@ngrx/signals';
|
||||
import { rxMethod } from '@ngrx/signals/rxjs-interop';
|
||||
import { StorageProvider } from './storage-provider';
|
||||
import { injectStorage } from './storage';
|
||||
import { debounceTime, pipe, switchMap } from 'rxjs';
|
||||
|
||||
export function withStorage(storageKey: string, storageProvider: Type<StorageProvider>) {
|
||||
export function withStorage(
|
||||
storageKey: string,
|
||||
storageProvider: Type<StorageProvider>,
|
||||
) {
|
||||
return signalStoreFeature(
|
||||
withMethods((store, storage = injectStorage(storageProvider)) => ({
|
||||
storeState: rxMethod<void>(
|
||||
@@ -16,7 +25,7 @@ export function withStorage(storageKey: string, storageProvider: Type<StoragePro
|
||||
),
|
||||
restoreState: async () => {
|
||||
const data = await storage.get(storageKey);
|
||||
if (data) {
|
||||
if (data && typeof data === 'object') {
|
||||
patchState(store, data);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,27 +1,42 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { StorageProvider } from './storage-provider';
|
||||
import { UserStateService } from '@generated/swagger/isa-api';
|
||||
import { firstValueFrom, map, shareReplay } from 'rxjs';
|
||||
import { inject, Injectable } from "@angular/core";
|
||||
import { StorageProvider } from "./storage-provider";
|
||||
import { UserStateService } from "@generated/swagger/isa-api";
|
||||
import { catchError, firstValueFrom, map, of } from "rxjs";
|
||||
import { isEmpty } from "lodash";
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
@Injectable({ providedIn: "root" })
|
||||
export class UserStorageProvider implements StorageProvider {
|
||||
#userStateService = inject(UserStateService);
|
||||
|
||||
private state$ = this.#userStateService.UserStateGetUserState().pipe(
|
||||
map((res) => {
|
||||
if (res.result?.content) {
|
||||
if (res?.result?.content) {
|
||||
return JSON.parse(res.result.content);
|
||||
}
|
||||
return {};
|
||||
}),
|
||||
shareReplay(1),
|
||||
catchError((err) => {
|
||||
console.warn(
|
||||
"No UserStateGetUserState found, returning empty object:",
|
||||
err,
|
||||
);
|
||||
return of({}); // Return empty state fallback
|
||||
}),
|
||||
// shareReplay(1), #5249, #5270 Würde beim Fehlerfall den fehlerhaften Zustand behalten
|
||||
// Aktuell wird nun jedes mal 2 mal der UserState aufgerufen (GET + POST)
|
||||
// Damit bei der set Funktion immer der aktuelle Zustand verwendet wird
|
||||
);
|
||||
|
||||
async set(key: string, value: unknown): Promise<void> {
|
||||
async set(key: string, value: Record<string, unknown>): Promise<void> {
|
||||
const current = await firstValueFrom(this.state$);
|
||||
firstValueFrom(
|
||||
const content =
|
||||
current && !isEmpty(current)
|
||||
? { ...current, [key]: value }
|
||||
: { [key]: value };
|
||||
|
||||
await firstValueFrom(
|
||||
this.#userStateService.UserStateSetUserState({
|
||||
content: JSON.stringify({ ...current, [key]: value }),
|
||||
content: JSON.stringify(content),
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -32,7 +47,6 @@ export class UserStorageProvider implements StorageProvider {
|
||||
}
|
||||
|
||||
async clear(key: string): Promise<void> {
|
||||
|
||||
const current = await firstValueFrom(this.state$);
|
||||
delete current[key];
|
||||
firstValueFrom(this.#userStateService.UserStateResetUserState());
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { TabService } from './tab.service';
|
||||
|
||||
export function injectActivatedTabId() {
|
||||
/**
|
||||
* Injects the current activated tab as a signal.
|
||||
* @returns A signal that emits the current activated tab or null if no tab is activated.
|
||||
*/
|
||||
export function injectTab() {
|
||||
return inject(TabService).activatedTab;
|
||||
}
|
||||
|
||||
/**
|
||||
* Injects the current tab ID as a signal.
|
||||
* @returns A signal that emits the current tab ID or null if no tab is activated.
|
||||
*/
|
||||
export function injectTabId() {
|
||||
return inject(TabService).activatedTabId;
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ export const isaFiliale =
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"> <path fill-rule="evenodd" clip-rule="evenodd" d="M11.4772 1.33637C11.8195 1.24369 12.1803 1.24369 12.5226 1.33637C12.92 1.44396 13.2545 1.70662 13.5215 1.91625C13.547 1.93627 13.5719 1.9558 13.5961 1.97466L20.3784 7.24979C20.4046 7.27009 20.4305 7.2902 20.4562 7.31015C20.8328 7.60242 21.1646 7.85993 21.4119 8.19422C21.6288 8.48761 21.7905 8.81812 21.8889 9.16952C22.0009 9.56993 22.0005 9.98994 22 10.4667C21.9999 10.4992 21.9999 10.532 21.9999 10.5651V17.8386C21.9999 18.3657 21.9999 18.8205 21.9693 19.195C21.937 19.5904 21.8657 19.9836 21.6729 20.362C21.3853 20.9265 20.9264 21.3854 20.3619 21.673C19.9835 21.8658 19.5903 21.9371 19.1949 21.9694C18.8204 22 18.3656 22 17.8385 22H6.16133C5.63419 22 5.17943 22 4.80487 21.9694C4.40952 21.9371 4.0163 21.8658 3.63792 21.673C3.07344 21.3854 2.6145 20.9265 2.32688 20.362C2.13408 19.9836 2.06277 19.5904 2.03046 19.195C1.99986 18.8205 1.99988 18.3657 1.99989 17.8385L1.9999 10.5651C1.9999 10.532 1.99986 10.4992 1.99982 10.4667C1.99931 9.98994 1.99886 9.56993 2.11094 9.16952C2.2093 8.81811 2.37094 8.48761 2.58794 8.19422C2.83519 7.85992 3.16701 7.60242 3.54364 7.31013C3.56934 7.29019 3.59524 7.27009 3.62134 7.24979L10.4037 1.97466C10.4279 1.9558 10.4528 1.93626 10.4783 1.91625C10.7453 1.70662 11.0798 1.44396 11.4772 1.33637ZM9.9999 20H13.9999V13.6C13.9999 13.3035 13.9991 13.1412 13.9896 13.0246C13.9892 13.02 13.9888 13.0156 13.9884 13.0114C13.9843 13.0111 13.9799 13.0107 13.9753 13.0103C13.8587 13.0008 13.6964 13 13.3999 13H10.5999C10.3034 13 10.1411 13.0008 10.0245 13.0103C10.0199 13.0107 10.0155 13.0111 10.0113 13.0114C10.011 13.0156 10.0106 13.02 10.0102 13.0246C10.0007 13.1412 9.9999 13.3035 9.9999 13.6V20ZM15.9999 20L15.9999 13.5681C15.9999 13.3157 16 13.0699 15.983 12.8618C15.9643 12.6332 15.9202 12.3634 15.7819 12.092C15.5902 11.7157 15.2842 11.4097 14.9079 11.218C14.6365 11.0797 14.3667 11.0356 14.1381 11.0169C13.93 10.9999 13.6842 11 13.4318 11H10.568C10.3156 11 10.0698 10.9999 9.86167 11.0169C9.63307 11.0356 9.36334 11.0797 9.09191 11.218C8.71559 11.4097 8.40963 11.7157 8.21788 12.092C8.07959 12.3634 8.03552 12.6332 8.01684 12.8618C7.99983 13.0699 7.99986 13.3157 7.99989 13.5681L7.9999 20H6.1999C5.62334 20 5.25107 19.9992 4.96773 19.9761C4.69607 19.9539 4.59535 19.9162 4.5459 19.891C4.35774 19.7951 4.20476 19.6422 4.10889 19.454C4.0837 19.4045 4.04602 19.3038 4.02382 19.0322C4.00067 18.7488 3.9999 18.3766 3.9999 17.8V10.5651C3.9999 9.93408 4.00858 9.80982 4.03691 9.70862C4.0697 9.59148 4.12358 9.48131 4.19591 9.38352C4.2584 9.29903 4.35115 9.21588 4.84923 8.82849L11.6315 3.55337C11.8184 3.40799 11.9174 3.33175 11.9926 3.28154C11.9951 3.27984 11.9976 3.27823 11.9999 3.27671C12.0022 3.27823 12.0046 3.27984 12.0072 3.28154C12.0823 3.33175 12.1814 3.40799 12.3683 3.55337L19.1506 8.82849C19.6486 9.21588 19.7414 9.29903 19.8039 9.38352C19.8762 9.48131 19.9301 9.59148 19.9629 9.70862C19.9912 9.80982 19.9999 9.93408 19.9999 10.5651V17.8C19.9999 18.3766 19.9991 18.7488 19.976 19.0322C19.9538 19.3038 19.9161 19.4045 19.8909 19.454C19.795 19.6422 19.642 19.7951 19.4539 19.891C19.4044 19.9162 19.3037 19.9539 19.0321 19.9761C18.7487 19.9992 18.3764 20 17.7999 20H15.9999Z" fill="currentColor"/></svg>';
|
||||
|
||||
export const isaFilialeLocation =
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"> <path d="M12 13C13.6569 13 15 11.6569 15 10C15 8.34315 13.6569 7 12 7C10.3431 7 9 8.34315 9 10C9 11.6569 10.3431 13 12 13Z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/> <path d="M12 22C16 18 20 14.4183 20 10C20 5.58172 16.4183 2 12 2C7.58172 2 4 5.58172 4 10C4 14.4183 8 18 12 22Z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"><path d="M12 13C13.6569 13 15 11.6569 15 10C15 8.34315 13.6569 7 12 7C10.3431 7 9 8.34315 9 10C9 11.6569 10.3431 13 12 13Z" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M12 22C16 18 20 14.4183 20 10C20 5.58172 16.4183 2 12 2C7.58172 2 4 5.58172 4 10C4 14.4183 8 18 12 22Z" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
|
||||
|
||||
export const isaArtikelKartoniert = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M7.24787 2.5C7.25947 2.5 7.2711 2.5 7.28276 2.5L7.60047 2.5C8.34332 2.49999 8.95985 2.49998 9.46281 2.54033C9.98596 2.5823 10.4728 2.67271 10.9325 2.90269C11.3354 3.10427 11.6965 3.37467 12.0002 3.6995C12.3038 3.37467 12.665 3.10427 13.0679 2.90269C13.5275 2.67271 14.0144 2.5823 14.5375 2.54033C15.0405 2.49998 15.657 2.49999 16.3999 2.5L16.7525 2.5C17.111 2.49998 17.437 2.49996 17.7088 2.52177C18.0006 2.54518 18.3162 2.59847 18.6274 2.75419C19.0751 2.9782 19.4425 3.3374 19.6739 3.78334C19.8357 4.09512 19.891 4.41165 19.9152 4.70214C19.9376 4.97133 19.9376 5.29341 19.9375 5.64431L19.9375 15.0162C19.9375 15.3671 19.9375 15.6892 19.9151 15.9584C19.8909 16.2489 19.8356 16.5654 19.6739 16.8772C19.4425 17.3231 19.0751 17.6823 18.6273 17.9063C18.3161 18.062 18.0006 18.1153 17.7088 18.1387C17.4369 18.1605 17.111 18.1605 16.7524 18.1605L15.7637 18.1605C14.8337 18.1605 14.5735 18.1704 14.3521 18.2364C14.127 18.3035 13.9187 18.4132 13.7388 18.5585C13.5634 18.7 13.4135 18.9026 12.8969 19.6636L12.8274 19.7659C12.6413 20.04 12.3315 20.2042 12.0001 20.2042C11.6687 20.2042 11.3589 20.04 11.1728 19.7659L11.1033 19.6636C10.5867 18.9026 10.4368 18.7 10.2615 18.5585C10.0815 18.4132 9.87318 18.3035 9.64811 18.2364C9.42671 18.1704 9.1665 18.1605 8.23647 18.1605L7.24783 18.1605C6.88925 18.1605 6.56329 18.1605 6.29144 18.1387C5.99966 18.1153 5.68411 18.062 5.37287 17.9063C4.92515 17.6823 4.55774 17.3231 4.32635 16.8772C4.16457 16.5654 4.10926 16.2489 4.08509 15.9584C4.0627 15.6892 4.06272 15.3671 4.06275 15.0162L4.06281 5.67991C4.06281 5.67991 4.06281 5.67991 4.06281 5.67991C4.06281 5.66801 4.06281 5.65612 4.06281 5.64428C4.06279 5.29339 4.06276 4.97133 4.08516 4.70215C4.10933 4.41166 4.16464 4.09512 4.32642 3.78334C4.55781 3.33739 4.92522 2.9782 5.37293 2.75419C5.68418 2.59847 5.99972 2.54518 6.2915 2.52177C6.56335 2.49996 6.8893 2.49998 7.24787 2.5ZM6.26449 4.54428C6.26445 4.54427 6.26506 4.54398 6.26646 4.54347L6.26449 4.54428ZM6.26646 4.54347C6.27658 4.53983 6.32436 4.52556 6.45145 4.51536C6.63354 4.50075 6.87803 4.5 7.28276 4.5H7.56026C8.35352 4.5 8.88941 4.50075 9.30286 4.53392C9.70517 4.5662 9.90362 4.62429 10.0376 4.69131C10.3731 4.85916 10.6424 5.12525 10.8101 5.44839C10.8752 5.57377 10.9333 5.76196 10.9658 6.15304C10.9994 6.55634 11.0002 7.07998 11.0002 7.85982L11.0001 16.6511C10.7538 16.5122 10.492 16.401 10.2197 16.3198C9.68245 16.1596 9.10813 16.16 8.36282 16.1604C8.32125 16.1605 8.27913 16.1605 8.23647 16.1605H7.2827C6.87797 16.1605 6.63348 16.1598 6.45139 16.1451C6.3243 16.1349 6.2767 16.1207 6.26659 16.1171C6.19397 16.0805 6.13794 16.0243 6.10332 15.9593C6.0995 15.9476 6.08735 15.9024 6.07821 15.7925C6.06355 15.6164 6.06275 15.3789 6.06275 14.9806L6.06281 5.67992C6.06281 5.2816 6.06362 5.04409 6.07827 4.86798C6.08742 4.75806 6.09956 4.71289 6.10339 4.7012C6.13801 4.63617 6.19384 4.58011 6.26646 4.54347ZM13.0001 16.6511C13.2464 16.5122 13.5082 16.401 13.7805 16.3198C14.3178 16.1596 14.8921 16.16 15.6374 16.1604C15.679 16.1605 15.7211 16.1605 15.7637 16.1605H16.7175C17.1222 16.1605 17.3667 16.1598 17.5488 16.1451C17.6759 16.1349 17.7235 16.1207 17.7336 16.1171C17.8062 16.0805 17.8623 16.0243 17.8969 15.9593C17.9007 15.9476 17.9129 15.9024 17.922 15.7925C17.9367 15.6164 17.9375 15.3789 17.9375 14.9806L17.9375 5.67991C17.9375 5.28159 17.9367 5.04409 17.9221 4.86798C17.9129 4.75807 17.9008 4.7129 17.8969 4.7012C17.8623 4.63617 17.8063 4.58004 17.7337 4.5434C17.7236 4.53976 17.676 4.52556 17.5489 4.51536C17.3668 4.50075 17.1223 4.5 16.7176 4.5H16.4401C15.6468 4.5 15.1109 4.50075 14.6975 4.53392C14.2952 4.5662 14.0967 4.62429 13.9628 4.69131C13.6273 4.85916 13.3579 5.12525 13.1902 5.44839C13.1252 5.57377 13.0671 5.76196 13.0345 6.15304C13.001 6.55634 13.0002 7.07998 13.0002 7.85983L13.0001 16.6511ZM17.7358 16.1162C17.7358 16.1162 17.735 16.1166 17.7336 16.1171L17.7358 16.1162Z" fill="#212529"/>
|
||||
|
||||
@@ -51,14 +51,24 @@ export const isTolinoEligibleForReturn = (
|
||||
};
|
||||
}
|
||||
|
||||
// #5286 Anpassung des Tolino-Rückgabeflows (+ siehe Kommentare)
|
||||
const displayDamaged =
|
||||
answers[ReturnProcessQuestionKey.DisplayDamaged] === YesNoAnswer.Yes;
|
||||
const receivedDamaged = itemDamaged === ReturnReasonAnswer.ReceivedDamaged;
|
||||
const receiptOlderThan6Months = date
|
||||
? differenceInCalendarMonths(new Date(), parseISO(date)) >= 6
|
||||
: undefined;
|
||||
const receiptOlderThan24Months = date
|
||||
? differenceInCalendarMonths(new Date(), parseISO(date)) >= 24
|
||||
: undefined;
|
||||
|
||||
if (
|
||||
itemDamaged === ReturnReasonAnswer.ReceivedDamaged &&
|
||||
receiptOlderThan6Months
|
||||
) {
|
||||
const isEligible =
|
||||
receiptOlderThan6Months &&
|
||||
!receiptOlderThan24Months &&
|
||||
receivedDamaged &&
|
||||
!displayDamaged;
|
||||
|
||||
if (!isEligible) {
|
||||
return {
|
||||
state: EligibleForReturnState.NotEligible,
|
||||
reason: 'Keine Retoure möglich',
|
||||
|
||||
8
libs/oms/data-access/src/lib/index.ts
Normal file
8
libs/oms/data-access/src/lib/index.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export * from './errors';
|
||||
export * from './guards';
|
||||
export * from './models';
|
||||
export * from './operators';
|
||||
export * from './questions';
|
||||
export * from './schemas';
|
||||
export * from './services';
|
||||
export * from './stores';
|
||||
@@ -116,7 +116,7 @@ export class ReturnDetailsService {
|
||||
* Validates that the email parameter is a properly formatted email address.
|
||||
*/
|
||||
static FetchReceiptsEmailParamsSchema = z.object({
|
||||
email: z.string().email(),
|
||||
email: z.string(),
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
></oms-feature-return-details-static>
|
||||
@if (customerReceiptsResource.isLoading()) {
|
||||
<ui-progress-bar class="w-full" mode="indeterminate"></ui-progress-bar>
|
||||
} @else {
|
||||
} @else if (!customerReceiptsResource.error()) {
|
||||
@for (receipt of customerReceiptsResource.value(); track receipt.id) {
|
||||
@if (r.id !== receipt.id) {
|
||||
<oms-feature-return-details-lazy
|
||||
|
||||
@@ -1,151 +1,157 @@
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
computed,
|
||||
inject,
|
||||
resource,
|
||||
} from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { toSignal } from '@angular/core/rxjs-interop';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { NgIconComponent, provideIcons } from '@ng-icons/core';
|
||||
import { isaActionChevronLeft } from '@isa/icons';
|
||||
import { ButtonComponent } from '@isa/ui/buttons';
|
||||
import { injectActivatedTabId } from '@isa/core/tabs';
|
||||
import { Location } from '@angular/common';
|
||||
import { ExpandableDirectives } from '@isa/ui/expandable';
|
||||
import { ProgressBarComponent } from '@isa/ui/progress-bar';
|
||||
import {
|
||||
ReturnDetailsService,
|
||||
ReturnProcessStore,
|
||||
ReturnDetailsStore,
|
||||
} from '@isa/oms/data-access';
|
||||
import { ReturnDetailsStaticComponent } from './return-details-static/return-details-static.component';
|
||||
import { ReturnDetailsLazyComponent } from './return-details-lazy/return-details-lazy.component';
|
||||
import { logger } from '@isa/core/logging';
|
||||
import { groupBy } from 'lodash';
|
||||
|
||||
@Component({
|
||||
selector: 'oms-feature-return-details',
|
||||
templateUrl: './return-details.component.html',
|
||||
styleUrls: ['./return-details.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
imports: [
|
||||
ReturnDetailsStaticComponent,
|
||||
ReturnDetailsLazyComponent,
|
||||
NgIconComponent,
|
||||
ButtonComponent,
|
||||
ExpandableDirectives,
|
||||
ProgressBarComponent,
|
||||
],
|
||||
providers: [provideIcons({ isaActionChevronLeft }), ReturnDetailsStore],
|
||||
})
|
||||
export class ReturnDetailsComponent {
|
||||
#logger = logger(() => ({
|
||||
component: 'ReturnDetailsComponent',
|
||||
itemId: this.receiptId(),
|
||||
processId: this.processId(),
|
||||
params: this.params(),
|
||||
}));
|
||||
#store = inject(ReturnDetailsStore);
|
||||
#returnDetailsService = inject(ReturnDetailsService);
|
||||
#returnProcessStore = inject(ReturnProcessStore);
|
||||
|
||||
private processId = injectActivatedTabId();
|
||||
|
||||
private _router = inject(Router);
|
||||
|
||||
private _activatedRoute = inject(ActivatedRoute);
|
||||
|
||||
location = inject(Location);
|
||||
|
||||
params = toSignal(this._activatedRoute.params);
|
||||
|
||||
receiptId = computed<number>(() => {
|
||||
const params = this.params();
|
||||
if (params) {
|
||||
return z.coerce.number().parse(params['receiptId']);
|
||||
}
|
||||
throw new Error('No receiptId found in route params');
|
||||
});
|
||||
|
||||
receiptResource = this.#store.receiptResource(this.receiptId);
|
||||
|
||||
customerReceiptsResource = resource({
|
||||
params: this.receiptResource.value,
|
||||
loader: async ({ params, abortSignal }) => {
|
||||
const email = params.buyer?.communicationDetails?.email;
|
||||
if (!email) {
|
||||
return [];
|
||||
}
|
||||
return await this.#returnDetailsService.fetchReceiptsByEmail(
|
||||
{ email },
|
||||
abortSignal,
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
canStartProcess = computed(() => {
|
||||
return (
|
||||
this.#store.selectedItemIds().length > 0 && this.processId() !== undefined
|
||||
);
|
||||
});
|
||||
|
||||
startProcess() {
|
||||
if (!this.canStartProcess()) {
|
||||
this.#logger.warn(
|
||||
'Cannot start process: No items selected or no process ID',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const processId = this.processId();
|
||||
const selectedItems = this.#store.selectedItems();
|
||||
const selectedQuantites = this.#store.selectedQuantityMap();
|
||||
const selectedProductCategories = this.#store.itemCategoryMap();
|
||||
|
||||
this.#logger.info('Starting return process', () => ({
|
||||
processId: processId,
|
||||
selectedItems: selectedItems.map((item) => item.id),
|
||||
}));
|
||||
|
||||
if (!selectedItems.length || !processId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const itemsGrouptByReceiptId = groupBy(
|
||||
selectedItems,
|
||||
(item) => item.receipt?.id,
|
||||
);
|
||||
const receipts = this.#store.receiptsEntityMap();
|
||||
|
||||
const returns = Object.entries(itemsGrouptByReceiptId).map(
|
||||
([receiptId, items]) => ({
|
||||
receipt: receipts[Number(receiptId)],
|
||||
items: items.map((item) => {
|
||||
const receiptItem = item;
|
||||
return {
|
||||
receiptItem,
|
||||
quantity: selectedQuantites[receiptItem.id],
|
||||
category: selectedProductCategories[receiptItem.id],
|
||||
};
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
this.#logger.info('Starting return process with returns', () => ({
|
||||
processId,
|
||||
returns,
|
||||
}));
|
||||
|
||||
this.#returnProcessStore.startProcess({
|
||||
processId,
|
||||
returns,
|
||||
});
|
||||
|
||||
this._router.navigate(['../../', 'process'], {
|
||||
relativeTo: this._activatedRoute,
|
||||
});
|
||||
}
|
||||
}
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
computed,
|
||||
inject,
|
||||
resource,
|
||||
} from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { toSignal } from '@angular/core/rxjs-interop';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { NgIconComponent, provideIcons } from '@ng-icons/core';
|
||||
import { isaActionChevronLeft } from '@isa/icons';
|
||||
import { ButtonComponent } from '@isa/ui/buttons';
|
||||
import { injectTabId } from '@isa/core/tabs';
|
||||
import { Location } from '@angular/common';
|
||||
import { ExpandableDirectives } from '@isa/ui/expandable';
|
||||
import { ProgressBarComponent } from '@isa/ui/progress-bar';
|
||||
import {
|
||||
ReturnDetailsService,
|
||||
ReturnProcessStore,
|
||||
ReturnDetailsStore,
|
||||
} from '@isa/oms/data-access';
|
||||
import { ReturnDetailsStaticComponent } from './return-details-static/return-details-static.component';
|
||||
import { ReturnDetailsLazyComponent } from './return-details-lazy/return-details-lazy.component';
|
||||
import { logger } from '@isa/core/logging';
|
||||
import { groupBy } from 'lodash';
|
||||
|
||||
@Component({
|
||||
selector: 'oms-feature-return-details',
|
||||
templateUrl: './return-details.component.html',
|
||||
styleUrls: ['./return-details.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
imports: [
|
||||
ReturnDetailsStaticComponent,
|
||||
ReturnDetailsLazyComponent,
|
||||
NgIconComponent,
|
||||
ButtonComponent,
|
||||
ExpandableDirectives,
|
||||
ProgressBarComponent,
|
||||
],
|
||||
providers: [provideIcons({ isaActionChevronLeft }), ReturnDetailsStore],
|
||||
})
|
||||
export class ReturnDetailsComponent {
|
||||
#logger = logger(() => ({
|
||||
component: 'ReturnDetailsComponent',
|
||||
itemId: this.receiptId(),
|
||||
processId: this.processId(),
|
||||
params: this.params(),
|
||||
}));
|
||||
#store = inject(ReturnDetailsStore);
|
||||
#returnDetailsService = inject(ReturnDetailsService);
|
||||
#returnProcessStore = inject(ReturnProcessStore);
|
||||
|
||||
private processId = injectTabId();
|
||||
|
||||
private _router = inject(Router);
|
||||
|
||||
private _activatedRoute = inject(ActivatedRoute);
|
||||
|
||||
location = inject(Location);
|
||||
|
||||
params = toSignal(this._activatedRoute.params);
|
||||
|
||||
receiptId = computed<number>(() => {
|
||||
const params = this.params();
|
||||
if (params) {
|
||||
return z.coerce.number().parse(params['receiptId']);
|
||||
}
|
||||
throw new Error('No receiptId found in route params');
|
||||
});
|
||||
|
||||
receiptResource = this.#store.receiptResource(this.receiptId);
|
||||
|
||||
customerReceiptsResource = resource({
|
||||
params: this.receiptResource.value,
|
||||
loader: async ({ params, abortSignal }) => {
|
||||
const email = params.buyer?.communicationDetails?.email;
|
||||
if (!email) {
|
||||
return [];
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.#returnDetailsService.fetchReceiptsByEmail(
|
||||
{ email },
|
||||
abortSignal,
|
||||
);
|
||||
} catch (error) {
|
||||
this.#logger.error('Failed to fetch customer receipts', error);
|
||||
return [];
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
canStartProcess = computed(() => {
|
||||
return (
|
||||
this.#store.selectedItemIds().length > 0 && this.processId() !== undefined
|
||||
);
|
||||
});
|
||||
|
||||
startProcess() {
|
||||
if (!this.canStartProcess()) {
|
||||
this.#logger.warn(
|
||||
'Cannot start process: No items selected or no process ID',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const processId = this.processId();
|
||||
const selectedItems = this.#store.selectedItems();
|
||||
const selectedQuantites = this.#store.selectedQuantityMap();
|
||||
const selectedProductCategories = this.#store.itemCategoryMap();
|
||||
|
||||
this.#logger.info('Starting return process', () => ({
|
||||
processId: processId,
|
||||
selectedItems: selectedItems.map((item) => item.id),
|
||||
}));
|
||||
|
||||
if (!selectedItems.length || !processId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const itemsGrouptByReceiptId = groupBy(
|
||||
selectedItems,
|
||||
(item) => item.receipt?.id,
|
||||
);
|
||||
const receipts = this.#store.receiptsEntityMap();
|
||||
|
||||
const returns = Object.entries(itemsGrouptByReceiptId).map(
|
||||
([receiptId, items]) => ({
|
||||
receipt: receipts[Number(receiptId)],
|
||||
items: items.map((item) => {
|
||||
const receiptItem = item;
|
||||
return {
|
||||
receiptItem,
|
||||
quantity: selectedQuantites[receiptItem.id],
|
||||
category: selectedProductCategories[receiptItem.id],
|
||||
};
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
this.#logger.info('Starting return process with returns', () => ({
|
||||
processId,
|
||||
returns,
|
||||
}));
|
||||
|
||||
this.#returnProcessStore.startProcess({
|
||||
processId,
|
||||
returns,
|
||||
});
|
||||
|
||||
this._router.navigate(['../../', 'process'], {
|
||||
relativeTo: this._activatedRoute,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,7 @@ import {
|
||||
signal,
|
||||
viewChild,
|
||||
} from '@angular/core';
|
||||
import {
|
||||
AbstractControl,
|
||||
FormControl,
|
||||
ReactiveFormsModule,
|
||||
ValidationErrors,
|
||||
ValidatorFn,
|
||||
Validators,
|
||||
} from '@angular/forms';
|
||||
import { FormControl, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import {
|
||||
Product,
|
||||
ReturnProcessProductQuestion,
|
||||
@@ -39,16 +32,7 @@ import { isaActionScanner } from '@isa/icons';
|
||||
import { ScannerButtonComponent } from '@isa/shared/scanner';
|
||||
import { ProductRouterLinkDirective } from '@isa/shared/product-router-link';
|
||||
import { toSignal } from '@angular/core/rxjs-interop';
|
||||
|
||||
const eanValidator: ValidatorFn = (
|
||||
control: AbstractControl,
|
||||
): ValidationErrors | null => {
|
||||
const value = control.value;
|
||||
if (value && !/^[0-9]{13}$/.test(value)) {
|
||||
return { invalidEan: true };
|
||||
}
|
||||
return null;
|
||||
};
|
||||
import { eanValidator } from '@isa/utils/ean-validation';
|
||||
|
||||
@Component({
|
||||
selector: 'oms-feature-return-process-product-question',
|
||||
|
||||
@@ -21,7 +21,7 @@ import { ReturnProcessComponent } from './return-process.component';
|
||||
|
||||
const mockActivatedProcessIdSignal = signal<number | null>(123);
|
||||
jest.mock('@isa/core/tabs', () => ({
|
||||
injectActivatedTabId: jest.fn(() => mockActivatedProcessIdSignal),
|
||||
injectTabId: jest.fn(() => mockActivatedProcessIdSignal),
|
||||
}));
|
||||
|
||||
jest.mock('scandit-web-datacapture-core', () => ({}));
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
ReturnProcessService,
|
||||
ReturnProcessStore,
|
||||
} from '@isa/oms/data-access';
|
||||
import { injectActivatedTabId } from '@isa/core/tabs';
|
||||
import { injectTabId } from '@isa/core/tabs';
|
||||
import { ReturnProcessItemComponent } from './return-process-item/return-process-item.component';
|
||||
import { Location } from '@angular/common';
|
||||
import { RouterLink } from '@angular/router';
|
||||
@@ -58,7 +58,7 @@ export class ReturnProcessComponent {
|
||||
#logger = logger();
|
||||
|
||||
/** Signal emitting the numeric ID of the currently active return process, derived from the route parameters. Null if no ID is present. */
|
||||
processId = injectActivatedTabId();
|
||||
processId = injectTabId();
|
||||
|
||||
#returnCanReturnService = inject(ReturnCanReturnService);
|
||||
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
import { computed, inject, Injectable } from '@angular/core';
|
||||
import { CanDeactivate } from '@angular/router';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { injectActivatedTabId } from '@isa/core/tabs';
|
||||
import { injectTabId } from '@isa/core/tabs';
|
||||
import { ReturnTaskListStore } from '@isa/oms/data-access';
|
||||
import { ReturnReviewComponent } from '../return-review.component';
|
||||
import { ConfirmationDialogComponent, injectDialog } from '@isa/ui/dialog';
|
||||
import { injectConfirmationDialog } from '@isa/ui/dialog';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class UncompletedTasksGuard
|
||||
implements CanDeactivate<ReturnReviewComponent>
|
||||
{
|
||||
#returnTaskListStore = inject(ReturnTaskListStore);
|
||||
#confirmationDialog = injectDialog(ConfirmationDialogComponent, {
|
||||
title: 'Aufgaben erledigen',
|
||||
});
|
||||
#confirmationDialog = injectConfirmationDialog();
|
||||
|
||||
processId = injectActivatedTabId();
|
||||
processId = injectTabId();
|
||||
|
||||
uncompletedTaskListItems = computed(() => {
|
||||
const processId = this.processId();
|
||||
@@ -45,6 +43,7 @@ export class UncompletedTasksGuard
|
||||
|
||||
async openDialog(): Promise<boolean> {
|
||||
const confirmDialogRef = this.#confirmationDialog({
|
||||
title: 'Aufgaben erledigen',
|
||||
data: {
|
||||
message:
|
||||
'Bitte schließen Sie die Aufgaben ab bevor Sie das die Rückgabe verlassen',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
|
||||
import { PrintReceiptsService, ReturnProcessStore } from '@isa/oms/data-access';
|
||||
import { injectActivatedTabId } from '@isa/core/tabs';
|
||||
import { injectTabId } from '@isa/core/tabs';
|
||||
import { ReturnTaskListComponent } from '@isa/oms/shared/task-list';
|
||||
import { ReturnReviewHeaderComponent } from './return-review-header/return-review-header.component';
|
||||
|
||||
@@ -15,7 +15,7 @@ import { ReturnReviewHeaderComponent } from './return-review-header/return-revie
|
||||
export class ReturnReviewComponent {
|
||||
#printReceiptsService = inject(PrintReceiptsService);
|
||||
#returnProcessStore = inject(ReturnProcessStore);
|
||||
processId = injectActivatedTabId();
|
||||
processId = injectTabId();
|
||||
|
||||
async printReceipt() {
|
||||
const processId = this.processId();
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
} from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { CallbackResult, ListResponseArgs } from '@isa/common/data-access';
|
||||
import { injectActivatedTabId } from '@isa/core/tabs';
|
||||
import { injectTabId } from '@isa/core/tabs';
|
||||
import {
|
||||
ReceiptListItem,
|
||||
ReturnSearchStatus,
|
||||
@@ -38,7 +38,7 @@ export class ReturnSearchMainComponent {
|
||||
#route = inject(ActivatedRoute);
|
||||
#router = inject(Router);
|
||||
|
||||
private _processId = injectActivatedTabId();
|
||||
private _processId = injectTabId();
|
||||
private _filterService = inject(FilterService);
|
||||
private _returnSearchStore = inject(ReturnSearchStore);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
inject,
|
||||
linkedSignal,
|
||||
} from '@angular/core';
|
||||
import { injectActivatedTabId } from '@isa/core/tabs';
|
||||
import { injectTabId } from '@isa/core/tabs';
|
||||
|
||||
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
||||
import {
|
||||
@@ -72,7 +72,7 @@ export class ReturnSearchResultComponent implements AfterViewInit {
|
||||
restoreScrollPosition = injectRestoreScrollPosition();
|
||||
|
||||
/** Current process ID from the activated route */
|
||||
processId = injectActivatedTabId();
|
||||
processId = injectTabId();
|
||||
|
||||
/** Store for managing return search data and operations */
|
||||
returnSearchStore = inject(ReturnSearchStore);
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
name="isaActionEdit"
|
||||
data-what="button"
|
||||
data-which="edit-return-item"
|
||||
(click)="navigateBack()"
|
||||
[disabled]="returnItemsAndPrintReciptPending()"
|
||||
(click)="location.back()"
|
||||
></ui-icon-button>
|
||||
</div>
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { createRoutingFactory, Spectator } from '@ngneat/spectator/jest';
|
||||
import { ReturnSummaryItemComponent } from './return-summary-item.component';
|
||||
import { MockComponents, MockProvider } from 'ng-mocks';
|
||||
import { ReturnProductInfoComponent } from '@isa/oms/shared/product-info';
|
||||
import { createRoutingFactory, Spectator } from "@ngneat/spectator/jest";
|
||||
import { ReturnSummaryItemComponent } from "./return-summary-item.component";
|
||||
import { MockComponents, MockProvider } from "ng-mocks";
|
||||
import { ReturnProductInfoComponent } from "@isa/oms/shared/product-info";
|
||||
import {
|
||||
Product,
|
||||
ReturnProcess,
|
||||
ReturnProcessQuestionKey,
|
||||
ReturnProcessService,
|
||||
} from '@isa/oms/data-access';
|
||||
import { NgIcon } from '@ng-icons/core';
|
||||
import { IconButtonComponent } from '@isa/ui/buttons';
|
||||
import { Router } from '@angular/router';
|
||||
} from "@isa/oms/data-access";
|
||||
import { NgIcon } from "@ng-icons/core";
|
||||
import { IconButtonComponent } from "@isa/ui/buttons";
|
||||
import { Location } from "@angular/common";
|
||||
|
||||
/**
|
||||
* Creates a mock ReturnProcess with default values that can be overridden
|
||||
@@ -21,20 +21,20 @@ function createMockReturnProcess(
|
||||
return {
|
||||
id: 1,
|
||||
processId: 1,
|
||||
productCategory: 'Electronics',
|
||||
productCategory: "Electronics",
|
||||
answers: {},
|
||||
receiptId: 123,
|
||||
receiptItem: {
|
||||
id: 321,
|
||||
product: {
|
||||
name: 'Test Product',
|
||||
name: "Test Product",
|
||||
},
|
||||
},
|
||||
...partial,
|
||||
} as ReturnProcess;
|
||||
}
|
||||
|
||||
describe('ReturnSummaryItemComponent', () => {
|
||||
describe("ReturnSummaryItemComponent", () => {
|
||||
let spectator: Spectator<ReturnSummaryItemComponent>;
|
||||
let returnProcessService: jest.Mocked<ReturnProcessService>;
|
||||
|
||||
@@ -48,7 +48,10 @@ describe('ReturnSummaryItemComponent', () => {
|
||||
providers: [
|
||||
MockProvider(ReturnProcessService, {
|
||||
getReturnInfo: jest.fn(),
|
||||
eligibleForReturn: jest.fn().mockReturnValue({ state: 'eligible' }),
|
||||
eligibleForReturn: jest.fn().mockReturnValue({ state: "eligible" }),
|
||||
}),
|
||||
MockProvider(Location, {
|
||||
back: jest.fn(),
|
||||
}),
|
||||
],
|
||||
shallow: true,
|
||||
@@ -64,38 +67,38 @@ describe('ReturnSummaryItemComponent', () => {
|
||||
spectator.detectChanges();
|
||||
});
|
||||
|
||||
describe('Component Creation', () => {
|
||||
it('should create the component', () => {
|
||||
describe("Component Creation", () => {
|
||||
it("should create the component", () => {
|
||||
expect(spectator.component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Return Information Display', () => {
|
||||
describe("Return Information Display", () => {
|
||||
const mockReturnInfo = {
|
||||
itemCondition: 'itemCondition',
|
||||
returnDetails: { [ReturnProcessQuestionKey.CaseDamaged]: 'no' },
|
||||
returnReason: 'returnReason',
|
||||
itemCondition: "itemCondition",
|
||||
returnDetails: { [ReturnProcessQuestionKey.CaseDamaged]: "no" },
|
||||
returnReason: "returnReason",
|
||||
otherProduct: {
|
||||
ean: 'ean',
|
||||
ean: "ean",
|
||||
} as Product,
|
||||
comment: 'comment',
|
||||
comment: "comment",
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest
|
||||
.spyOn(returnProcessService, 'getReturnInfo')
|
||||
.spyOn(returnProcessService, "getReturnInfo")
|
||||
.mockReturnValue(mockReturnInfo);
|
||||
spectator.setInput('returnProcess', createMockReturnProcess({ id: 2 }));
|
||||
spectator.setInput("returnProcess", createMockReturnProcess({ id: 2 }));
|
||||
spectator.detectChanges();
|
||||
});
|
||||
it('should provide correct return information array', () => {
|
||||
it("should provide correct return information array", () => {
|
||||
// Arrange
|
||||
const expectedInfos = [
|
||||
'itemCondition',
|
||||
'returnReason',
|
||||
'Gehäuse beschädigt: no',
|
||||
'Geliefert wurde: ean',
|
||||
'comment',
|
||||
"itemCondition",
|
||||
"returnReason",
|
||||
"Gehäuse beschädigt: no",
|
||||
"Geliefert wurde: ean",
|
||||
"comment",
|
||||
];
|
||||
|
||||
// Act
|
||||
@@ -105,14 +108,14 @@ describe('ReturnSummaryItemComponent', () => {
|
||||
expect(actualInfos).toEqual(expectedInfos);
|
||||
expect(actualInfos.length).toBe(5);
|
||||
});
|
||||
it('should render return info items with correct content', () => {
|
||||
it("should render return info items with correct content", () => {
|
||||
// Arrange
|
||||
const expectedInfos = [
|
||||
'itemCondition',
|
||||
'returnReason',
|
||||
'Gehäuse beschädigt: no',
|
||||
'Geliefert wurde: ean',
|
||||
'comment',
|
||||
"itemCondition",
|
||||
"returnReason",
|
||||
"Gehäuse beschädigt: no",
|
||||
"Geliefert wurde: ean",
|
||||
"comment",
|
||||
];
|
||||
|
||||
// Act
|
||||
@@ -125,14 +128,14 @@ describe('ReturnSummaryItemComponent', () => {
|
||||
expect(listItems.length).toBe(expectedInfos.length);
|
||||
listItems.forEach((item, index) => {
|
||||
expect(item).toHaveText(expectedInfos[index]);
|
||||
expect(item).toHaveAttribute('data-info-index', index.toString());
|
||||
expect(item).toHaveAttribute("data-info-index", index.toString());
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle undefined return info gracefully', () => {
|
||||
it("should handle undefined return info gracefully", () => {
|
||||
// Arrange
|
||||
returnProcessService.getReturnInfo.mockReturnValue(undefined);
|
||||
spectator.setInput('returnProcess', createMockReturnProcess({ id: 3 }));
|
||||
spectator.setInput("returnProcess", createMockReturnProcess({ id: 3 }));
|
||||
spectator.detectChanges();
|
||||
|
||||
// Act
|
||||
@@ -146,26 +149,26 @@ describe('ReturnSummaryItemComponent', () => {
|
||||
expect(listItems.length).toBe(0);
|
||||
});
|
||||
|
||||
describe('returnDetails mapping', () => {
|
||||
it('should map multiple returnDetails keys to correct info strings', () => {
|
||||
describe("returnDetails mapping", () => {
|
||||
it("should map multiple returnDetails keys to correct info strings", () => {
|
||||
const expected = [
|
||||
'itemCondition',
|
||||
'returnReason',
|
||||
'Gehäuse beschädigt: Ja',
|
||||
'Display beschädigt: Nein',
|
||||
'Geliefert wurde: ean',
|
||||
'comment',
|
||||
"itemCondition",
|
||||
"returnReason",
|
||||
"Gehäuse beschädigt: Ja",
|
||||
"Display beschädigt: Nein",
|
||||
"Geliefert wurde: ean",
|
||||
"comment",
|
||||
];
|
||||
// Arrange
|
||||
const details = {
|
||||
[ReturnProcessQuestionKey.CaseDamaged]: 'Ja',
|
||||
[ReturnProcessQuestionKey.DisplayDamaged]: 'Nein',
|
||||
[ReturnProcessQuestionKey.CaseDamaged]: "Ja",
|
||||
[ReturnProcessQuestionKey.DisplayDamaged]: "Nein",
|
||||
};
|
||||
returnProcessService.getReturnInfo.mockReturnValue({
|
||||
...mockReturnInfo,
|
||||
returnDetails: details,
|
||||
});
|
||||
spectator.setInput('returnProcess', createMockReturnProcess({ id: 4 }));
|
||||
spectator.setInput("returnProcess", createMockReturnProcess({ id: 4 }));
|
||||
spectator.detectChanges();
|
||||
|
||||
// Act
|
||||
@@ -173,31 +176,31 @@ describe('ReturnSummaryItemComponent', () => {
|
||||
expect(infos).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should not include returnDetails if empty', () => {
|
||||
it("should not include returnDetails if empty", () => {
|
||||
// Arrange
|
||||
returnProcessService.getReturnInfo.mockReturnValue({
|
||||
...mockReturnInfo,
|
||||
returnDetails: {},
|
||||
});
|
||||
spectator.setInput('returnProcess', createMockReturnProcess({ id: 5 }));
|
||||
spectator.setInput("returnProcess", createMockReturnProcess({ id: 5 }));
|
||||
spectator.detectChanges();
|
||||
|
||||
// Act
|
||||
const infos = spectator.component.returnInfos();
|
||||
|
||||
// Assert
|
||||
expect(infos.some((info) => info.includes('Gehäuse beschädigt'))).toBe(
|
||||
expect(infos.some((info) => info.includes("Gehäuse beschädigt"))).toBe(
|
||||
false,
|
||||
);
|
||||
expect(infos.some((info) => info.includes('Zubehör fehlt'))).toBe(
|
||||
expect(infos.some((info) => info.includes("Zubehör fehlt"))).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Navigation', () => {
|
||||
it('should render edit button with correct attributes', () => {
|
||||
describe("Navigation", () => {
|
||||
it("should render edit button with correct attributes", () => {
|
||||
// Assert
|
||||
const editButton = spectator.query(
|
||||
'[data-what="button"][data-which="edit-return-item"]',
|
||||
@@ -205,7 +208,7 @@ describe('ReturnSummaryItemComponent', () => {
|
||||
expect(editButton).toExist();
|
||||
});
|
||||
|
||||
it('should navigate back when edit button is clicked', () => {
|
||||
it("should navigate back when edit button is clicked", () => {
|
||||
// Arrange
|
||||
const editButton = spectator.query(
|
||||
'[data-what="button"][data-which="edit-return-item"]',
|
||||
@@ -217,25 +220,20 @@ describe('ReturnSummaryItemComponent', () => {
|
||||
}
|
||||
|
||||
// Assert
|
||||
expect(spectator.inject(Router).navigate).toHaveBeenCalledWith(
|
||||
['..'],
|
||||
expect.objectContaining({
|
||||
relativeTo: expect.anything(),
|
||||
}),
|
||||
);
|
||||
expect(spectator.inject(Location).back).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should render the product info component', () => {
|
||||
it("should render the product info component", () => {
|
||||
const productInfo = spectator.query(ReturnProductInfoComponent);
|
||||
expect(productInfo).toExist();
|
||||
});
|
||||
|
||||
it('should compute eligibility state as eligible', () => {
|
||||
it("should compute eligibility state as eligible", () => {
|
||||
(returnProcessService.eligibleForReturn as jest.Mock).mockReturnValue({
|
||||
state: 'eligible',
|
||||
state: "eligible",
|
||||
});
|
||||
spectator.detectChanges();
|
||||
expect(spectator.component.eligibleForReturn()?.state).toBe('eligible');
|
||||
expect(spectator.component.eligibleForReturn()?.state).toBe("eligible");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,13 +4,13 @@ import {
|
||||
computed,
|
||||
inject,
|
||||
input,
|
||||
} from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
} from "@angular/core";
|
||||
import { Location } from "@angular/common";
|
||||
import {
|
||||
isaActionChevronRight,
|
||||
isaActionClose,
|
||||
isaActionEdit,
|
||||
} from '@isa/icons';
|
||||
} from "@isa/icons";
|
||||
import {
|
||||
EligibleForReturn,
|
||||
EligibleForReturnState,
|
||||
@@ -18,10 +18,10 @@ import {
|
||||
ReturnProcessService,
|
||||
ProductCategory,
|
||||
returnDetailsMapping,
|
||||
} from '@isa/oms/data-access';
|
||||
import { ReturnProductInfoComponent } from '@isa/oms/shared/product-info';
|
||||
import { IconButtonComponent } from '@isa/ui/buttons';
|
||||
import { NgIcon, provideIcons } from '@ng-icons/core';
|
||||
} from "@isa/oms/data-access";
|
||||
import { ReturnProductInfoComponent } from "@isa/oms/shared/product-info";
|
||||
import { IconButtonComponent } from "@isa/ui/buttons";
|
||||
import { NgIcon, provideIcons } from "@ng-icons/core";
|
||||
|
||||
/**
|
||||
* Displays a single item in the return process summary, showing product details
|
||||
@@ -47,30 +47,34 @@ import { NgIcon, provideIcons } from '@ng-icons/core';
|
||||
* ```
|
||||
*/
|
||||
@Component({
|
||||
selector: 'oms-feature-return-summary-item',
|
||||
templateUrl: './return-summary-item.component.html',
|
||||
styleUrls: ['./return-summary-item.component.scss'],
|
||||
selector: "oms-feature-return-summary-item",
|
||||
templateUrl: "./return-summary-item.component.html",
|
||||
styleUrls: ["./return-summary-item.component.scss"],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
imports: [ReturnProductInfoComponent, NgIcon, IconButtonComponent],
|
||||
providers: [
|
||||
provideIcons({ isaActionChevronRight, isaActionEdit, isaActionClose }),
|
||||
],
|
||||
host: {
|
||||
'data-what': 'list-item',
|
||||
'data-which': 'return-process-item',
|
||||
'[attr.data-receipt-id]': 'returnProcess()?.receiptId',
|
||||
'[attr.data-return-item-id]': 'returnProcess()?.returnItem?.id',
|
||||
"data-what": "list-item",
|
||||
"data-which": "return-process-item",
|
||||
"[attr.data-receipt-id]": "returnProcess()?.receiptId",
|
||||
"[attr.data-return-item-id]": "returnProcess()?.returnItem?.id",
|
||||
},
|
||||
})
|
||||
export class ReturnSummaryItemComponent {
|
||||
EligibleForReturnState = EligibleForReturnState;
|
||||
#returnProcessService = inject(ReturnProcessService);
|
||||
#router = inject(Router);
|
||||
#activatedRoute = inject(ActivatedRoute);
|
||||
|
||||
/** Angular Location service for navigation */
|
||||
location = inject(Location);
|
||||
|
||||
/** The return process object containing all information about the return */
|
||||
returnProcess = input.required<ReturnProcess>();
|
||||
|
||||
/** The status of the return items and print receipt operation */
|
||||
returnItemsAndPrintReciptPending = input<boolean>(false);
|
||||
|
||||
/**
|
||||
* Computes whether the current return process is eligible for return.
|
||||
*
|
||||
@@ -149,8 +153,4 @@ export class ReturnSummaryItemComponent {
|
||||
// remove duplicates
|
||||
return Array.from(new Set(result));
|
||||
});
|
||||
|
||||
navigateBack() {
|
||||
this.#router.navigate(['..'], { relativeTo: this.#activatedRoute });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
color="tertiary"
|
||||
size="small"
|
||||
class="px-[0.875rem] py-1 min-w-0 bg-white gap-1 absolute top-0 left-0"
|
||||
[disabled]="returnItemsAndPrintReciptStatusPending()"
|
||||
(click)="location.back()"
|
||||
>
|
||||
<ng-icon name="isaActionChevronLeft" size="1.5rem" class="-ml-2"></ng-icon>
|
||||
@@ -28,19 +29,22 @@
|
||||
data-which="return-process-item"
|
||||
[attr.data-item-id]="item.id"
|
||||
[attr.data-item-category]="item.productCategory"
|
||||
[returnItemsAndPrintReciptPending]="
|
||||
returnItemsAndPrintReciptStatusPending()
|
||||
"
|
||||
></oms-feature-return-summary-item>
|
||||
}
|
||||
</div>
|
||||
<div class="mt-6 text-center">
|
||||
@if (returnItemsAndPrintReciptStatus() !== 'success') {
|
||||
@if (returnItemsAndPrintReciptStatus() !== "success") {
|
||||
<button
|
||||
type="button"
|
||||
size="large"
|
||||
uiButton
|
||||
color="brand"
|
||||
(click)="returnItemsAndPrintRecipt()"
|
||||
[pending]="returnItemsAndPrintReciptStatus() === 'pending'"
|
||||
[disabled]="returnItemsAndPrintReciptStatus() === 'pending'"
|
||||
[pending]="returnItemsAndPrintReciptStatusPending()"
|
||||
[disabled]="returnItemsAndPrintReciptStatusPending()"
|
||||
data-what="button"
|
||||
data-which="return-and-print"
|
||||
>
|
||||
|
||||
@@ -10,7 +10,7 @@ import { ReturnSummaryItemComponent } from './return-summary-item/return-summary
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
jest.mock('@isa/core/tabs', () => ({
|
||||
injectActivatedTabId: () => jest.fn(() => 1),
|
||||
injectTabId: () => jest.fn(() => 1),
|
||||
}));
|
||||
|
||||
const MOCK_RETURN_PROCESSES: ReturnProcess[] = [
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
signal,
|
||||
} from '@angular/core';
|
||||
import { ReturnSummaryItemComponent } from './return-summary-item/return-summary-item.component';
|
||||
import { injectActivatedTabId } from '@isa/core/tabs';
|
||||
import { injectTabId } from '@isa/core/tabs';
|
||||
import {
|
||||
ReturnProcess,
|
||||
ReturnProcessService,
|
||||
@@ -55,7 +55,7 @@ export class ReturnSummaryComponent {
|
||||
location = inject(Location);
|
||||
|
||||
/** The active process ID from the current route */
|
||||
processId = injectActivatedTabId();
|
||||
processId = injectTabId();
|
||||
|
||||
/** Filtered list of return processes for the current process ID */
|
||||
returnProcesses = computed<ReturnProcess[]>(() => {
|
||||
@@ -78,9 +78,17 @@ export class ReturnSummaryComponent {
|
||||
>(undefined);
|
||||
|
||||
/**
|
||||
* Handles the return and print process for multiple items.
|
||||
* Computed signal to determine if the return items and print receipt operation is pending.
|
||||
*
|
||||
* This method:
|
||||
* This signal checks the current status of the returnItemsAndPrintReciptStatus signal
|
||||
* and returns true if the status is 'pending', otherwise false.
|
||||
*
|
||||
* @returns {boolean} True if the operation is pending, false otherwise
|
||||
*/
|
||||
returnItemsAndPrintReciptStatusPending = computed(() => {
|
||||
return this.returnItemsAndPrintReciptStatus() === 'pending';
|
||||
});
|
||||
/**
|
||||
* 1. Checks if a return process is already in progress
|
||||
* 2. Sets status to pending while processing
|
||||
* 3. Calls the ReturnProcessService to complete the return
|
||||
@@ -118,9 +126,13 @@ export class ReturnSummaryComponent {
|
||||
relativeTo: this.#activatedRoute,
|
||||
});
|
||||
} catch (error) {
|
||||
this.#logger.error('Error completing return process', error as Error, () => ({
|
||||
function: 'returnItemsAndPrintRecipt',
|
||||
}));
|
||||
this.#logger.error(
|
||||
'Error completing return process',
|
||||
error as Error,
|
||||
() => ({
|
||||
function: 'returnItemsAndPrintRecipt',
|
||||
}),
|
||||
);
|
||||
this.returnItemsAndPrintReciptStatus.set('error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
} from '@isa/oms/data-access';
|
||||
import { IconButtonComponent } from '@isa/ui/buttons';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { injectActivatedTabId } from '@isa/core/tabs';
|
||||
import { injectTabId } from '@isa/core/tabs';
|
||||
import { logger, provideLoggerContext } from '@isa/core/logging';
|
||||
|
||||
// TODO: Komponente und logik benötigt review
|
||||
@@ -45,7 +45,7 @@ export class ReturnTaskListComponent {
|
||||
#returnTaskListStore = inject(ReturnTaskListStore);
|
||||
#logger = logger();
|
||||
|
||||
processId = injectActivatedTabId();
|
||||
processId = injectTabId();
|
||||
|
||||
appearanceClass = computed(
|
||||
() => `oms-shared-return-task-list__${this.appearance()}`,
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
export * from './lib/services';
|
||||
export * from './lib/schemas';
|
||||
export * from './lib/models';
|
||||
export * from './lib/services';
|
||||
export * from './lib/models';
|
||||
export * from './lib/stores';
|
||||
export * from './lib/schemas';
|
||||
export * from './lib/helpers';
|
||||
export * from './lib/guards';
|
||||
|
||||
2
libs/remission/data-access/src/lib/guards/index.ts
Normal file
2
libs/remission/data-access/src/lib/guards/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { isReturnItem } from './is-return-item';
|
||||
export { isReturnSuggestion } from './is-return-suggestion';
|
||||
42
libs/remission/data-access/src/lib/guards/is-return-item.ts
Normal file
42
libs/remission/data-access/src/lib/guards/is-return-item.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { ReturnItem } from '../models/return-item';
|
||||
|
||||
/**
|
||||
* Type guard to check if an object is a valid ReturnItem
|
||||
* @param value - The value to check
|
||||
* @returns True if the value is a ReturnItem, false otherwise
|
||||
*/
|
||||
export const isReturnItem = (value: unknown): value is ReturnItem => {
|
||||
if (!value || typeof value !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const item = value as Partial<ReturnItem>;
|
||||
|
||||
// Check required properties from ReturnItem
|
||||
return (
|
||||
// Check product exists and has required properties
|
||||
typeof item.product === 'object' &&
|
||||
item.product !== null &&
|
||||
(typeof item.product.name === 'string' ||
|
||||
typeof item.product.ean === 'string') &&
|
||||
// Check retailPrice exists and has required nested structure
|
||||
typeof item.retailPrice === 'object' &&
|
||||
item.retailPrice !== null &&
|
||||
typeof item.retailPrice.value === 'object' &&
|
||||
item.retailPrice.value !== null &&
|
||||
typeof item.retailPrice.value.value === 'number' &&
|
||||
typeof item.retailPrice.value.currency === 'string' &&
|
||||
// Check source exists and is a valid string
|
||||
typeof item.source === 'string' &&
|
||||
item.source.length > 0 &&
|
||||
// Check inherited ReturnItemDTO properties (id is a number)
|
||||
typeof item.id === 'number' &&
|
||||
// ReturnItem-specific: Must NOT have ReturnSuggestion-specific fields
|
||||
!('accepted' in item) &&
|
||||
!('rejected' in item) &&
|
||||
!('sort' in item) &&
|
||||
// ReturnItem can have predefinedReturnQuantity, quantityReturned, or neither
|
||||
// If it has none of the ReturnSuggestion-specific fields, it's a ReturnItem
|
||||
true
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
import { ReturnSuggestion } from '../models/return-suggestion';
|
||||
|
||||
/**
|
||||
* Type guard to check if an object is a valid ReturnSuggestion
|
||||
* @param value - The value to check
|
||||
* @returns True if the value is a ReturnSuggestion, false otherwise
|
||||
*/
|
||||
export const isReturnSuggestion = (
|
||||
value: unknown,
|
||||
): value is ReturnSuggestion => {
|
||||
if (!value || typeof value !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const suggestion = value as Partial<ReturnSuggestion>;
|
||||
|
||||
// Check required properties from ReturnSuggestion
|
||||
return (
|
||||
// Check product exists and has required properties
|
||||
typeof suggestion.product === 'object' &&
|
||||
suggestion.product !== null &&
|
||||
(typeof suggestion.product.name === 'string' ||
|
||||
typeof suggestion.product.ean === 'string') &&
|
||||
// Check retailPrice exists and has required nested structure
|
||||
typeof suggestion.retailPrice === 'object' &&
|
||||
suggestion.retailPrice !== null &&
|
||||
typeof suggestion.retailPrice.value === 'object' &&
|
||||
suggestion.retailPrice.value !== null &&
|
||||
typeof suggestion.retailPrice.value.value === 'number' &&
|
||||
typeof suggestion.retailPrice.value.currency === 'string' &&
|
||||
// Check source exists and is a valid string
|
||||
typeof suggestion.source === 'string' &&
|
||||
suggestion.source.length > 0 &&
|
||||
// Check inherited ReturnSuggestionDTO properties (id is a number)
|
||||
typeof suggestion.id === 'number' &&
|
||||
// ReturnSuggestion-specific: Must have at least one distinguishing property
|
||||
('accepted' in suggestion ||
|
||||
'rejected' in suggestion ||
|
||||
'sort' in suggestion) &&
|
||||
// Additionally, must NOT have ReturnItem-specific fields
|
||||
!('predefinedReturnQuantity' in suggestion) &&
|
||||
!('quantityReturned' in suggestion)
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,80 @@
|
||||
import { calculateAvailableStock } from './calc-available-stock.helper';
|
||||
|
||||
describe('calculateAvailableStock', () => {
|
||||
it('should return stock when removedFromStock is undefined', () => {
|
||||
// Arrange
|
||||
const input = { stock: 10 };
|
||||
|
||||
// Act
|
||||
const result = calculateAvailableStock(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(10);
|
||||
});
|
||||
|
||||
it('should return 0 when stock is undefined and removedFromStock is undefined', () => {
|
||||
// Arrange
|
||||
const input = { stock: undefined };
|
||||
|
||||
// Act
|
||||
const result = calculateAvailableStock(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(0);
|
||||
});
|
||||
|
||||
it('should subtract removedFromStock from stock', () => {
|
||||
// Arrange
|
||||
const input = { stock: 20, removedFromStock: 5 };
|
||||
|
||||
// Act
|
||||
const result = calculateAvailableStock(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(15);
|
||||
});
|
||||
|
||||
it('should return 0 if result is negative', () => {
|
||||
// Arrange
|
||||
const input = { stock: 3, removedFromStock: 5 };
|
||||
|
||||
// Act
|
||||
const result = calculateAvailableStock(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(0);
|
||||
});
|
||||
|
||||
it('should treat undefined stock as 0', () => {
|
||||
// Arrange
|
||||
const input = { stock: undefined, removedFromStock: 2 };
|
||||
|
||||
// Act
|
||||
const result = calculateAvailableStock(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(0);
|
||||
});
|
||||
|
||||
it('should treat undefined removedFromStock as 0', () => {
|
||||
// Arrange
|
||||
const input = { stock: 7, removedFromStock: undefined };
|
||||
|
||||
// Act
|
||||
const result = calculateAvailableStock(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(7);
|
||||
});
|
||||
|
||||
it('should return 0 if both stock and removedFromStock are undefined', () => {
|
||||
// Arrange
|
||||
const input = { stock: undefined, removedFromStock: undefined };
|
||||
|
||||
// Act
|
||||
const result = calculateAvailableStock(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Current available stock.
|
||||
* Calculation: stock - removedFromStock
|
||||
* Returns 0 if result is negative.
|
||||
*
|
||||
* @remarks
|
||||
* Used as the base for further stock calculations.
|
||||
*/
|
||||
export const calculateAvailableStock = ({
|
||||
stock,
|
||||
removedFromStock,
|
||||
}: {
|
||||
stock: number | undefined;
|
||||
removedFromStock?: number;
|
||||
}): number => {
|
||||
const availableStock = (stock ?? 0) - (removedFromStock ?? 0);
|
||||
return availableStock < 0 ? 0 : availableStock;
|
||||
};
|
||||
@@ -0,0 +1,207 @@
|
||||
import {
|
||||
calculateCapacity,
|
||||
calculateMaxCapacity,
|
||||
} from './calc-capacity.helper';
|
||||
|
||||
describe('calculateCapacity', () => {
|
||||
it('should return capacityValue2 when it is smaller than capacityValue3', () => {
|
||||
// Arrange
|
||||
const input = { capacityValue2: 5, capacityValue3: 10 };
|
||||
|
||||
// Act
|
||||
const result = calculateCapacity(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(5);
|
||||
});
|
||||
|
||||
it('should return capacityValue3 when it is smaller than capacityValue2', () => {
|
||||
// Arrange
|
||||
const input = { capacityValue2: 15, capacityValue3: 8 };
|
||||
|
||||
// Act
|
||||
const result = calculateCapacity(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(8);
|
||||
});
|
||||
|
||||
it('should return capacityValue3 when both values are equal', () => {
|
||||
// Arrange
|
||||
const input = { capacityValue2: 10, capacityValue3: 10 };
|
||||
|
||||
// Act
|
||||
const result = calculateCapacity(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(10);
|
||||
});
|
||||
|
||||
it('should handle zero values correctly', () => {
|
||||
// Arrange
|
||||
const input = { capacityValue2: 0, capacityValue3: 5 };
|
||||
|
||||
// Act
|
||||
const result = calculateCapacity(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(0);
|
||||
});
|
||||
|
||||
it('should handle negative values correctly', () => {
|
||||
// Arrange
|
||||
const input = { capacityValue2: -3, capacityValue3: 2 };
|
||||
|
||||
// Act
|
||||
const result = calculateCapacity(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(-3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('calculateMaxCapacity', () => {
|
||||
it('should return capacityValue2 when capacityValue4 is greater than capacityValue2', () => {
|
||||
// Arrange
|
||||
const input = {
|
||||
capacityValue2: 10,
|
||||
capacityValue3: 15,
|
||||
capacityValue4: 20,
|
||||
comparer: 5,
|
||||
};
|
||||
|
||||
// Act
|
||||
const result = calculateMaxCapacity(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(10);
|
||||
});
|
||||
|
||||
it('should return capacityValue4 when it is positive and less than capacityValue2', () => {
|
||||
// Arrange
|
||||
const input = {
|
||||
capacityValue2: 10,
|
||||
capacityValue3: 15,
|
||||
capacityValue4: 8,
|
||||
comparer: 5,
|
||||
};
|
||||
|
||||
// Act
|
||||
const result = calculateMaxCapacity(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(8);
|
||||
});
|
||||
|
||||
it('should return capacityValue2 when capacityValue4 is zero and capacityValue3 is greater than capacityValue2', () => {
|
||||
// Arrange
|
||||
const input = {
|
||||
capacityValue2: 10,
|
||||
capacityValue3: 15,
|
||||
capacityValue4: 0,
|
||||
comparer: 5,
|
||||
};
|
||||
|
||||
// Act
|
||||
const result = calculateMaxCapacity(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(10);
|
||||
});
|
||||
|
||||
it('should return capacityValue3 when capacityValue4 is zero and capacityValue3 is positive and less than capacityValue2', () => {
|
||||
// Arrange
|
||||
const input = {
|
||||
capacityValue2: 10,
|
||||
capacityValue3: 8,
|
||||
capacityValue4: 0,
|
||||
comparer: 5,
|
||||
};
|
||||
|
||||
// Act
|
||||
const result = calculateMaxCapacity(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(8);
|
||||
});
|
||||
|
||||
it('should return comparer when it is greater than calculated max capacity', () => {
|
||||
// Arrange
|
||||
const input = {
|
||||
capacityValue2: 5,
|
||||
capacityValue3: 3,
|
||||
capacityValue4: 2,
|
||||
comparer: 10,
|
||||
};
|
||||
|
||||
// Act
|
||||
const result = calculateMaxCapacity(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(10);
|
||||
});
|
||||
|
||||
it('should handle undefined capacityValue4 with default value 0', () => {
|
||||
// Arrange
|
||||
const input = {
|
||||
capacityValue2: 10,
|
||||
capacityValue3: 15,
|
||||
capacityValue4: undefined,
|
||||
comparer: 5,
|
||||
};
|
||||
|
||||
// Act
|
||||
const result = calculateMaxCapacity(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(10);
|
||||
});
|
||||
|
||||
it('should handle all zero capacity values', () => {
|
||||
// Arrange
|
||||
const input = {
|
||||
capacityValue2: 0,
|
||||
capacityValue3: 0,
|
||||
capacityValue4: 0,
|
||||
comparer: 3,
|
||||
};
|
||||
|
||||
// Act
|
||||
const result = calculateMaxCapacity(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(3);
|
||||
});
|
||||
|
||||
it('should handle negative capacity values', () => {
|
||||
// Arrange
|
||||
const input = {
|
||||
capacityValue2: -5,
|
||||
capacityValue3: -3,
|
||||
capacityValue4: -2,
|
||||
comparer: 1,
|
||||
};
|
||||
|
||||
// Act
|
||||
const result = calculateMaxCapacity(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(1);
|
||||
});
|
||||
|
||||
it('should use default values for optional parameters when not provided', () => {
|
||||
// Arrange
|
||||
const input = {
|
||||
capacityValue2: 10,
|
||||
capacityValue3: 8,
|
||||
capacityValue4: undefined,
|
||||
comparer: 5,
|
||||
};
|
||||
|
||||
// Act
|
||||
const result = calculateMaxCapacity(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(8);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Calculates the capacity based on the provided capacity values.
|
||||
* It returns the minimum of the two capacity values.
|
||||
* @param {Object} params - The parameters for the calculation
|
||||
* @param {number} params.capacityValue2 - The second capacity value
|
||||
* @param {number} params.capacityValue3 - The third capacity value
|
||||
* @return {number} The calculated capacity
|
||||
*/
|
||||
export const calculateCapacity = ({
|
||||
capacityValue2,
|
||||
capacityValue3,
|
||||
}: {
|
||||
capacityValue2: number;
|
||||
capacityValue3: number;
|
||||
}): number => {
|
||||
return capacityValue3 > capacityValue2 ? capacityValue2 : capacityValue3;
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates the maximum capacity based on the provided capacity values.
|
||||
* It compares the values and returns the maximum capacity that is greater than or equal to the comparer
|
||||
* or the maximum of the capacity values.
|
||||
* @param {Object} params - The parameters for the calculation
|
||||
* @param {number} params.capacityValue2 - The second capacity value
|
||||
* @param {number} params.capacityValue3 - The third capacity value
|
||||
* @param {number} params.capacityValue4 - The fourth capacity value (optional)
|
||||
* @param {number} params.comparer - The value to compare against
|
||||
* @return {number} The maximum capacity calculated
|
||||
*/
|
||||
export const calculateMaxCapacity = ({
|
||||
capacityValue2 = 0,
|
||||
capacityValue3 = 0,
|
||||
capacityValue4 = 0,
|
||||
comparer,
|
||||
}: {
|
||||
capacityValue2: number;
|
||||
capacityValue3: number;
|
||||
capacityValue4: number | undefined;
|
||||
comparer: number;
|
||||
}): number => {
|
||||
let maxCapacity = 0;
|
||||
|
||||
if (capacityValue4 < capacityValue2) {
|
||||
if (capacityValue4 > 0) {
|
||||
maxCapacity = capacityValue4;
|
||||
} else if (capacityValue3 > capacityValue2) {
|
||||
maxCapacity = capacityValue2;
|
||||
} else if (capacityValue3 > 0) {
|
||||
maxCapacity = capacityValue3;
|
||||
}
|
||||
} else {
|
||||
maxCapacity = capacityValue2;
|
||||
}
|
||||
|
||||
return Math.max(comparer, maxCapacity);
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user