Initial commit: NestJS NextJS pnpm monorepo
This commit is contained in:
commit
610dcf202b
175 files changed
+25172
No files matched your search
@@ -0,0 +1,56 @@
|
||||
# compiled output
|
||||
/dist
|
||||
/node_modules
|
||||
/build
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
pnpm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
|
||||
# Tests
|
||||
/coverage
|
||||
/.nyc_output
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# temp directory
|
||||
.temp
|
||||
.tmp
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<p align="center">
|
||||
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
|
||||
</p>
|
||||
|
||||
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
||||
[circleci-url]: https://circleci.com/gh/nestjs/nest
|
||||
|
||||
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
|
||||
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
|
||||
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
||||
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
||||
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
||||
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
|
||||
</p>
|
||||
<!--[](https://opencollective.com/nest#backer)
|
||||
[](https://opencollective.com/nest#sponsor)-->
|
||||
|
||||
## Description
|
||||
|
||||
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||
|
||||
## Project setup
|
||||
|
||||
```bash
|
||||
$ npm install
|
||||
```
|
||||
|
||||
## Compile and run the project
|
||||
|
||||
```bash
|
||||
# development
|
||||
$ npm run start
|
||||
|
||||
# watch mode
|
||||
$ npm run start:dev
|
||||
|
||||
# production mode
|
||||
$ npm run start:prod
|
||||
```
|
||||
|
||||
## Run tests
|
||||
|
||||
```bash
|
||||
# unit tests
|
||||
$ npm run test
|
||||
|
||||
# e2e tests
|
||||
$ npm run test:e2e
|
||||
|
||||
# test coverage
|
||||
$ npm run test:cov
|
||||
```
|
||||
|
||||
## Deployment
|
||||
|
||||
When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information.
|
||||
|
||||
If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:
|
||||
|
||||
```bash
|
||||
$ npm install -g @nestjs/mau
|
||||
$ mau deploy
|
||||
```
|
||||
|
||||
With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.
|
||||
|
||||
## Resources
|
||||
|
||||
Check out a few resources that may come in handy when working with NestJS:
|
||||
|
||||
- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
|
||||
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
|
||||
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
|
||||
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
|
||||
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
|
||||
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
|
||||
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
|
||||
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).
|
||||
|
||||
## Support
|
||||
|
||||
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
||||
|
||||
## Stay in touch
|
||||
|
||||
- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
|
||||
- Website - [https://nestjs.com](https://nestjs.com/)
|
||||
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
||||
|
||||
## License
|
||||
|
||||
Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
|
||||
Auswahl Lager | --> Anzeige Artikel im Lager |--> $ActionContnent +
|
||||
Anzeige Bereiche von Lager |--> $ActionContent -
|
||||
|--> $Action new |--> Artikel ausawahl |--> $Action ausgewählt | Eingabe Menge
|
||||
Ablaufdatum wenn Conumable
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
###
|
||||
// DELETE http://192.168.50.205/api/article-variant/696627dbdc0e59f41f1704cd
|
||||
|
||||
###
|
||||
GET http://192.168.50.205/api/article-variant/
|
||||
|
||||
###
|
||||
GET http://192.168.50.205/api/article-variant/696f63ba04ab7130ed802c07
|
||||
|
||||
####
|
||||
POST http://192.168.50.205/api/article-variant HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"artikelId": "Schweinehalz",
|
||||
"manufacturerId": "6967a298f9c4e2480405dc5f",
|
||||
"isConsumable": true,
|
||||
"packagingUnit": "kg",
|
||||
"supplierArticleNumber": "0"
|
||||
|
||||
}
|
||||
|
||||
|
||||
####
|
||||
#### Lager1 = 6966126a75af97664a4673b7
|
||||
#### Lager2 = 696614b375af97664a4673cd
|
||||
PATCH http://192.168.50.205/api/articles/6966142475af97664a4673c5 HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"name" : "Milch"
|
||||
}
|
||||
|
||||
|
||||
####
|
||||
POST http://192.168.50.205/api/articles/artikelvariant HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"article":{
|
||||
"name": "Schweinehalz3",
|
||||
"categoryId": "6966135575af97664a4673bb",
|
||||
"isConsumable": true
|
||||
},
|
||||
"variant":{
|
||||
"manufacturerId":"6967a298f9c4e2480405dc5f"
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
###
|
||||
DELETE http://192.168.50.205/api/articles/696627dbdc0e59f41f1704cd
|
||||
|
||||
###
|
||||
GET http://192.168.50.205/api/articles
|
||||
|
||||
###
|
||||
GET http://192.168.50.205/api/articles/697cab0122ffebb5cb2548d3
|
||||
|
||||
####
|
||||
POST http://192.168.50.205/api/articles HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"name": "Schweinehalz5",
|
||||
"categoryId": "6966135575af97664a4673bb",
|
||||
"articleVariants": [
|
||||
{
|
||||
"manufacturerId": "6967a298f9c4e2480405dc5f",
|
||||
"packagingUnit": "Packung"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
####
|
||||
#### Lager1 = 6966126a75af97664a4673b7
|
||||
#### Lager2 = 696614b375af97664a4673cd
|
||||
PATCH http://192.168.50.205/api/articles/697cab0122ffebb5cb2548d3 HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"_id": "6980c0ae644b5dc54a999c96",
|
||||
"name" : "Milch"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
###
|
||||
DELETE http://192.168.50.205/api/categories/6966135575af97664a4673bb
|
||||
|
||||
###
|
||||
GET http://192.168.50.205/api/categories
|
||||
|
||||
###
|
||||
GET http://192.168.50.205/api/categories/6966135575af97664a4673bb
|
||||
|
||||
####
|
||||
POST http://192.168.50.205/api/categories HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"name": "Lebensmittel",
|
||||
"description": "LM"
|
||||
}
|
||||
|
||||
|
||||
####
|
||||
|
||||
PATCH http://192.168.50.205/api/categories/6966135575af97664a4673bb HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"description": "LM2"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
###
|
||||
DELETE http://192.168.50.205/api/locations/6966126a75af97664a4673b7
|
||||
|
||||
### Get All
|
||||
GET http://192.168.50.205/api/locations
|
||||
|
||||
### Get One by ID
|
||||
GET http://192.168.50.205/api/locations/696614b375af97664a4673cd
|
||||
|
||||
### Get Tree Nodes
|
||||
GET http://192.168.50.205/api/locations/childs
|
||||
|
||||
####
|
||||
POST http://192.168.50.205/api/locations HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"name": "Unterlager3",
|
||||
"description": "Unterlager von 3",
|
||||
"parentLocationId" : "698ca482fec73763e0592bd0"
|
||||
}
|
||||
|
||||
|
||||
####
|
||||
PATCH http://192.168.50.205/api/locations/6966126a75af97664a4673b7 HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"name": "Lager15",
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
###
|
||||
DELETE http://192.168.50.205/api/manufacturer/6967a25ff9c4e2480405dc56
|
||||
|
||||
###
|
||||
GET http://192.168.50.205/api/manufacturer
|
||||
|
||||
###
|
||||
GET http://192.168.50.205/api/manufacturer/6967a25ff9c4e2480405dc56
|
||||
|
||||
####
|
||||
POST http://192.168.50.205/api/manufacturer HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"name": "Neuer Hersteller"
|
||||
}
|
||||
|
||||
|
||||
####
|
||||
#### Lager1 = 6966126a75af97664a4673b7
|
||||
#### Lager2 = 696614b375af97664a4673cd
|
||||
PATCH http://192.168.50.205/api/manufacturer/6967a25ff9c4e2480405dc56 HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"name" : "None"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
###
|
||||
GET http://192.168.50.205/api/stock
|
||||
|
||||
###
|
||||
GET http://192.168.50.205/api/stock/69b7b2ab9c5aca9e9d212b6a
|
||||
|
||||
### Create
|
||||
|
||||
POST http://192.168.50.205/api/stock HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"name": "Gefrierschrank Test",
|
||||
"locationId": "6966126a75af97664a4673b7",
|
||||
"areas": ["Fach 1","Fach 2"]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
###
|
||||
GET http://192.168.50.205/api/stock-content
|
||||
|
||||
###
|
||||
GET http://192.168.50.205/api/stock-content/69b7f8b592b8227339642615
|
||||
|
||||
### Create
|
||||
|
||||
POST http://192.168.50.205/api/stock HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"name": "Gefrierschrank Test",
|
||||
"locationId": "6966126a75af97664a4673b7",
|
||||
"areas": ["Fach 1","Fach 2"]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
|
||||
###
|
||||
GET http://192.168.50.205/api/stock-movements
|
||||
|
||||
### Artikel
|
||||
GET http://192.168.50.205/api/articles
|
||||
|
||||
|
||||
|
||||
### Movments
|
||||
GET http://192.168.50.205/api/stock-movements
|
||||
|
||||
### Movments Delete
|
||||
DELETE http://192.168.50.205/api/stock-movements/69662a4fc0cfefe24c4d413f
|
||||
|
||||
###
|
||||
### Lager1 = 6966126a75af97664a4673b7
|
||||
### Lager2 = 696614b375af97664a4673cd
|
||||
### Artikel 1 = 6966142475af97664a4673c5
|
||||
### ArtikelMilchVariant 6967b2bf30bd8874bf293161
|
||||
|
||||
POST http://192.168.50.205/api/stock-movements/IN HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"articleVariantId": "6980c0ae644b5dc54a999c98",
|
||||
"stockId": "69b91033c46a51e3b6848f3a",
|
||||
"quantity": 5,
|
||||
"batchNumber":"1004",
|
||||
"area":"Fach1"
|
||||
|
||||
}
|
||||
|
||||
### ArtikelMilchVariant 6967b2bf30bd8874bf293161
|
||||
|
||||
POST http://192.168.50.205/api/stock-movements/OUT HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"stockContentId": "69b9325d0dbcc3e5a77b4c42",
|
||||
"quantity": 1
|
||||
|
||||
}
|
||||
|
||||
### 69b8037ef4fe247cc0ec088a Gefrierschrank
|
||||
POST http://192.168.50.205/api/stock-movements/transfer HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"articleVariantId": "6980c0ae644b5dc54a999c98",
|
||||
"fromStockId": "69b7b2ab9c5aca9e9d212b6a",
|
||||
"toStockId": "69b91033c46a51e3b6848f3a",
|
||||
"batchNumber": "1001",
|
||||
"quantity": 5,
|
||||
"toArea": "Fach x"
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
GET http://192.168.50.205/api/cats
|
||||
|
||||
####
|
||||
POST http://192.168.50.205/api/cats HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"name": "sample",
|
||||
"breed": "Wed, 21 Oct 2015 18:27:50 GMT",
|
||||
"age": 13
|
||||
}
|
||||
|
||||
###
|
||||
DELETE http://192.168.50.205/api/cats/6964d9060faff490cb9c1157
|
||||
|
||||
###
|
||||
GET http://192.168.50.205/api/users
|
||||
|
||||
###
|
||||
GET http://192.168.50.205/api/users/696511448af50407ba9c8995
|
||||
|
||||
####
|
||||
POST http://192.168.50.205/api/users HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"name": "Bediener",
|
||||
"email": "[email protected]",
|
||||
"age": 8
|
||||
}
|
||||
|
||||
|
||||
####
|
||||
PATCH http://192.168.50.205/api/users/696511658af50407ba9c8998 HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
{
|
||||
"name": "Bediener2",
|
||||
"email": "[email protected]",
|
||||
"age": 9
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// @ts-check
|
||||
import eslint from '@eslint/js';
|
||||
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
||||
import globals from 'globals';
|
||||
import tseslint from 'typescript-eslint';
|
||||
|
||||
export default tseslint.config(
|
||||
{
|
||||
ignores: ['eslint.config.mjs'],
|
||||
},
|
||||
eslint.configs.recommended,
|
||||
...tseslint.configs.recommendedTypeChecked,
|
||||
eslintPluginPrettierRecommended,
|
||||
{
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.node,
|
||||
...globals.jest,
|
||||
},
|
||||
sourceType: 'commonjs',
|
||||
parserOptions: {
|
||||
projectService: true,
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
rules: {
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-floating-promises': 'warn',
|
||||
'@typescript-eslint/no-unsafe-argument': 'warn',
|
||||
"prettier/prettier": ["error", { endOfLine: "auto" }],
|
||||
},
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/nest-cli",
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src",
|
||||
"compilerOptions": {
|
||||
"deleteOutDir": true
|
||||
}
|
||||
}
|
||||
Generated
+9840
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"name": "backend",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"build": "nest build",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --watch",
|
||||
"dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^11.0.1",
|
||||
"@nestjs/core": "^11.0.1",
|
||||
"@nestjs/mapped-types": "^2.1.0",
|
||||
"@nestjs/mongoose": "^11.0.4",
|
||||
"@nestjs/platform-express": "^11.0.1",
|
||||
"@nestjs/platform-socket.io": "^11.1.14",
|
||||
"@nestjs/websockets": "^11.1.14",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.3",
|
||||
"mongodb": "^7.0.0",
|
||||
"mongoose": "^9.1.5",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1",
|
||||
"socket.io": "^4.8.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.2.0",
|
||||
"@eslint/js": "^9.18.0",
|
||||
"@nestjs/cli": "^11.0.0",
|
||||
"@nestjs/schematics": "^11.0.0",
|
||||
"@nestjs/testing": "^11.0.1",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/mongodb": "^4.0.7",
|
||||
"@types/node": "^22.10.7",
|
||||
"@types/supertest": "^6.0.2",
|
||||
"eslint": "^9.18.0",
|
||||
"eslint-config-prettier": "^10.0.1",
|
||||
"eslint-plugin-prettier": "^5.2.2",
|
||||
"globals": "^16.0.0",
|
||||
"jest": "^30.0.0",
|
||||
"prettier": "^3.4.2",
|
||||
"source-map-support": "^0.5.21",
|
||||
"supertest": "^7.0.0",
|
||||
"ts-jest": "^29.2.5",
|
||||
"ts-loader": "^9.5.2",
|
||||
"ts-node": "^10.9.2",
|
||||
"tsconfig-paths": "^4.2.0",
|
||||
"typescript": "^5.7.3",
|
||||
"typescript-eslint": "^8.20.0"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"testRegex": ".*\\.spec\\.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"collectCoverageFrom": [
|
||||
"**/*.(t|j)s"
|
||||
],
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile();
|
||||
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return this.appService.getHello();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
|
||||
import { LocationsModule } from './locations/locations.module';
|
||||
|
||||
import { UsersModule } from './users/users.module';
|
||||
import { CatalogModule } from './catalog/catalog.module';
|
||||
import { InventoryModule } from './inventory/inventory.module';
|
||||
import { ChatGateway } from './chat.gateway';
|
||||
|
||||
@Module({
|
||||
imports: [MongooseModule.forRoot('mongodb://192.168.50.206/nest'),
|
||||
CatalogModule,
|
||||
InventoryModule,
|
||||
UsersModule,
|
||||
LocationsModule,
|
||||
],
|
||||
//controllers: [AppController],
|
||||
providers: [ChatGateway,LocationsModule],
|
||||
})
|
||||
export class AppModule { }
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Types } from 'mongoose';
|
||||
import { ManufacturerDto } from './manufacturer.dto';
|
||||
import { ArticleDto } from './article.dto';
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
|
||||
export class ArticleVariantDto {
|
||||
_id: Types.ObjectId;
|
||||
article: ArticleDto;
|
||||
manufacturer: ManufacturerDto;
|
||||
supplierArticleNumber?: string;
|
||||
packagingUnit?: string;
|
||||
extra?: Record<string, any>;
|
||||
}
|
||||
|
||||
export class ArticleVariantCreateDto {
|
||||
articleId: Types.ObjectId;
|
||||
manufacturerId: Types.ObjectId;
|
||||
supplierArticleNumber?: string;
|
||||
packagingUnit?: string;
|
||||
extra?: Record<string, any>;
|
||||
}
|
||||
|
||||
|
||||
export class ArticleVariantUpdateDto extends PartialType(ArticleVariantCreateDto) {}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import { Types } from 'mongoose';
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
|
||||
import { CategoryDto } from './category.dto';
|
||||
import { ManufacturerDto } from './manufacturer.dto';
|
||||
import { Type } from "class-transformer";
|
||||
import { IsArray, IsMongoId, IsObject, IsOptional, IsString, ValidateNested } from "class-validator";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export class ArticleDto {
|
||||
_id: Types.ObjectId;
|
||||
name: string;
|
||||
category: CategoryDto;
|
||||
attributes?: Record<string, any>;
|
||||
variants: ArticleVariantDto[]
|
||||
}
|
||||
|
||||
|
||||
export class ArticleAndVariantsDto {
|
||||
_id: Types.ObjectId;
|
||||
name: string;
|
||||
categoryId: Types.ObjectId;
|
||||
attributes?: Record<string, any>;
|
||||
variants: {
|
||||
_id:Types.ObjectId;
|
||||
manufacturerId: Types.ObjectId;
|
||||
supplierArticleNumber?: string;
|
||||
packagingUnit?: string;
|
||||
extra?: Record<string, any>;
|
||||
}[]
|
||||
}
|
||||
|
||||
export class ArticleVariantBaseDto {
|
||||
_id: Types.ObjectId;
|
||||
article: ArticleDto;
|
||||
manufacturer: ManufacturerDto;
|
||||
supplierArticleNumber?: string;
|
||||
packagingUnit?: string;
|
||||
extra?: Record<string, any>;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export class ArticleVariantDto {
|
||||
@IsMongoId()
|
||||
manufacturerId: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
supplierArticleNumber?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
packagingUnit?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
extra?: Record<string, any>;
|
||||
}
|
||||
|
||||
|
||||
export class ArticleCreateDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsMongoId()
|
||||
categoryId: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
attributes?: Record<string, any>;
|
||||
|
||||
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ArticleVariantDto)
|
||||
variants: ArticleVariantDto[];
|
||||
}
|
||||
|
||||
export class ArticleUpdateDto extends PartialType(ArticleCreateDto) {}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { PartialType } from "@nestjs/mapped-types";
|
||||
import { Types } from "mongoose";
|
||||
|
||||
export class CategoryCreateDto {
|
||||
name: string;
|
||||
isConsumable: boolean;
|
||||
description?: string;
|
||||
requiredAttributes?: Record<string, any>;
|
||||
parentCategoryId?: Types.ObjectId;
|
||||
|
||||
}
|
||||
|
||||
export class CategoryUpdateDto extends PartialType(CategoryCreateDto) {}
|
||||
|
||||
export class CategoryDto {
|
||||
_id: Types.ObjectId;
|
||||
name: string;
|
||||
isConsumable: boolean;
|
||||
description?: string;
|
||||
requiredAttributes?: Record<string, any>;
|
||||
parentCategoryId?: Types.ObjectId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { IsOptional, IsString } from "class-validator";
|
||||
import { Types } from "mongoose";
|
||||
|
||||
export class ManufacturerCreateDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
}
|
||||
|
||||
export class ManufacturerDto {
|
||||
_id: Types.ObjectId;
|
||||
name: string;
|
||||
}
|
||||
|
||||
|
||||
export class ManufacturerUpdateDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
name: string;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { Type } from "class-transformer";
|
||||
import { IsArray, IsBoolean, IsMongoId, IsObject, IsOptional, IsString, ValidateNested } from "class-validator";
|
||||
|
||||
export class ArticleVariantUpsertDto {
|
||||
@IsOptional()
|
||||
@IsMongoId()
|
||||
_id: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsMongoId()
|
||||
manufacturerId: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
supplierArticleNumber?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
packagingUnit?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
extra?: Record<string, any>;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
deleted?: boolean;
|
||||
}
|
||||
|
||||
export class ArticleUpsertDto {
|
||||
@IsOptional()
|
||||
//@IsMongoId()
|
||||
_id: string;
|
||||
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsMongoId()
|
||||
categoryId: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
attributes?: Record<string, any>;
|
||||
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ArticleVariantUpsertDto)
|
||||
variants: ArticleVariantUpsertDto[];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||
import { Document, Types } from 'mongoose';
|
||||
|
||||
@Schema()
|
||||
export class ArticleVariant extends Document {
|
||||
@Prop({ type: Types.ObjectId, ref: 'Article', required: true })
|
||||
articleId: Types.ObjectId;
|
||||
|
||||
@Prop({ type: Types.ObjectId, ref: 'Manufacturer', required: true })
|
||||
manufacturerId: Types.ObjectId;
|
||||
|
||||
@Prop()
|
||||
supplierArticleNumber?: string;
|
||||
|
||||
@Prop()
|
||||
packagingUnit?: string; // z. B. "Karton 12 Stk"
|
||||
|
||||
@Prop({ type: Object })
|
||||
extra?: Record<string, any>;
|
||||
}
|
||||
|
||||
|
||||
export const ArticleVariantSchema = SchemaFactory.createForClass(ArticleVariant);
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||
import { Document, Types } from 'mongoose';
|
||||
|
||||
@Schema({ timestamps: true })
|
||||
export class Article extends Document {
|
||||
@Prop({ required: true })
|
||||
name: string;
|
||||
|
||||
@Prop({ type: Types.ObjectId, ref: 'Category', required: true })
|
||||
categoryId: Types.ObjectId;
|
||||
|
||||
@Prop({ type: Map, of: String })
|
||||
attributes?: Map<string, any>;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const ArticleSchema = SchemaFactory.createForClass(Article);
|
||||
|
||||
ArticleSchema.virtual('varianten', {
|
||||
ref: 'ArticleVariant',
|
||||
localField: '_id',
|
||||
foreignField: 'articleId',
|
||||
});
|
||||
|
||||
ArticleSchema.set('toJSON', { virtuals: true });
|
||||
ArticleSchema.set('toObject', { virtuals: true });
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||
import { Document, Types } from 'mongoose';
|
||||
|
||||
@Schema({ timestamps: true })
|
||||
export class Category extends Document {
|
||||
@Prop({ required: true })
|
||||
name: string;
|
||||
|
||||
@Prop()
|
||||
description?: string;
|
||||
|
||||
@Prop({ default: true })
|
||||
isConsumable: boolean;
|
||||
|
||||
@Prop({ type: Map, of: String })
|
||||
requiredAttributes?: Map<string, string>;
|
||||
|
||||
}
|
||||
|
||||
export const CategorySchema = SchemaFactory.createForClass(Category);
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||
import { Document, Types } from 'mongoose';
|
||||
|
||||
|
||||
@Schema()
|
||||
export class Manufacturer extends Document {
|
||||
@Prop({ required: true })
|
||||
name: string;
|
||||
|
||||
}
|
||||
|
||||
export const ManufacturerSchema =
|
||||
SchemaFactory.createForClass(Manufacturer);
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { ArticleVariantService } from './article-variant.service';
|
||||
import { ArticleVariantCreateDto, ArticleVariantDto, ArticleVariantUpdateDto } from '../_dto/article-variant.dto';
|
||||
|
||||
@Controller('article-variant')
|
||||
export class ArticleVariantController {
|
||||
constructor(
|
||||
private readonly articleVariantService: ArticleVariantService,
|
||||
) { }
|
||||
|
||||
@Get()
|
||||
findAll():Promise<ArticleVariantDto[]> {
|
||||
|
||||
return this.articleVariantService.findAll();
|
||||
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.articleVariantService.findOne(id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() createArticleVariantDto: ArticleVariantCreateDto) {
|
||||
return this.articleVariantService.create(createArticleVariantDto);
|
||||
}
|
||||
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateArticleVariantDto: ArticleVariantUpdateDto) {
|
||||
return this.articleVariantService.update(id, updateArticleVariantDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.articleVariantService.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ArticleVariantService } from './article-variant.service';
|
||||
|
||||
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { ArticleVariant, ArticleVariantSchema } from '../_entities/article-variant.entity';
|
||||
import { ArticleVariantController } from './article-variant.controller';
|
||||
import { ArticleVariantRepository } from './repository/article-variant.repository';
|
||||
|
||||
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MongooseModule.forFeature([
|
||||
{ name: ArticleVariant.name, schema: ArticleVariantSchema },
|
||||
])
|
||||
],
|
||||
controllers:[ArticleVariantController],
|
||||
providers: [ArticleVariantService,ArticleVariantRepository],
|
||||
exports:[ ArticleVariantService,ArticleVariantRepository]
|
||||
})
|
||||
export class ArticleVariantModule { }
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ArticleVariantRepository } from './repository/article-variant.repository';
|
||||
import { ArticleVariantCreateDto, ArticleVariantDto, ArticleVariantUpdateDto } from '../_dto/article-variant.dto';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class ArticleVariantService {
|
||||
|
||||
constructor(
|
||||
private readonly articleVariantRepository: ArticleVariantRepository,
|
||||
) { }
|
||||
|
||||
create(dto: ArticleVariantCreateDto) {
|
||||
return this.articleVariantRepository.create(dto);
|
||||
}
|
||||
|
||||
findAll(): Promise<ArticleVariantDto[]> {
|
||||
return this.articleVariantRepository.findAll();
|
||||
}
|
||||
|
||||
async findOne(id: string): Promise<ArticleVariantDto> {
|
||||
return await this.articleVariantRepository.findOne(id);
|
||||
}
|
||||
|
||||
update(id: string, dto: ArticleVariantUpdateDto) {
|
||||
return this.articleVariantRepository.update(id, dto);
|
||||
}
|
||||
|
||||
remove(id: string) {
|
||||
return this.articleVariantRepository.remove(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
|
||||
|
||||
export const articleVariantGetQuery = [
|
||||
{
|
||||
$lookup: {
|
||||
from: 'articles',
|
||||
localField: 'articleId',
|
||||
foreignField: '_id',
|
||||
as: 'article',
|
||||
}
|
||||
},
|
||||
{ $unwind: '$article' },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'manufacturers',
|
||||
localField: 'manufacturerId',
|
||||
foreignField: '_id',
|
||||
as: 'manufacturer',
|
||||
},
|
||||
},
|
||||
{ $unwind: '$manufacturer' },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'categories',
|
||||
localField: 'article.categoryId',
|
||||
foreignField: '_id',
|
||||
as: 'category',
|
||||
},
|
||||
},
|
||||
{ $unwind: '$category' },
|
||||
{
|
||||
$project: {
|
||||
packagingUnit: 1,
|
||||
supplierArticleNumber: 1,
|
||||
|
||||
article: {
|
||||
_id: 1,
|
||||
name: 1,
|
||||
unit: 1,
|
||||
|
||||
category: {
|
||||
_id: '$category._id',
|
||||
name: '$category.name',
|
||||
isConsumable: '$category.isConsumable',
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
manufacturer: {
|
||||
_id: 1,
|
||||
name: 1
|
||||
},
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model, Types } from 'mongoose';
|
||||
import { ArticleVariantCreateDto, ArticleVariantDto, ArticleVariantUpdateDto } from 'src/catalog/_dto/article-variant.dto';
|
||||
import { ArticleVariant } from 'src/catalog/_entities/article-variant.entity';
|
||||
import { articleVariantGetQuery } from '../querys/article-variant-get.query';
|
||||
import { ArticleVariantUpsertDto } from 'src/catalog/_dto/upsert-article.dto';
|
||||
import { BulkWriteResult } from 'mongodb';
|
||||
|
||||
@Injectable()
|
||||
export class ArticleVariantRepository {
|
||||
|
||||
constructor(
|
||||
@InjectModel(ArticleVariant.name)
|
||||
private articleVariantModel: Model<ArticleVariant>,
|
||||
) { }
|
||||
|
||||
|
||||
async findAll(): Promise<ArticleVariantDto[]> {
|
||||
return this.articleVariantModel
|
||||
.aggregate<ArticleVariantDto>([...articleVariantGetQuery])
|
||||
}
|
||||
|
||||
async findOne(id: string): Promise<ArticleVariantDto> {
|
||||
const result = await this.articleVariantModel
|
||||
.aggregate<ArticleVariantDto>([
|
||||
{
|
||||
$match: { _id: new Types.ObjectId(id) }
|
||||
},
|
||||
...articleVariantGetQuery]
|
||||
);
|
||||
|
||||
return result[0];
|
||||
}
|
||||
|
||||
create(dto: ArticleVariantCreateDto) {
|
||||
return this.articleVariantModel.create({
|
||||
articleId: new Types.ObjectId(dto.articleId),
|
||||
manufacturerId: new Types.ObjectId(dto.manufacturerId),
|
||||
supplierArticleNumber: dto.supplierArticleNumber,
|
||||
packagingUnit: dto.packagingUnit,
|
||||
extra: dto.extra
|
||||
});
|
||||
}
|
||||
|
||||
createMany(dto: ArticleVariantCreateDto[]) {
|
||||
const withObjId = dto.map((variant) => ({ ...variant, manufacturerId: new Types.ObjectId(variant.manufacturerId) }));
|
||||
return this.articleVariantModel.insertMany(withObjId)
|
||||
|
||||
}
|
||||
|
||||
update(id: string, dto: ArticleVariantUpdateDto) {
|
||||
return this.articleVariantModel.findByIdAndUpdate(id, dto, { new: true });
|
||||
}
|
||||
|
||||
remove(id: string) {
|
||||
return this.articleVariantModel.findByIdAndDelete(id);
|
||||
}
|
||||
|
||||
upsertVariants(articleId: string, dto: ArticleVariantUpsertDto[]): Promise<BulkWriteResult> {
|
||||
const ops = dto.map((v) => {
|
||||
if (v._id) {
|
||||
if (v.deleted) {
|
||||
return {
|
||||
deleteOne: {
|
||||
filter: {
|
||||
_id: new Types.ObjectId(v._id),
|
||||
articleId: new Types.ObjectId(articleId),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
}
|
||||
return {
|
||||
updateOne: {
|
||||
filter: { _id: new Types.ObjectId(v._id), articleId: new Types.ObjectId(articleId) },
|
||||
update: {
|
||||
$set: {
|
||||
manufacturerId: new Types.ObjectId(v.manufacturerId),
|
||||
supplierArticleNumber: v.supplierArticleNumber,
|
||||
packagingUnit: v.packagingUnit,
|
||||
extra: v.extra,
|
||||
}
|
||||
}
|
||||
},
|
||||
upsert: false, // Upsert false, um Fehler bei Duplikaten zu kontrollieren
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
insertOne: {
|
||||
document: {
|
||||
articleId: new Types.ObjectId(articleId),
|
||||
manufacturerId: new Types.ObjectId(v.manufacturerId),
|
||||
supplierArticleNumber: v.supplierArticleNumber,
|
||||
packagingUnit: v.packagingUnit,
|
||||
extra: v.extra,
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
return this.articleVariantModel.bulkWrite(ops);
|
||||
} catch (err) {
|
||||
if (err.code === 11000) {
|
||||
throw new BadRequestException(
|
||||
'Es darf keine Variant mit gleicher manufacturerId für diesen Artikel geben',
|
||||
);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
test() { }
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
upsertVariants1(articleId: string, dto: ArticleVariantUpsertDto[]) {
|
||||
const ops = dto.map((v) => {
|
||||
if (v._id) {
|
||||
return {
|
||||
updateOne: {
|
||||
filter: { _id: v._id, articleId },
|
||||
update: {
|
||||
$set: {
|
||||
manufacturerId: v.manufacturerId,
|
||||
supplierArticleNumber: v.supplierArticleNumber,
|
||||
packagingUnit: v.packagingUnit,
|
||||
extra: v.extra,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
insertOne: {
|
||||
document: {
|
||||
articleId: new Types.ObjectId(articleId),
|
||||
manufacturerId: new Types.ObjectId(v.manufacturerId),
|
||||
supplierArticleNumber: v.supplierArticleNumber,
|
||||
packagingUnit: v.packagingUnit,
|
||||
extra: v.extra,
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
try {
|
||||
return this.articleVariantModel.bulkWrite(ops);
|
||||
} catch (err) {
|
||||
if (err.code === 11000) {
|
||||
throw new BadRequestException(
|
||||
'Es darf keine Variant mit gleicher manufacturerId für diesen Artikel geben',
|
||||
);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { ArticlesService } from './articles.service';
|
||||
|
||||
|
||||
import { ArticleCreateDto, ArticleUpdateDto } from '../_dto/article.dto';
|
||||
import { ArticleUpsertDto } from '../_dto/upsert-article.dto';
|
||||
|
||||
@Controller('articles')
|
||||
export class ArticlesController {
|
||||
constructor(
|
||||
private readonly articlesService: ArticlesService,
|
||||
) { }
|
||||
|
||||
@Post()
|
||||
create(@Body() dto: ArticleCreateDto) {
|
||||
console.log('Create Artikel')
|
||||
return this.articlesService.create(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.articlesService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
console.log('Find one')
|
||||
return this.articlesService.findOne(id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateArticleDto: ArticleUpsertDto) {
|
||||
return this.articlesService.update(id, updateArticleDto);
|
||||
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.articlesService.remove(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ArticlesService } from './articles.service';
|
||||
import { ArticlesController } from './articles.controller';
|
||||
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { Article, ArticleSchema } from '../_entities/article.entity';
|
||||
import { ArticleVariantModule } from '../article-variant/article-variant.module';
|
||||
import { ArticleRepository } from './repository/article.repository';
|
||||
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MongooseModule.forFeature([
|
||||
{ name: Article.name, schema: ArticleSchema },
|
||||
]),
|
||||
ArticleVariantModule
|
||||
],
|
||||
controllers: [ArticlesController],
|
||||
providers: [ArticlesService,ArticleRepository],
|
||||
exports:[ArticlesService]
|
||||
})
|
||||
export class ArticlesModule { }
|
||||
@@ -0,0 +1,51 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
|
||||
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model, Types } from 'mongoose';
|
||||
import { Article } from '../_entities/article.entity';
|
||||
import { ArticleRepository } from './repository/article.repository';
|
||||
import { ArticleAndVariantsDto, ArticleDto, ArticleUpdateDto,ArticleCreateDto } from '../_dto/article.dto';
|
||||
|
||||
import { ArticleUpsertDto } from '../_dto/upsert-article.dto';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class ArticlesService {
|
||||
constructor(
|
||||
@InjectModel(Article.name) private articleModel: Model<Article>,
|
||||
private readonly articleRepository: ArticleRepository
|
||||
) { }
|
||||
|
||||
create(dto: ArticleCreateDto) {
|
||||
return this.articleRepository.creatArticle(dto);
|
||||
|
||||
}
|
||||
|
||||
async findAll(): Promise<ArticleDto[]> {
|
||||
return this.articleRepository.findAll();
|
||||
}
|
||||
|
||||
async findOne(id: string): Promise<ArticleDto> {
|
||||
const article = await this.articleRepository.findOne(id);
|
||||
|
||||
|
||||
|
||||
|
||||
return article;
|
||||
|
||||
}
|
||||
|
||||
update(id: string, dto: ArticleUpsertDto) {
|
||||
console.log('update service')
|
||||
return this.articleRepository.updateArticle(id,dto);
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
console.log('all variants deleted')
|
||||
return this.articleRepository.deleteArticle(id);
|
||||
|
||||
|
||||
//return this.articleModel.findByIdAndDelete(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
import { Types } from "mongoose";
|
||||
|
||||
export const articleGetQuery = [
|
||||
{
|
||||
$lookup: {
|
||||
from: 'articlevariants',
|
||||
localField: '_id',
|
||||
foreignField: 'articleId',
|
||||
as: 'varianten',
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'manufacturers',
|
||||
localField: 'varianten.manufacturerId',
|
||||
foreignField: '_id',
|
||||
as: 'manufacturer',
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'categories',
|
||||
localField: 'categoryId',
|
||||
foreignField: '_id',
|
||||
as: 'category',
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: '$category',
|
||||
preserveNullAndEmptyArrays: true
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
name: 1,
|
||||
category: {
|
||||
_id: '$category._id',
|
||||
name: '$category.name',
|
||||
isConsumable: '$category.isConsumable'
|
||||
},
|
||||
|
||||
variants: {
|
||||
$map: {
|
||||
input: '$varianten',
|
||||
as: 'v',
|
||||
in: {
|
||||
_id: '$$v._id',
|
||||
packagingUnit: '$$v.packagingUnit',
|
||||
manufacturer: {
|
||||
$arrayElemAt: [
|
||||
{
|
||||
$filter: {
|
||||
input: '$manufacturer',
|
||||
as: 'm',
|
||||
cond: {
|
||||
$eq: [
|
||||
'$$m._id',
|
||||
{ $toObjectId: '$$v.manufacturerId' }
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
0
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
export const articleGetQuery2 = [
|
||||
{
|
||||
$lookup: {
|
||||
from: 'articlevariants',
|
||||
localField: '_id',
|
||||
foreignField: 'articleId',
|
||||
as: 'varianten',
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'manufacturers',
|
||||
localField: 'varianten.manufacturerId',
|
||||
foreignField: '_id',
|
||||
as: 'manufacturer',
|
||||
},
|
||||
},
|
||||
{ $unwind: '$manufacturer' },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'categories',
|
||||
localField: 'categoryId',
|
||||
foreignField: '_id',
|
||||
as: 'category',
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: '$category',
|
||||
preserveNullAndEmptyArrays: true
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
$project: {
|
||||
name: 1,
|
||||
category: {
|
||||
_id: '$category._id',
|
||||
name: '$category.name',
|
||||
isConsumable: 1,
|
||||
},
|
||||
varianten: {
|
||||
_id: 1,
|
||||
manufacturer: {
|
||||
_id: '$manufacturer._id',
|
||||
name: '$manufacturer.name',
|
||||
},
|
||||
packagingUnit: 1
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
];
|
||||
@@ -0,0 +1,113 @@
|
||||
import { Injectable, NotFoundException, ConflictException } from '@nestjs/common';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model, Types } from 'mongoose';
|
||||
|
||||
import { ArticleCreateDto, ArticleDto } from 'src/catalog/_dto/article.dto';
|
||||
import { Article } from 'src/catalog/_entities/article.entity';
|
||||
import { ArticleVariantRepository } from 'src/catalog/article-variant/repository/article-variant.repository';
|
||||
import { articleGetQuery } from '../querys/article-get.query';
|
||||
|
||||
import { ArticleUpsertDto, ArticleVariantUpsertDto } from 'src/catalog/_dto/upsert-article.dto';
|
||||
|
||||
@Injectable()
|
||||
export class ArticleRepository {
|
||||
|
||||
constructor(
|
||||
@InjectModel(Article.name)
|
||||
private articleModel: Model<Article>,
|
||||
private readonly articleVariantRepository: ArticleVariantRepository
|
||||
|
||||
) { }
|
||||
|
||||
async findAll(): Promise<ArticleDto[]> {
|
||||
const res = await this.articleModel.aggregate<ArticleDto>(
|
||||
[...articleGetQuery]);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
async findOne(id: string): Promise<ArticleDto> {
|
||||
const res = await this.articleModel.aggregate<ArticleDto>(
|
||||
[{ $match: { _id: new Types.ObjectId(id) } }
|
||||
, ...articleGetQuery]);
|
||||
|
||||
return res[0];
|
||||
}
|
||||
|
||||
async creatArticle(dto: ArticleCreateDto) {
|
||||
const { name, variants, categoryId, attributes } = dto;
|
||||
|
||||
|
||||
const isSameName = await this.articleModel.findOne({ name: name });
|
||||
if (isSameName) throw new ConflictException("Name ist arlready exsist!");
|
||||
|
||||
const newArticle = await this.articleModel.create({ name, categoryId: new Types.ObjectId(categoryId), attributes })
|
||||
|
||||
|
||||
const variantsWithNewArticleId = variants.map((variant) => (
|
||||
{
|
||||
packagingUnit: variant.packagingUnit,
|
||||
manufacturerId: new Types.ObjectId(variant.manufacturerId),
|
||||
articleId: newArticle._id
|
||||
}
|
||||
));
|
||||
|
||||
await this.articleVariantRepository.createMany(variantsWithNewArticleId)
|
||||
|
||||
return this.findOne(newArticle.id);
|
||||
|
||||
}
|
||||
|
||||
async updateArticle(id: string, dto: ArticleUpsertDto) {
|
||||
const { name, variants, categoryId, attributes } = dto;
|
||||
|
||||
|
||||
const article = await this.articleModel.findOne({ _id: id });
|
||||
|
||||
if (!article) throw new NotFoundException("Article nicht gefunden");
|
||||
|
||||
if (dto.name !== undefined) article.name = dto.name;
|
||||
if (dto.categoryId !== undefined) article.categoryId = new Types.ObjectId(dto.categoryId);
|
||||
if (dto.attributes !== undefined) { article.attributes = new Map(Object.entries(dto.attributes));}
|
||||
|
||||
article.updateOne({
|
||||
$set:{
|
||||
name,categoryId,attributes
|
||||
}
|
||||
});
|
||||
article.save();
|
||||
|
||||
|
||||
await this.articleVariantRepository.upsertVariants(id,variants)
|
||||
|
||||
return this.findOne(id);
|
||||
|
||||
}
|
||||
|
||||
async deleteArticle(id: string) {
|
||||
|
||||
const article = await this.findOne(id);
|
||||
|
||||
if (true) throw new NotFoundException("deleteArticle Not Supportet jet");
|
||||
if (!article) throw new NotFoundException("Article nicht gefunden");
|
||||
|
||||
/*
|
||||
for (const item of article.variants) {
|
||||
const res = await this.articleVariantRepository.remove(item._id.toString())
|
||||
}
|
||||
|
||||
const deleteIt = await this.articleModel.deleteOne(article._id);
|
||||
|
||||
console.log(deleteIt)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return {_id:id};
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { CategoriesModule } from './categories/categories.module';
|
||||
import { ArticlesModule } from './articles/articles.module';
|
||||
import { ArticleVariantModule } from './article-variant/article-variant.module';
|
||||
import { ManufacturerModule } from './manufacturer/manufacturer.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ArticlesModule,
|
||||
ArticleVariantModule,
|
||||
CategoriesModule,
|
||||
ManufacturerModule,
|
||||
],
|
||||
exports: [ArticlesModule, ArticleVariantModule]
|
||||
})
|
||||
export class CatalogModule { }
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { CategoriesService } from './categories.service';
|
||||
import { CategoryCreateDto,CategoryUpdateDto } from '../_dto/category.dto';
|
||||
|
||||
@Controller('categories')
|
||||
export class CategoriesController {
|
||||
constructor(private readonly categoriesService: CategoriesService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createCategoryDto: CategoryCreateDto) {
|
||||
return this.categoriesService.create(createCategoryDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.categoriesService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.categoriesService.findOne(id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateCategoryDto: CategoryUpdateDto) {
|
||||
return this.categoriesService.update(id, updateCategoryDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.categoriesService.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { Category, CategorySchema } from '../_entities/category.entity';
|
||||
import { CategoriesService } from './categories.service';
|
||||
import { CategoriesController } from './categories.controller';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MongooseModule.forFeature([
|
||||
{ name: Category.name, schema: CategorySchema },
|
||||
])
|
||||
],
|
||||
controllers: [CategoriesController],
|
||||
providers: [CategoriesService],
|
||||
})
|
||||
export class CategoriesModule {}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { Injectable,NotFoundException } from '@nestjs/common';
|
||||
import { CategoryCreateDto,CategoryUpdateDto } from '../_dto/category.dto';
|
||||
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
import { Category } from '../_entities/category.entity';
|
||||
|
||||
@Injectable()
|
||||
export class CategoriesService {
|
||||
constructor(
|
||||
@InjectModel(Category.name)
|
||||
private categoryModel: Model<Category>,
|
||||
) { }
|
||||
|
||||
create(dto: CategoryCreateDto) {
|
||||
return this.categoryModel.create(dto);
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.categoryModel
|
||||
.find();
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
const category = await this.categoryModel.findById(id);
|
||||
if (!category) throw new NotFoundException('Category nicht gefunden');
|
||||
return category;
|
||||
}
|
||||
|
||||
update(id: string, dto: CategoryUpdateDto) {
|
||||
|
||||
|
||||
return this.categoryModel.findByIdAndUpdate(id, dto, { new: true });
|
||||
}
|
||||
|
||||
remove(id: string) {
|
||||
return this.categoryModel.findByIdAndDelete(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { ManufacturerService } from './manufacturer.service';
|
||||
import { ManufacturerCreateDto, ManufacturerUpdateDto } from '../_dto/manufacturer.dto';
|
||||
|
||||
|
||||
@Controller('manufacturer')
|
||||
export class ManufacturerController {
|
||||
constructor(private readonly manufacturerService: ManufacturerService) {}
|
||||
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.manufacturerService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.manufacturerService.findOne(id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() createManufacturerDto: ManufacturerCreateDto) {
|
||||
return this.manufacturerService.create(createManufacturerDto);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateManufacturerDto: ManufacturerUpdateDto) {
|
||||
console.log(updateManufacturerDto)
|
||||
return this.manufacturerService.update(id, updateManufacturerDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.manufacturerService.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ManufacturerService } from './manufacturer.service';
|
||||
import { ManufacturerController } from './manufacturer.controller';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { Manufacturer, ManufacturerSchema } from '../_entities/manufacturer.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MongooseModule.forFeature([
|
||||
{ name: Manufacturer.name, schema: ManufacturerSchema },
|
||||
])
|
||||
],
|
||||
controllers: [ManufacturerController],
|
||||
providers: [ManufacturerService],
|
||||
})
|
||||
export class ManufacturerModule {}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Injectable,NotFoundException } from '@nestjs/common';
|
||||
import { ManufacturerCreateDto, ManufacturerUpdateDto } from '../_dto/manufacturer.dto';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
import { Manufacturer } from '../_entities/manufacturer.entity';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class ManufacturerService {
|
||||
constructor(
|
||||
@InjectModel(Manufacturer.name)
|
||||
private manufacturerModel: Model<Manufacturer>,
|
||||
) { }
|
||||
|
||||
create(dto: ManufacturerCreateDto) {
|
||||
return this.manufacturerModel.create(dto);
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.manufacturerModel
|
||||
.find();
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
const article = await this.manufacturerModel.findById(id);
|
||||
if (!article) throw new NotFoundException('Artikel nicht gefunden');
|
||||
return article;
|
||||
}
|
||||
|
||||
update(id: string, dto: ManufacturerUpdateDto) {
|
||||
return this.manufacturerModel.findByIdAndUpdate(id, dto, { new: true });
|
||||
}
|
||||
|
||||
remove(id: string) {
|
||||
return this.manufacturerModel.findByIdAndDelete(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import {
|
||||
WebSocketGateway,
|
||||
SubscribeMessage,
|
||||
MessageBody,
|
||||
WebSocketServer,
|
||||
} from '@nestjs/websockets';
|
||||
import { Server } from 'socket.io';
|
||||
|
||||
@WebSocketGateway({
|
||||
cors: {
|
||||
origin: 'http://192.168.50.205',
|
||||
},
|
||||
})
|
||||
export class ChatGateway {
|
||||
@WebSocketServer()
|
||||
server: Server; // 👈 DAS fehlt dir gerade
|
||||
|
||||
@SubscribeMessage('message')
|
||||
handleMessage(@MessageBody() data: string) {
|
||||
console.log('msg:', data);
|
||||
this.server.emit('message', data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { DrawService } from './draw.service';
|
||||
|
||||
@Controller('draw')
|
||||
export class DrawController {
|
||||
constructor(private readonly service:DrawService){}
|
||||
|
||||
@Get('ellipse')
|
||||
getEllypse(){
|
||||
return this.service.ellypse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { DrawController } from './draw.controller';
|
||||
import { DrawService } from './draw.service';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [DrawController],
|
||||
providers:[DrawService]
|
||||
})
|
||||
export class DrawModule {}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DrawContainer } from 'src/graphics/lib/draw';
|
||||
import { DrawEllipse } from 'src/graphics/lib/drawEllipse';
|
||||
import { DrawGroup } from 'src/graphics/lib/drawGroup';
|
||||
import { DrawPath, PathCommand } from 'src/graphics/lib/drawPath';
|
||||
|
||||
@Injectable()
|
||||
export class DrawService {
|
||||
constructor() { }
|
||||
|
||||
async ellypse() {
|
||||
|
||||
const raster = 4;
|
||||
const scale = 2.0;
|
||||
const x0 = 0;
|
||||
const y0 = 0;
|
||||
|
||||
const l1 = 40 * raster * scale
|
||||
const h1 = 2 * raster * scale
|
||||
|
||||
const r = h1 / 2;
|
||||
|
||||
const deck: PathCommand[] = [
|
||||
{ type: "M", x: r, y: y0 },
|
||||
{ type: "H", x: l1 - r }, // --
|
||||
{ type: "A", rx: r, ry: r,
|
||||
xAxisRotation: 0,
|
||||
largeArcFlag: 0,
|
||||
sweepFlag: 1, x: l1 - r, y: h1 }, // >
|
||||
|
||||
{ type: "H", x: x0 + r }, // --
|
||||
{ type: "A", rx: r, ry: r,
|
||||
xAxisRotation: 0,
|
||||
largeArcFlag: 0,
|
||||
sweepFlag: 1, x: r, y: y0 }, // <
|
||||
{ type: "Z" }
|
||||
];
|
||||
|
||||
const c1 = new DrawGroup({});
|
||||
const c2 = new DrawGroup({});
|
||||
|
||||
const rtc = new DrawPath(deck);
|
||||
const ely1 = new DrawEllipse( { cx: 10, cy: 10, rx: 5, ry: 5});
|
||||
c2.add(ely1);
|
||||
|
||||
c1.add(rtc);
|
||||
c1.add(c2);
|
||||
c1.add(rtc);
|
||||
|
||||
return c1.getChildString(false,0)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
|
||||
export abstract class DrawContainer {
|
||||
elements = new Map<number, DrawContainer | DrawElement>();
|
||||
|
||||
add(item: DrawContainer | DrawElement) {
|
||||
const elNr = this.elements.size
|
||||
this.elements.set(elNr, item);
|
||||
}
|
||||
|
||||
getElements() {
|
||||
return this.elements;
|
||||
}
|
||||
|
||||
abstract getChildString(xaml: boolean,deph:number):string;
|
||||
}
|
||||
|
||||
class Translate {
|
||||
dataXaml = new Map<string, string>()
|
||||
constructor(private xaml?:boolean) {
|
||||
if(!xaml) this.xaml = false;
|
||||
this.dataXaml.set('color', 'Color');
|
||||
this.dataXaml.set('strokeWidth', 'StrokeThickness');
|
||||
this.dataXaml.set('stroke', 'Stroke');
|
||||
this.dataXaml.set('dasharray', 'dasharray');
|
||||
this.dataXaml.set('fill', 'fill');
|
||||
this.dataXaml.set('opacity', 'opacity');
|
||||
}
|
||||
|
||||
getAttribute(key: string, value: string | number): { key: string, value: string | number } {
|
||||
let t_key = this.dataXaml.get(key);
|
||||
|
||||
if(this.xaml && key==='fill' && value==='none') return {key:'ignore',value:''};
|
||||
|
||||
if (t_key) return { key: t_key, value: value };
|
||||
else return { key: key, value: value };
|
||||
}
|
||||
|
||||
setXaml(){
|
||||
this.xaml = true;
|
||||
}
|
||||
|
||||
setSvg(){
|
||||
this.xaml = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export abstract class DrawElement {
|
||||
attributes = new Map<string, string | number>();
|
||||
|
||||
constructor() { }
|
||||
|
||||
getParameterString(values:Map<string, string|number>,xaml?: boolean, translate?: Translate) {
|
||||
translate = new Translate(xaml);
|
||||
|
||||
let str = '';
|
||||
let sep = ' ';
|
||||
for (const [key, paraValue] of values) {
|
||||
let attr = {key,value: paraValue};
|
||||
if (xaml && translate) attr = translate.getAttribute(attr.key, attr.value);
|
||||
|
||||
if(attr.key!=='ignore'){
|
||||
str += `${attr.key}="${attr.value}"${sep}`
|
||||
sep = ' ';
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
abstract drawSvg():string;
|
||||
abstract drawXaml():string;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
interface ElypI {
|
||||
x: number,
|
||||
y: number
|
||||
}
|
||||
|
||||
class Elipse extends DrawElement {
|
||||
constructor(name: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
|
||||
getAttString(): string {
|
||||
return "att1=1";
|
||||
}
|
||||
|
||||
setAtrr(att: Partial<ElypI>) {
|
||||
Object.entries(att).forEach(([key, value]) => {
|
||||
this.attributes.set(key, value);
|
||||
});
|
||||
}
|
||||
|
||||
drawSvg(): string {
|
||||
return 'not Supportet jet'
|
||||
}
|
||||
|
||||
|
||||
|
||||
drawXaml(): string {
|
||||
return 'not Supportet jet'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
import { DrawElement } from "./draw"
|
||||
|
||||
interface PropEllipse {
|
||||
cx: number
|
||||
cy: number
|
||||
rx: number
|
||||
ry: number
|
||||
}
|
||||
|
||||
interface SvgOptions {
|
||||
color?: string
|
||||
storkWidth?: number,
|
||||
dasharray?: string,
|
||||
fill?: string,
|
||||
opacity?: number
|
||||
}
|
||||
|
||||
|
||||
export class DrawEllipse extends DrawElement {
|
||||
|
||||
|
||||
|
||||
constructor(private posAndSize: PropEllipse) {
|
||||
super();
|
||||
|
||||
// Default Attribute
|
||||
this.attributes.set('strokeWidth', 1);
|
||||
this.attributes.set('stroke', "#000000");
|
||||
this.attributes.set('fill', 'none');
|
||||
}
|
||||
|
||||
|
||||
setAtrr(att: Partial<SvgOptions>) {
|
||||
Object.entries(att).forEach(([key, value]) => {
|
||||
this.attributes.set(key, value);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
drawSvg() {
|
||||
const paraStr = this.getParameterString(this.attributes);
|
||||
const posSvg = this.getSvgPositions(this.posAndSize)
|
||||
const posStr = this.getParameterString(posSvg);
|
||||
|
||||
const shape = this.drawElementSvg(posStr, paraStr);
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
drawXaml(): string {
|
||||
const paraStr = this.getParameterString(this.attributes, true);
|
||||
const posXaml = this.getXamlPositions(this.posAndSize)
|
||||
const posStr = this.getParameterString(posXaml, true);
|
||||
|
||||
const shape = this.drawElementXaml(posStr, paraStr);
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
drawElementSvg(position: string, options: string) {
|
||||
return `<ellipse ${position} ${options}></ellipse>`
|
||||
}
|
||||
|
||||
drawElementXaml(position: string, options: string) {
|
||||
|
||||
return `<Ellipse ${position} ${options}></Ellipse>`
|
||||
|
||||
}
|
||||
|
||||
getSvgPositions(dim: PropEllipse) {
|
||||
|
||||
let retValue = new Map<string, number>();
|
||||
|
||||
retValue.set('cx', dim.cx);
|
||||
retValue.set('cy', dim.cy);
|
||||
retValue.set('rx', dim.rx);
|
||||
retValue.set('ry', dim.ry);
|
||||
|
||||
return retValue;
|
||||
|
||||
}
|
||||
|
||||
getXamlPositions(dim: PropEllipse) {
|
||||
|
||||
let retValue = new Map<string, number>();
|
||||
|
||||
retValue.set('Canvas.Left', dim.cx - dim.rx);
|
||||
retValue.set('Canvas.Top', dim.cx - dim.ry);
|
||||
retValue.set('Width', dim.rx * 2);
|
||||
retValue.set('Height', dim.ry * 2);
|
||||
|
||||
return retValue;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
import { DrawContainer, DrawElement } from "./draw"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
interface PropDimGroup {
|
||||
x?: number,
|
||||
y?: number,
|
||||
rotate?: number
|
||||
}
|
||||
|
||||
|
||||
interface SvgOptionsGroup {
|
||||
dummy: number
|
||||
}
|
||||
|
||||
|
||||
export class DrawGroup extends DrawContainer {
|
||||
|
||||
attributes = new Map<string,string|number>();
|
||||
|
||||
constructor(private posDim: PropDimGroup) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
setAtrr(att: Partial<SvgOptionsGroup>) {
|
||||
Object.entries(att).forEach(([key, value]) => {
|
||||
this.attributes.set(key, value);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
drawElementSvg(pathCmd: string, options: string) {
|
||||
return `<path d="${pathCmd}" ${options}></path>`
|
||||
}
|
||||
|
||||
drawElementXaml(pathCmd: string, options: string) {
|
||||
|
||||
return `<Path data="${pathCmd}" ${options}></Path>`
|
||||
|
||||
}
|
||||
|
||||
getChildString(xaml: boolean,deph:number):string {
|
||||
console.log(deph)
|
||||
deph = deph +1;
|
||||
|
||||
const reversedElements = Array.from(this.elements).reverse();
|
||||
let containerData = ''
|
||||
|
||||
for (const [key, value] of reversedElements) {
|
||||
let svgOfNextElement = ''
|
||||
|
||||
if( value instanceof DrawContainer){
|
||||
svgOfNextElement = value.getChildString(xaml,deph)
|
||||
} else{
|
||||
svgOfNextElement = "\t".repeat(deph) + value.drawSvg() + '\n';
|
||||
}
|
||||
containerData += svgOfNextElement;
|
||||
}
|
||||
|
||||
|
||||
const group = "\t".repeat(deph-1) +'<g>\n'+containerData+"\t".repeat(deph-1) +'</g>\n'
|
||||
|
||||
return group;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
const group = (svg: string, options?: { x?: number, y?: number, rotate?: number }, xaml?: boolean) => {
|
||||
if (!options) options = { x: 0, y: 0, rotate: 0 };
|
||||
if (!options.x) options.x = 0;
|
||||
if (!options.y) options.y = 0;
|
||||
if (!options.rotate) options.rotate = 0;
|
||||
|
||||
let transform = '';
|
||||
let translate = '';
|
||||
let rotate = ''
|
||||
if (options.x > 0 || options.y > 0) translate = `translate(${options.x},${options.y})`
|
||||
if (options.rotate != 0) rotate = `rotate(${options.rotate} ${0} ${0})`
|
||||
if (options.x > 0 || options.y > 0 || options.rotate != 0) transform = `transform="${translate} ${rotate}"`
|
||||
|
||||
// XAML
|
||||
let x_left = `Left="${options.x}"`;
|
||||
let x_top = `Top="${options.y}"`;
|
||||
let x_rotate = '';
|
||||
if (options.rotate != 0) x_rotate =
|
||||
`
|
||||
<Canvas.RenderTransform>
|
||||
<RotateTransform Angle="${options.rotate}" CenterX="${0}" CenterY="${0}" />
|
||||
</Canvas.RenderTransform>`
|
||||
if (options.x > 0) x_left = ''
|
||||
|
||||
let group =
|
||||
`<g ${transform}>
|
||||
${svg}
|
||||
</g>`
|
||||
|
||||
let xgroup =
|
||||
`<Canvas ${x_left} ${x_top}>
|
||||
${svg} ${x_rotate}
|
||||
</Canvas>`
|
||||
|
||||
|
||||
if (xaml) return xgroup;
|
||||
return group;
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
import { DrawElement } from "./draw"
|
||||
|
||||
|
||||
/** Basis-Typ: alle Commands haben ein Flag ob relativ oder absolut */
|
||||
interface BaseCommand {
|
||||
/** true = relativer Befehl (kleiner Buchstabe), false/undefined = absolut */
|
||||
relative?: boolean;
|
||||
}
|
||||
|
||||
/** Move-To */
|
||||
export interface MoveToCommand extends BaseCommand {
|
||||
type: "M";
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
/** Line-To */
|
||||
export interface LineToCommand extends BaseCommand {
|
||||
type: "L";
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
/** Horizontal Line-To */
|
||||
export interface HorizontalLineToCommand extends BaseCommand {
|
||||
type: "H";
|
||||
x: number;
|
||||
}
|
||||
|
||||
/** Vertical Line-To */
|
||||
export interface VerticalLineToCommand extends BaseCommand {
|
||||
type: "V";
|
||||
y: number;
|
||||
}
|
||||
|
||||
/** Cubic Bézier Curve */
|
||||
export interface CubicBezierCommand extends BaseCommand {
|
||||
type: "C";
|
||||
x1: number; y1: number;
|
||||
x2: number; y2: number;
|
||||
x: number; y: number;
|
||||
}
|
||||
|
||||
/** Smooth Cubic Bézier Curve */
|
||||
export interface SmoothCubicBezierCommand extends BaseCommand {
|
||||
type: "S";
|
||||
x2: number; y2: number;
|
||||
x: number; y: number;
|
||||
}
|
||||
|
||||
/** Quadratic Bézier Curve */
|
||||
export interface QuadraticBezierCommand extends BaseCommand {
|
||||
type: "Q";
|
||||
x1: number; y1: number;
|
||||
x: number; y: number;
|
||||
}
|
||||
|
||||
/** Smooth Quadratic Bézier Curve */
|
||||
export interface SmoothQuadraticBezierCommand extends BaseCommand {
|
||||
type: "T";
|
||||
x: number; y: number;
|
||||
}
|
||||
|
||||
/** Elliptical Arc */
|
||||
export interface ArcCommand extends BaseCommand {
|
||||
type: "A";
|
||||
rx: number;
|
||||
ry: number;
|
||||
xAxisRotation: number;
|
||||
largeArcFlag: 0 | 1;
|
||||
sweepFlag: 0 | 1;
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
/** Close Path */
|
||||
export interface ClosePathCommand extends BaseCommand {
|
||||
type: "Z";
|
||||
}
|
||||
|
||||
/** Union aller Path-Kommandos */
|
||||
export type PathCommand =
|
||||
| MoveToCommand
|
||||
| LineToCommand
|
||||
| HorizontalLineToCommand
|
||||
| VerticalLineToCommand
|
||||
| CubicBezierCommand
|
||||
| SmoothCubicBezierCommand
|
||||
| QuadraticBezierCommand
|
||||
| SmoothQuadraticBezierCommand
|
||||
| ArcCommand
|
||||
| ClosePathCommand;
|
||||
|
||||
/** Ein ganzer Pfad ist einfach eine Liste von Kommandos */
|
||||
export type SvgPath = PathCommand[];
|
||||
|
||||
|
||||
|
||||
|
||||
interface PropDimPath {
|
||||
cx: number
|
||||
cy: number
|
||||
rx: number
|
||||
ry: number
|
||||
}
|
||||
|
||||
interface SvgOptions {
|
||||
color?: string
|
||||
storkWidth?: number,
|
||||
dasharray?: string,
|
||||
fill?: string,
|
||||
opacity?: number
|
||||
}
|
||||
|
||||
|
||||
|
||||
export class DrawPath extends DrawElement {
|
||||
|
||||
|
||||
|
||||
constructor(private pathCommands: PathCommand[]) {
|
||||
super();
|
||||
|
||||
// Default Attribute
|
||||
this.attributes.set('strokeWidth', 1);
|
||||
this.attributes.set('stroke', "#000000");
|
||||
this.attributes.set('fill', 'none');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
setAtrr(att: Partial<SvgOptions>) {
|
||||
Object.entries(att).forEach(([key, value]) => {
|
||||
this.attributes.set(key, value);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
drawSvg() {
|
||||
const paraStr = this.getParameterString(this.attributes);
|
||||
const path = this.getCmdString(false)
|
||||
|
||||
|
||||
const shape = this.drawElementSvg(path, paraStr);
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
drawXaml(): string {
|
||||
const paraStr = this.getParameterString(this.attributes, true);
|
||||
const path = this.getCmdString(true);
|
||||
const shape = this.drawElementXaml(path, paraStr);
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
drawElementSvg(pathCmd: string, options: string) {
|
||||
return `<path d="${pathCmd}" ${options}></path>`
|
||||
}
|
||||
|
||||
drawElementXaml(pathCmd: string, options: string) {
|
||||
|
||||
return `<Path data="${pathCmd}" ${options}></Path>`
|
||||
|
||||
}
|
||||
|
||||
getCmdString(xaml: boolean = false) {
|
||||
const pathCmd = this.pathCommands.map(d => this.commandToString(d, xaml)).join(" ")
|
||||
|
||||
return pathCmd;
|
||||
|
||||
}
|
||||
|
||||
commandToString(cmd: PathCommand, xaml?: boolean): string {
|
||||
const prefix = cmd.relative && !xaml ? cmd.type.toLowerCase() : cmd.type;
|
||||
const separator = xaml ? "," : " ";
|
||||
switch (cmd.type) {
|
||||
case "M":
|
||||
case "L":
|
||||
return `${prefix} ${cmd.x}${separator}${cmd.y}`;
|
||||
|
||||
case "H":
|
||||
return `${prefix} ${cmd.x}`;
|
||||
|
||||
case "V":
|
||||
return `${prefix} ${cmd.y}`;
|
||||
|
||||
case "C":
|
||||
return `${prefix} ${cmd.x1}${separator}${cmd.y1} ${cmd.x2} ${cmd.y2} ${cmd.x}${separator}${cmd.y}`;
|
||||
|
||||
case "S":
|
||||
return `${prefix} ${cmd.x2} ${cmd.y2} ${cmd.x} ${cmd.y}`;
|
||||
|
||||
case "Q":
|
||||
return `${prefix} ${cmd.x1} ${cmd.y1} ${cmd.x} ${cmd.y}`;
|
||||
|
||||
case "T":
|
||||
return `${prefix} ${cmd.x} ${cmd.y}`;
|
||||
|
||||
case "A":
|
||||
return `${prefix} ${cmd.rx}${separator}${cmd.ry} ${cmd.xAxisRotation} ${cmd.largeArcFlag} ${cmd.sweepFlag} ${cmd.x}${separator}${cmd.y}`;
|
||||
|
||||
case "Z":
|
||||
return `${prefix}`;
|
||||
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Whitespace-only changes.
@@ -0,0 +1,45 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { StockMovementsService } from '../movements/movements.service';
|
||||
import { StockMovementInDto,StockMovementOutDto,StockMovementTransferDto } from '../_dto/stock-movement.dto';
|
||||
|
||||
|
||||
@Controller('stock-movements')
|
||||
export class StockMovementsController {
|
||||
constructor(
|
||||
|
||||
private readonly stockMovementsService: StockMovementsService
|
||||
) { console.log('movement controller');}
|
||||
|
||||
@Post('in')
|
||||
async stockIn(@Body() dto: StockMovementInDto) {
|
||||
|
||||
return this.stockMovementsService.in(dto);
|
||||
}
|
||||
|
||||
@Post('out')
|
||||
async stockOut(@Body() dto: StockMovementOutDto) {
|
||||
return this.stockMovementsService.out(dto);
|
||||
}
|
||||
|
||||
@Post('transfer')
|
||||
async transfer(@Body() dto: StockMovementTransferDto) {
|
||||
return this.stockMovementsService.transfer(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findx() {
|
||||
return "Hello from movement";
|
||||
}
|
||||
|
||||
|
||||
@Get()
|
||||
async findAll() {
|
||||
return this.stockMovementsService.findAll();
|
||||
}
|
||||
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.stockMovementsService.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { StockContentService } from '../stock-content/stock-content.service';
|
||||
import { StockSummaryQuery } from '../_queries/stock-summary.query';
|
||||
|
||||
@Controller('stock-content')
|
||||
export class StockContentController {
|
||||
constructor(
|
||||
private readonly stockService: StockContentService,
|
||||
private readonly stockSummaryQuery: StockSummaryQuery,
|
||||
) { }
|
||||
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.stockService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.stockService.findOne(id);
|
||||
}
|
||||
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.stockService.remove(id);
|
||||
}
|
||||
|
||||
@Get('summary/by-variant')
|
||||
getStockByVariant() {
|
||||
return this.stockSummaryQuery.byArticle();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { StockService } from '../stock/stock.service';
|
||||
import { StockCreateDto, StockUpdateDto } from '../_dto/stock.dto';
|
||||
|
||||
|
||||
|
||||
@Controller('stock')
|
||||
export class StockController {
|
||||
constructor(
|
||||
private readonly service: StockService,
|
||||
) { }
|
||||
|
||||
@Post()
|
||||
create(@Body() dto: StockCreateDto) {
|
||||
console.log('Create Stock')
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.service.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
console.log('Find one')
|
||||
return this.service.findOne(id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() dto: StockUpdateDto) {
|
||||
return this.service.update(id, dto);
|
||||
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.service.remove(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { PartialType } from "@nestjs/mapped-types";
|
||||
import { StockDto } from "./stock.dto";
|
||||
import { ArticleVariantDto } from "src/catalog/_dto/article.dto";
|
||||
|
||||
|
||||
export class StockContentDto {
|
||||
id:string
|
||||
stock: StockDto;
|
||||
articleVariant: ArticleVariantDto;
|
||||
batchNumber?: string;
|
||||
area?:string;
|
||||
quantity:number
|
||||
}
|
||||
|
||||
export class StockContentCreateDto {
|
||||
stock: StockDto;
|
||||
articleVariant: ArticleVariantDto;
|
||||
batchNumber?: string;
|
||||
area?:string;
|
||||
quantity:number
|
||||
}
|
||||
|
||||
export class StockContentFindConsumableDto {
|
||||
stockId: string;
|
||||
articleVariantId: string;
|
||||
batchNumber: string;
|
||||
}
|
||||
|
||||
export class StockContentFindNonConsumableDto {
|
||||
stockId: string;
|
||||
articleVariantId: string;
|
||||
}
|
||||
|
||||
export class StockContentConsumableInDto {
|
||||
stockId: string;
|
||||
articleVariantId: string;
|
||||
quantity: number;
|
||||
expiryDate?: Date;
|
||||
batchNumber?: string;
|
||||
area?: string;
|
||||
}
|
||||
|
||||
export class StockContentNonConsumableInDto{
|
||||
stockId: string;
|
||||
articleVariantId: string;
|
||||
quantity: number;
|
||||
area?: string;
|
||||
}
|
||||
|
||||
export class StockContentUpdateDto extends PartialType(StockContentConsumableInDto) { }
|
||||
@@ -0,0 +1,72 @@
|
||||
import { IsDate, IsMongoId, IsNumber, IsOptional, IsString } from "class-validator";
|
||||
|
||||
export enum StockMovementType {
|
||||
IN = 'IN',
|
||||
OUT = 'OUT',
|
||||
TRANSFER = 'TRANSFER',
|
||||
}
|
||||
|
||||
export class StockMovementInDto {
|
||||
@IsString()
|
||||
@IsMongoId()
|
||||
stockId: string;
|
||||
|
||||
@IsString()
|
||||
@IsMongoId()
|
||||
articleVariantId: string;
|
||||
|
||||
@IsNumber()
|
||||
quantity: number;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
batchNumber?: string;
|
||||
|
||||
@IsDate()
|
||||
@IsOptional()
|
||||
expiryDate?: Date;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
area?: string;
|
||||
|
||||
}
|
||||
|
||||
export class StockMovementOutDto {
|
||||
@IsString()
|
||||
@IsMongoId()
|
||||
stockContentId: string;
|
||||
|
||||
@IsNumber()
|
||||
quantity: number;
|
||||
|
||||
}
|
||||
|
||||
export class StockMovementTransferDto {
|
||||
@IsString()
|
||||
@IsMongoId()
|
||||
articleVariantId: string;
|
||||
|
||||
@IsString()
|
||||
@IsMongoId()
|
||||
fromStockId: string;
|
||||
|
||||
@IsString()
|
||||
@IsMongoId()
|
||||
toStockId: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
toArea?: string;
|
||||
|
||||
@IsNumber()
|
||||
quantity: number;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
batchNumber?: string;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { IsMongoId, IsOptional, IsString, IsArray } from "class-validator";
|
||||
import { Types } from "mongoose";
|
||||
import { LocationDto } from "src/locations/dto/location.dto";
|
||||
|
||||
export class StockCreateDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsString()
|
||||
@IsMongoId()
|
||||
locationId: string;
|
||||
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
areas?:string[]
|
||||
}
|
||||
|
||||
export class StockUpdateDto {
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
name?: string;
|
||||
|
||||
@IsString()
|
||||
@IsMongoId()
|
||||
@IsOptional()
|
||||
locationId?: string;
|
||||
|
||||
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
areas?:string[]
|
||||
}
|
||||
|
||||
export class StockRowDto {
|
||||
_id: string
|
||||
name: string;
|
||||
locationId: Types.ObjectId;
|
||||
areas?:string[]
|
||||
}
|
||||
|
||||
export class StockDto {
|
||||
id: string
|
||||
name: string;
|
||||
location: LocationDto;
|
||||
areas?:string[]
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||
import { Document, Types } from 'mongoose';
|
||||
|
||||
@Schema({ timestamps: true })
|
||||
export class StockContent extends Document {
|
||||
@Prop({ type: Types.ObjectId, ref: 'Stock', required: true })
|
||||
stockId: Types.ObjectId;
|
||||
|
||||
@Prop({ type: Types.ObjectId, ref: 'ArticleVariant', required: true })
|
||||
articleVariantId: Types.ObjectId;
|
||||
|
||||
@Prop({required:false})
|
||||
batchNumber?: string;
|
||||
|
||||
@Prop({ required: true })
|
||||
quantity: number;
|
||||
|
||||
@Prop()
|
||||
expiryDate?: Date;
|
||||
|
||||
@Prop()
|
||||
area?: string;
|
||||
|
||||
}
|
||||
|
||||
export const StockContentSchema = SchemaFactory.createForClass(StockContent);
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||
import { Document, Types } from 'mongoose';
|
||||
import { StockMovementType } from '../_dto/stock-movement.dto';
|
||||
|
||||
|
||||
|
||||
@Schema({ timestamps: true })
|
||||
export class StockMovement extends Document {
|
||||
@Prop({ type: Types.ObjectId, ref: 'Stock', required: true })
|
||||
stockId: Types.ObjectId;
|
||||
|
||||
@Prop({ type: Types.ObjectId, ref: 'ArticleVariant', required: true })
|
||||
articleVariantId: Types.ObjectId;
|
||||
|
||||
|
||||
@Prop({ type: String, enum: StockMovementType, required: true, })
|
||||
type: StockMovementType;
|
||||
|
||||
@Prop({ required: true, min: 1 })
|
||||
quantity: number;
|
||||
|
||||
@Prop({ type: Types.ObjectId, ref: 'Stock' })
|
||||
toStockId?: Types.ObjectId;
|
||||
|
||||
|
||||
@Prop({ type: Object })
|
||||
meta?: Record<string, any>;
|
||||
}
|
||||
|
||||
export const StockMovementSchema =
|
||||
SchemaFactory.createForClass(StockMovement);
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||
import { Document, Types } from 'mongoose';
|
||||
|
||||
@Schema({ timestamps: false })
|
||||
export class Stock extends Document {
|
||||
@Prop({ required: true })
|
||||
name: string;
|
||||
|
||||
@Prop({ type: Types.ObjectId, ref: 'Location', required: true })
|
||||
locationId: Types.ObjectId;
|
||||
|
||||
@Prop({ })
|
||||
areas: Types.Array<string>;
|
||||
|
||||
}
|
||||
|
||||
export const StockSchema = SchemaFactory.createForClass(Stock);
|
||||
@@ -0,0 +1,95 @@
|
||||
import { Injectable, BadRequestException } from '@nestjs/common';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
import { StockContent } from '../_entities/stock-content.entity'
|
||||
|
||||
@Injectable()
|
||||
export class StockSummaryQuery {
|
||||
constructor(
|
||||
@InjectModel(StockContent.name)
|
||||
private readonly stockModel: Model<StockContent>,
|
||||
) { }
|
||||
|
||||
async byArticle() {
|
||||
console.log('get');
|
||||
const x = await this.stockModel.aggregate<{id_:string,articleVariantId:string,articleName:string,manufacturer:string,totalQuantity:number}>([
|
||||
{
|
||||
$group: {
|
||||
_id: '$articleVariantId',
|
||||
totalQuantity: { $sum: '$quantity' },
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
$lookup: {
|
||||
from: 'articlevariants',
|
||||
localField: '_id',
|
||||
foreignField: '_id',
|
||||
as: 'variant',
|
||||
}
|
||||
},
|
||||
|
||||
{ $unwind: '$variant' },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'articles',
|
||||
localField: 'variant.articleId',
|
||||
foreignField: '_id',
|
||||
as: 'article',
|
||||
},
|
||||
},
|
||||
{ $unwind: '$article' },
|
||||
// 4️⃣ Hersteller holen
|
||||
{
|
||||
$lookup: {
|
||||
from: 'manufacturers',
|
||||
localField: 'variant.manufacturerId',
|
||||
foreignField: '_id',
|
||||
as: 'manufacturer',
|
||||
},
|
||||
},
|
||||
{ $unwind: '$manufacturer' },
|
||||
{
|
||||
$project: {
|
||||
_id: 0,
|
||||
articleVariantId: '$_id',
|
||||
articleName: '$article.name',
|
||||
manufacturer: '$manufacturer.name',
|
||||
totalQuantity: 1,
|
||||
},
|
||||
}
|
||||
|
||||
]);
|
||||
console.log(x[0].articleName + ' von ' + x[0].manufacturer);
|
||||
return x;
|
||||
}
|
||||
|
||||
async byArticle2() {
|
||||
return this.stockModel.aggregate([
|
||||
{
|
||||
$group: {
|
||||
_id: '$articleVariantId',
|
||||
totalQuantity: { $sum: '$quantity' },
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'articlevariants',
|
||||
localField: '_id',
|
||||
foreignField: '_id',
|
||||
as: 'variant',
|
||||
},
|
||||
},
|
||||
{ $unwind: '$variant' },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'articles',
|
||||
localField: 'variant.articleId',
|
||||
foreignField: '_id',
|
||||
as: 'article',
|
||||
},
|
||||
},
|
||||
{ $unwind: '$article' },
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { MovementsModule } from './movements/movements.module';
|
||||
import { StockContentModule } from './stock-content/stock-content.module';
|
||||
import { StockModule } from './stock/stock.module';
|
||||
import { LocationsModule } from 'src/locations/locations.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MovementsModule,
|
||||
StockContentModule,
|
||||
StockModule,
|
||||
LocationsModule
|
||||
],
|
||||
|
||||
|
||||
})
|
||||
export class InventoryModule { }
|
||||
@@ -0,0 +1,76 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model, Types } from 'mongoose';
|
||||
import { StockMovement } from '../_entities/stock-movement.entity';
|
||||
|
||||
import { StockMovementInDto, StockMovementType, StockMovementTransferDto, StockMovementOutDto } from '../_dto/stock-movement.dto';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class MovementRepository {
|
||||
constructor(
|
||||
@InjectModel(StockMovement.name)
|
||||
private readonly model: Model<StockMovement>,
|
||||
|
||||
) { }
|
||||
|
||||
async findAll() {
|
||||
return this.model.find().exec();
|
||||
}
|
||||
|
||||
remove(id: string) {
|
||||
return this.model.findByIdAndDelete(id);
|
||||
}
|
||||
|
||||
// ===============================
|
||||
// IN
|
||||
// ===============================
|
||||
async logStockMoveIn(dto: StockMovementInDto) {
|
||||
const { articleVariantId, stockId, quantity } = dto;
|
||||
return this.model.create(
|
||||
{
|
||||
articleVariantId,
|
||||
stockId,
|
||||
type: StockMovementType.IN,
|
||||
quantity
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ===============================
|
||||
// OUT
|
||||
// ===============================
|
||||
async logStockMoveOut(dto: StockMovementOutDto,result:any) {
|
||||
|
||||
return this.model.create({
|
||||
stockId: new Types.ObjectId(dto.stockContentId),
|
||||
articleVariantId: new Types.ObjectId(result.articelVariantId),
|
||||
type: StockMovementType.OUT,
|
||||
quantity: dto.quantity,
|
||||
});
|
||||
}
|
||||
|
||||
// ===============================
|
||||
// TRANSFER
|
||||
// ===============================
|
||||
async logStockContentTransfer(dto: StockMovementTransferDto) {
|
||||
const { articleVariantId, quantity, fromStockId, toStockId } = dto;
|
||||
|
||||
|
||||
return this.model.create({
|
||||
articleVariantId: new Types.ObjectId(articleVariantId),
|
||||
stockId:fromStockId,
|
||||
type: StockMovementType.TRANSFER,
|
||||
quantity,
|
||||
meta: {
|
||||
fromLocationId: new Types.ObjectId(fromStockId),
|
||||
toLocationId: new Types.ObjectId(toStockId),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { StockMovementsController } from '../_controllers/movements.controller';
|
||||
import { StockMovementsService } from './movements.service';
|
||||
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
|
||||
import { MovementRepository } from './movement.repository';
|
||||
|
||||
import { StockContent, StockContentSchema } from '../_entities/stock-content.entity';
|
||||
import { StockMovement, StockMovementSchema } from '../_entities/stock-movement.entity';
|
||||
import { Article, ArticleSchema } from 'src/catalog/_entities/article.entity';
|
||||
import { ArticleVariant, ArticleVariantSchema } from 'src/catalog/_entities/article-variant.entity';
|
||||
import { CatalogModule } from 'src/catalog/catalog.module';
|
||||
import { StockContentModule } from '../stock-content/stock-content.module';
|
||||
import { StockContentRepository } from '../stock-content/stock-content.repository';
|
||||
import { StockContentService } from '../stock-content/stock-content.service';
|
||||
|
||||
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MongooseModule.forFeature([
|
||||
{ name: StockContent.name, schema: StockContentSchema },
|
||||
{ name: StockMovement.name, schema: StockMovementSchema },
|
||||
{ name: Article.name, schema: ArticleSchema },
|
||||
{ name: ArticleVariant.name, schema: ArticleVariantSchema },
|
||||
|
||||
]),
|
||||
CatalogModule,
|
||||
|
||||
],
|
||||
|
||||
controllers: [StockMovementsController],
|
||||
providers: [
|
||||
StockMovementsService,
|
||||
StockContentService,
|
||||
StockContentRepository,
|
||||
MovementRepository,
|
||||
],
|
||||
|
||||
})
|
||||
export class MovementsModule { }
|
||||
@@ -0,0 +1,48 @@
|
||||
import { Injectable, BadRequestException } from '@nestjs/common';
|
||||
import { StockMovementOutDto, StockMovementInDto, StockMovementTransferDto } from '../_dto/stock-movement.dto';
|
||||
import { MovementRepository } from './movement.repository';
|
||||
import { StockContentService } from '../stock-content/stock-content.service';
|
||||
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class StockMovementsService {
|
||||
constructor(
|
||||
private readonly movementRepo: MovementRepository,
|
||||
private readonly stockContentService: StockContentService
|
||||
) { }
|
||||
|
||||
findAll() {
|
||||
return this.movementRepo.findAll();
|
||||
}
|
||||
|
||||
remove(id: string) {
|
||||
return this.movementRepo.remove(id);
|
||||
}
|
||||
|
||||
|
||||
async in(dto: StockMovementInDto) {
|
||||
this.validateIn(dto);
|
||||
|
||||
const result = this.stockContentService.moveIn(dto);
|
||||
return await this.movementRepo.logStockMoveIn(dto);
|
||||
}
|
||||
|
||||
async out(dto: StockMovementOutDto) {
|
||||
const outResult = await this.stockContentService.moveOut(dto);
|
||||
return await this.movementRepo.logStockMoveOut(dto, outResult);
|
||||
}
|
||||
|
||||
async transfer(dto: StockMovementTransferDto) {
|
||||
const result = await this.stockContentService.transfer(dto);
|
||||
return this.movementRepo.logStockContentTransfer(dto);
|
||||
}
|
||||
|
||||
|
||||
private validateIn(dto: StockMovementInDto) {
|
||||
if (dto.quantity <= 0) {
|
||||
throw new BadRequestException('Menge muss > 0 sein');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { StockContentService } from './stock-content.service';
|
||||
import { StockContentController } from '../_controllers/stock-content.controller';
|
||||
import { StockSummaryQuery } from '../_queries/stock-summary.query';
|
||||
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { StockContent, StockContentSchema } from '../_entities/stock-content.entity';
|
||||
import { StockContentRepository } from './stock-content.repository';
|
||||
import { CatalogModule } from 'src/catalog/catalog.module';
|
||||
import { StockModule } from '../stock/stock.module';
|
||||
import { StockService } from '../stock/stock.service';
|
||||
|
||||
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MongooseModule.forFeature([
|
||||
{ name: StockContent.name, schema: StockContentSchema },
|
||||
]),
|
||||
CatalogModule,
|
||||
|
||||
],
|
||||
controllers: [StockContentController],
|
||||
providers: [StockContentService, StockSummaryQuery,StockContentRepository],
|
||||
exports: [StockContentService]
|
||||
})
|
||||
export class StockContentModule { }
|
||||
@@ -0,0 +1,286 @@
|
||||
import { Injectable, BadRequestException } from '@nestjs/common';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model, Types } from 'mongoose';
|
||||
import { StockContent } from '../_entities/stock-content.entity';
|
||||
import {
|
||||
StockContentConsumableInDto,
|
||||
StockContentNonConsumableInDto,
|
||||
StockContentFindConsumableDto,
|
||||
StockContentFindNonConsumableDto
|
||||
} from '../_dto/stock-content.dto';
|
||||
|
||||
import { StockMovementOutDto, StockMovementTransferDto } from '../_dto/stock-movement.dto';
|
||||
import { ArticleVariantService } from 'src/catalog/article-variant/article-variant.service';
|
||||
|
||||
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class StockContentRepository {
|
||||
constructor(
|
||||
@InjectModel(StockContent.name)
|
||||
private readonly model: Model<StockContent>,
|
||||
//private readonly articleService: ArticleVariantService,
|
||||
|
||||
) { }
|
||||
|
||||
async remove(id: string) {
|
||||
return this.model.findByIdAndDelete(id);
|
||||
}
|
||||
|
||||
async findById(stockId: string) {
|
||||
return this.model.findById(stockId);
|
||||
}
|
||||
|
||||
async findNonConsumable(dto: StockContentFindNonConsumableDto) {
|
||||
return this.model
|
||||
.findOne({
|
||||
articleVariantId: dto.articleVariantId,
|
||||
stockId: dto.stockId,
|
||||
batchNumber: null,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async findConsumable(dto: StockContentFindConsumableDto) {
|
||||
const { articleVariantId, stockId, batchNumber } = dto;
|
||||
|
||||
return this.model
|
||||
.findOne({
|
||||
articleVariantId,
|
||||
stockId,
|
||||
batchNumber,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stock IN
|
||||
*/
|
||||
|
||||
//--- Konsumierbare artikel
|
||||
async moveConsumableIn(dto: StockContentConsumableInDto): Promise<StockContent> {
|
||||
|
||||
const { stockId, articleVariantId, batchNumber, quantity } = dto;
|
||||
|
||||
if (!batchNumber) {
|
||||
throw new BadRequestException(
|
||||
'Batch Nummer erfoderlich erforderlich',
|
||||
);
|
||||
}
|
||||
|
||||
const stockContent = await this.findConsumable({ stockId, articleVariantId, batchNumber });
|
||||
|
||||
return await this.moveIn(dto, stockContent);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Nicht Konsumierbare artikel
|
||||
async moveNonConsumableIn(dto: StockContentNonConsumableInDto): Promise<StockContent> {
|
||||
|
||||
const stockContent = await this.findNonConsumable({
|
||||
articleVariantId: dto.articleVariantId,
|
||||
stockId: dto.stockId,
|
||||
});
|
||||
|
||||
return this.moveIn(dto, stockContent);
|
||||
|
||||
}
|
||||
|
||||
private async moveIn(dto: StockContentConsumableInDto, stockContent?: StockContent | null): Promise<StockContent> {
|
||||
|
||||
let result: StockContent;
|
||||
|
||||
if (stockContent) {
|
||||
// Artikel im Lager bereits vorhanden
|
||||
stockContent.quantity += dto.quantity;
|
||||
result = await stockContent.save();
|
||||
} else {
|
||||
// Artikel nicht im Lager vorhanden
|
||||
const create = {
|
||||
articleVariantId: new Types.ObjectId(dto.articleVariantId),
|
||||
stockId: new Types.ObjectId(dto.stockId),
|
||||
quantity: dto.quantity,
|
||||
|
||||
}
|
||||
if (dto.area) create['area'] = dto.area;
|
||||
if (dto.batchNumber) create['batchNumber'] = dto.batchNumber;
|
||||
if (dto.expiryDate) create['expiryDate'] = dto.expiryDate;
|
||||
|
||||
result = await this.model.create(create);
|
||||
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Move from Stock OUT
|
||||
*/
|
||||
async moveOut(dto: StockMovementOutDto) {
|
||||
|
||||
let stockContent = await this.findById(dto.stockContentId);
|
||||
if (!stockContent) throw new BadRequestException('consumeStock: Stock Content nicht gefunden');
|
||||
|
||||
|
||||
|
||||
let result = {
|
||||
stockId: stockContent._id,
|
||||
articleVariantId: stockContent.articleVariantId,
|
||||
quantity: dto.quantity,
|
||||
empty: false
|
||||
}
|
||||
|
||||
stockContent.quantity -= dto.quantity;
|
||||
|
||||
if (stockContent.quantity < 0) {
|
||||
throw new BadRequestException('Negativer Bestand');
|
||||
}
|
||||
|
||||
if (stockContent.quantity === 0) {
|
||||
result.empty = true;
|
||||
await stockContent.deleteOne();
|
||||
} else {
|
||||
await stockContent.save();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// =================================
|
||||
// TRANSFER
|
||||
// =================================
|
||||
|
||||
|
||||
|
||||
async transfer(dto: StockMovementTransferDto, isConsumable: boolean) {
|
||||
const { articleVariantId, quantity, fromStockId, toStockId } = dto;
|
||||
//const articleVariant = await this.articleService.findOne(articleVariantId);
|
||||
//const isConsumable = articleVariant.article.category.isConsumable;
|
||||
|
||||
if (isConsumable && !dto.batchNumber) throw new BadRequestException('Batch Nummer muss für Konsumierbare Artikel zum Verschieben vorhanden sein');
|
||||
//if (!articleVariant) throw new BadRequestException('Artikel Variante nicht gefunden');
|
||||
|
||||
if (isConsumable && dto.batchNumber) {
|
||||
this.handelTransferConsumable(dto)
|
||||
} else {
|
||||
this.handelTransferNonConsumable(articleVariantId, fromStockId, toStockId, quantity)
|
||||
}
|
||||
|
||||
let retValue = {
|
||||
//articleVariant,
|
||||
isConsumable,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private async handelTransferConsumable(dto: StockMovementTransferDto) {
|
||||
const { articleVariantId, fromStockId, batchNumber, quantity, toStockId, toArea } = dto;
|
||||
|
||||
if (!batchNumber) throw new BadRequestException('handelTransferConsumable: Batch Nummer muss vorhanden sein');
|
||||
|
||||
//--- StockContent -- FROM
|
||||
const stockContentFrom = await this.findConsumable({ articleVariantId, stockId: fromStockId, batchNumber });
|
||||
|
||||
if (!stockContentFrom) throw new BadRequestException('handelTransferConsumable: stockContentFrom nicht gefunden');
|
||||
if (stockContentFrom.quantity < quantity) throw new BadRequestException('handelTransferConsumable: Menge überschreitet Lagerbestand im Quell Lager');
|
||||
|
||||
//--- StockContent -- TO
|
||||
const stockContetTo = await this.findConsumable({ articleVariantId, stockId: toStockId, batchNumber });
|
||||
|
||||
// From Content aktualisieren
|
||||
stockContentFrom.quantity -= quantity;
|
||||
if (stockContentFrom.quantity == 0) {
|
||||
// Lager ist leergeräumt
|
||||
await this.remove(fromStockId);
|
||||
} else {
|
||||
// neuer lagerbestand speichern
|
||||
await stockContentFrom.save();
|
||||
}
|
||||
|
||||
if (stockContetTo) {
|
||||
// Besteand vom exisitierenden Lagerbestand erhöhen
|
||||
stockContetTo.quantity += quantity;
|
||||
await stockContetTo.save();
|
||||
} else {
|
||||
// Besteand im Ziellager neu anlegen
|
||||
let data = {
|
||||
stockId: toStockId,
|
||||
articleVariantId,
|
||||
quantity,
|
||||
batchNumber,
|
||||
}
|
||||
if(toArea) data['area'] = toArea;
|
||||
this.moveConsumableIn(data)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async handelTransferNonConsumable(articleVariantId: string, fromStockId: string, toStockId: string, quantity: number) {
|
||||
|
||||
const stockContentFrom = await this.findNonConsumable({ articleVariantId, stockId: fromStockId, });
|
||||
if (!stockContentFrom) throw new BadRequestException('from StockContent not found');
|
||||
|
||||
const stockContetTo = await this.findNonConsumable({ articleVariantId, stockId: toStockId, });
|
||||
if (stockContentFrom.quantity < quantity) throw new BadRequestException('Menge überschreitet Lagerbestand im Quell Lager');
|
||||
|
||||
stockContentFrom.quantity -= quantity;
|
||||
if (stockContentFrom.quantity == 0) {
|
||||
// Lager ist leergeräumt
|
||||
await this.remove(fromStockId);
|
||||
} else {
|
||||
// neuer lagerbestand speichern
|
||||
await stockContentFrom.save();
|
||||
}
|
||||
|
||||
if (stockContetTo) {
|
||||
// Besteand vom exisitierenden Lagerbestand erhöhen
|
||||
stockContetTo.quantity += quantity;
|
||||
await stockContetTo.save();
|
||||
} else {
|
||||
// Besteand im Ziellager neu anlegen
|
||||
this.moveNonConsumableIn({
|
||||
stockId: toStockId,
|
||||
articleVariantId,
|
||||
quantity
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
async increaseOrCreate(
|
||||
data: {
|
||||
articleId: string;
|
||||
locationId: string;
|
||||
quantity: number;
|
||||
expiryDate?: Date;
|
||||
batchNumber?: string;
|
||||
},
|
||||
session?: ClientSession,
|
||||
) {
|
||||
const filter: any = {
|
||||
articleId: data.articleId,
|
||||
locationId: data.locationId,
|
||||
expiryDate: data.expiryDate ?? null,
|
||||
batchNumber: data.batchNumber ?? null,
|
||||
};
|
||||
|
||||
const stock = await this.model
|
||||
.findOne(filter)
|
||||
.session(session ?? null);
|
||||
|
||||
if (stock) {
|
||||
stock.quantity += data.quantity;
|
||||
await stock.save({ session });
|
||||
} else {
|
||||
await this.model.create([data], { session });
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,234 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
import { StockContent } from '../_entities/stock-content.entity';
|
||||
import { StockContentConsumableInDto, StockContentNonConsumableInDto, StockContentFindConsumableDto, StockContentFindNonConsumableDto, StockContentDto } from '../_dto/stock-content.dto';
|
||||
import { StockContentRepository } from './stock-content.repository';
|
||||
import { StockMovementInDto, StockMovementOutDto, StockMovementTransferDto } from '../_dto/stock-movement.dto';
|
||||
import { ArticleVariantService } from 'src/catalog/article-variant/article-variant.service';
|
||||
import { StockService } from '../stock/stock.service';
|
||||
|
||||
@Injectable()
|
||||
export class StockContentService {
|
||||
|
||||
constructor(
|
||||
@InjectModel(StockContent.name) private stockContentModel: Model<StockContent>,
|
||||
private readonly stockContentRepo: StockContentRepository,
|
||||
private readonly articleVariantService: ArticleVariantService,
|
||||
// private readonly stockService: StockService
|
||||
|
||||
) { }
|
||||
|
||||
async findAll() {
|
||||
let stockContent = await this.stockContentModel.aggregate<StockContent>([
|
||||
{
|
||||
$lookup: {
|
||||
from: 'articlevariants',
|
||||
localField: 'articleVariantId',
|
||||
foreignField: '_id',
|
||||
as: 'articleVariant',
|
||||
pipeline: [
|
||||
{
|
||||
$addFields: { id: "$_id" }
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'articles',
|
||||
localField: 'articleId',
|
||||
foreignField: '_id',
|
||||
as: 'article',
|
||||
pipeline: [
|
||||
{
|
||||
$addFields: { id: "$_id" }
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
__v: 0,
|
||||
_id: 0
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: "$article",
|
||||
preserveNullAndEmptyArrays: true
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
$project: {
|
||||
articleId: 0,
|
||||
__v: 0,
|
||||
_id: 0
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: "$articleVariant",
|
||||
preserveNullAndEmptyArrays: true
|
||||
}
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'stocks',
|
||||
localField: 'stockId',
|
||||
foreignField: '_id',
|
||||
as: 'stock',
|
||||
pipeline: [
|
||||
{
|
||||
$addFields: { id: "$_id" }
|
||||
},
|
||||
|
||||
{
|
||||
$lookup: {
|
||||
from: 'locations',
|
||||
localField: 'locationId',
|
||||
foreignField: '_id',
|
||||
as: 'location',
|
||||
pipeline: [
|
||||
{
|
||||
$addFields: { id: "$_id" }
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
__v: 0,
|
||||
_id: 0
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: "$location",
|
||||
preserveNullAndEmptyArrays: true
|
||||
}
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
// articleId:0,
|
||||
__v: 0,
|
||||
_id: 0,
|
||||
locationId:0
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: "$stock",
|
||||
preserveNullAndEmptyArrays: true
|
||||
}
|
||||
},
|
||||
{
|
||||
$addFields: { id: "$_id" }
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
id: 1,
|
||||
_id: 0,
|
||||
stock: 1,
|
||||
batchNumber: 1,
|
||||
area: 1,
|
||||
quantity: 1,
|
||||
articleVariant: 1,
|
||||
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
return stockContent;
|
||||
return this.stockContentModel.aggregate<StockContentDto>([
|
||||
{
|
||||
$lookup: {
|
||||
from: 'articlevariants',
|
||||
localField: 'articleVariantId',
|
||||
foreignField: '_id',
|
||||
as: 'articleVariant',
|
||||
}
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'stocks',
|
||||
localField: 'stockId',
|
||||
foreignField: '_id',
|
||||
as: 'stock',
|
||||
}
|
||||
},
|
||||
{ $unwind: '$stock' },
|
||||
{
|
||||
$project: {
|
||||
|
||||
articleVariantId: 1,
|
||||
stockId: 1,
|
||||
batchNumber: 1,
|
||||
area: 1,
|
||||
quantity: 1
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
const item = await this.stockContentModel.findById(id);
|
||||
if (!item) throw new NotFoundException('Stock Content nicht gefunden');
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
remove(id: string) {
|
||||
return this.stockContentRepo.remove(id);
|
||||
}
|
||||
|
||||
|
||||
//--- Stock IN
|
||||
async moveIn(dto: StockMovementInDto): Promise<StockContent> {
|
||||
|
||||
const articleVariant = await this.articleVariantService.findOne(dto.articleVariantId);
|
||||
const avId = articleVariant._id.toString();
|
||||
const isConsumable = articleVariant.article.category.isConsumable;
|
||||
|
||||
let moveData = {
|
||||
...dto,
|
||||
articleVariantId: avId,
|
||||
}
|
||||
|
||||
if (isConsumable) {
|
||||
return await this.stockContentRepo.moveConsumableIn(moveData);
|
||||
} else {
|
||||
return await this.stockContentRepo.moveNonConsumableIn(moveData);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//--- Stock OUT
|
||||
moveOut(dto: StockMovementOutDto) {
|
||||
return this.stockContentRepo.moveOut(dto);
|
||||
}
|
||||
|
||||
|
||||
//--- Stock Transfer
|
||||
async transfer(dto: StockMovementTransferDto) {
|
||||
|
||||
const articleVariant = await this.articleVariantService.findOne(dto.articleVariantId);
|
||||
const avId = articleVariant._id.toString();
|
||||
const isConsumable = articleVariant.article.category.isConsumable;
|
||||
|
||||
this.stockContentRepo.transfer(dto, isConsumable);
|
||||
|
||||
return {
|
||||
articleVariant,
|
||||
isConsumable,
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
|
||||
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { Stock, StockSchema } from '../_entities/stock.entity';
|
||||
import { StockController } from '../_controllers/stock.controller';
|
||||
import { StockService } from './stock.service';
|
||||
import { LocationsModule } from 'src/locations/locations.module';
|
||||
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MongooseModule.forFeature([
|
||||
{ name: Stock.name, schema: StockSchema },
|
||||
]),
|
||||
LocationsModule
|
||||
],
|
||||
controllers: [StockController],
|
||||
providers: [StockService],
|
||||
exports: [StockService]
|
||||
})
|
||||
export class StockModule { }
|
||||
@@ -0,0 +1,66 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
|
||||
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model, Types } from 'mongoose';
|
||||
import { Stock } from '../_entities/stock.entity';
|
||||
import { StockCreateDto, StockDto, StockRowDto, StockUpdateDto } from '../_dto/stock.dto';
|
||||
import { LocationsService } from 'src/locations/locations.service';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class StockService {
|
||||
constructor(
|
||||
@InjectModel(Stock.name) private model: Model<Stock>,
|
||||
readonly locationService: LocationsService
|
||||
|
||||
) { }
|
||||
|
||||
create(dto: StockCreateDto) {
|
||||
|
||||
const item = {
|
||||
name: dto.name,
|
||||
locationId: new Types.ObjectId(dto.locationId),
|
||||
areas:dto.areas ? dto.areas : []
|
||||
}
|
||||
return this.model.create(item)
|
||||
|
||||
|
||||
}
|
||||
|
||||
async findAll(): Promise<Stock[]> {
|
||||
return this.model.find({});
|
||||
}
|
||||
|
||||
|
||||
async findOne(id: string): Promise<StockDto> {
|
||||
const item = await this.model.findById(id);
|
||||
|
||||
if (!item) throw new NotFoundException('Stock nicht gefunden');
|
||||
const stock = item;
|
||||
|
||||
const location = await this.locationService.getNode(stock.locationId.toString())
|
||||
if(!location) throw new NotFoundException('Location ion vom Stock nicht gefunden');
|
||||
|
||||
const retItem:StockDto = {
|
||||
id : stock._id.toString(),
|
||||
name: stock.name,
|
||||
location:location
|
||||
}
|
||||
return retItem;
|
||||
}
|
||||
|
||||
|
||||
update(id: string, dto: StockUpdateDto) {
|
||||
console.log('update service')
|
||||
return this.model.findByIdAndUpdate(id, dto, { new: true });
|
||||
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
console.log('all variants deleted')
|
||||
return this.model.findByIdAndDelete(id);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
|
||||
import { IsMongoId, IsOptional, IsString } from 'class-validator';
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { Types } from 'mongoose';
|
||||
|
||||
export class LocationCreateDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsMongoId()
|
||||
parentLocationId?: Types.ObjectId;
|
||||
}
|
||||
|
||||
export class LocationUpdateDto extends PartialType(LocationCreateDto) { }
|
||||
|
||||
export class LocationNodeDto {
|
||||
@IsString()
|
||||
_id: Types.ObjectId;
|
||||
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
|
||||
parentLocationId: Types.ObjectId;
|
||||
children: LocationNodeDto[];
|
||||
}
|
||||
|
||||
export class LocationDto {
|
||||
id: string;
|
||||
name: string;
|
||||
parentLocation?: LocationViewDto;
|
||||
children?: LocationViewDto[];
|
||||
}
|
||||
|
||||
export class LocationViewDto {
|
||||
id: string;
|
||||
name: string;
|
||||
parentLocation?: string;
|
||||
}
|
||||
|
||||
export class LocationRawDto {
|
||||
_id: string;
|
||||
name: string;
|
||||
parentLocationId?: Types.ObjectId;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||
import { Document, Types } from 'mongoose';
|
||||
|
||||
@Schema({ timestamps: true })
|
||||
export class Location extends Document {
|
||||
@Prop({ required: true })
|
||||
name: string;
|
||||
|
||||
@Prop()
|
||||
description?: string;
|
||||
|
||||
@Prop({ type: Types.ObjectId, ref: 'Location' })
|
||||
parentLocationId: Types.ObjectId
|
||||
|
||||
}
|
||||
|
||||
export const LocationSchema = SchemaFactory.createForClass(Location);
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { LocationsService } from './locations.service';
|
||||
import { LocationCreateDto, LocationNodeDto ,LocationUpdateDto} from './dto/location.dto';
|
||||
|
||||
|
||||
@Controller('locations')
|
||||
export class LocationsController {
|
||||
constructor(private readonly locationsService: LocationsService) {}
|
||||
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.locationsService.findAll();
|
||||
}
|
||||
|
||||
@Get('/childs')
|
||||
findAllChilds():Promise<LocationNodeDto[]> {
|
||||
console.log('getTRee')
|
||||
return this.locationsService.getTree();
|
||||
//return this.locationsService.findAllChilds(id);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.locationsService.findOne(id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() createLocationDto: LocationCreateDto) {
|
||||
return this.locationsService.create(createLocationDto);
|
||||
}
|
||||
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateLocationDto: LocationUpdateDto) {
|
||||
return this.locationsService.update(id, updateLocationDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.locationsService.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { Location, LocationSchema } from './entities/location.entity';
|
||||
|
||||
import { LocationsService } from './locations.service';
|
||||
import { LocationsController } from './locations.controller';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MongooseModule.forFeature([
|
||||
{ name: Location.name, schema: LocationSchema },
|
||||
])
|
||||
],
|
||||
controllers: [LocationsController],
|
||||
providers: [LocationsService],
|
||||
exports:[LocationsService]
|
||||
})
|
||||
export class LocationsModule {}
|
||||
@@ -0,0 +1,132 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { LocationCreateDto, LocationDto, LocationNodeDto, LocationRawDto, LocationViewDto, LocationUpdateDto } from './dto/location.dto';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model, Types } from 'mongoose';
|
||||
import { Location } from './entities/location.entity';
|
||||
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class LocationsService {
|
||||
|
||||
constructor(@InjectModel(Location.name) private locationModel: Model<Location>) { }
|
||||
|
||||
create(dto: LocationCreateDto) {
|
||||
|
||||
let {name,description,parentLocationId } = dto;
|
||||
|
||||
return this.locationModel.create({
|
||||
name,
|
||||
parentLocationId: new Types.ObjectId(parentLocationId),
|
||||
description
|
||||
});
|
||||
}
|
||||
|
||||
update(id: string, dto: LocationUpdateDto) {
|
||||
let {name,description,parentLocationId } = dto;
|
||||
|
||||
let update:LocationUpdateDto ={};
|
||||
if(name) update['name'] = name;
|
||||
if(description) update['description'] = description;
|
||||
if(parentLocationId) update['parentLocationId'] = new Types.ObjectId(parentLocationId);
|
||||
|
||||
return this.locationModel.findByIdAndUpdate(id, update, { new: true });
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.locationModel
|
||||
.find();
|
||||
}
|
||||
|
||||
async findOne(id: string): Promise<LocationRawDto> {
|
||||
const location = await this.locationModel.findById(id) as LocationRawDto || null;
|
||||
if (!location) throw new NotFoundException('location nicht gefunden');
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
async getNode(id: string): Promise<LocationDto> {
|
||||
const location = await this.findOne(id);
|
||||
|
||||
let retValue: LocationDto = {
|
||||
id: location._id,
|
||||
name: location.name,
|
||||
}
|
||||
|
||||
//--- Parent suchen, wenn vorhanden
|
||||
let parent: LocationRawDto | undefined = undefined;
|
||||
|
||||
if (location.parentLocationId) {
|
||||
parent = await this.findOne(location.parentLocationId.toString());
|
||||
|
||||
retValue['parentLocation'] = {
|
||||
id: parent._id,
|
||||
name: parent.name,
|
||||
parentLocation: parent.parentLocationId?.toString()
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
//--- Childs suchen
|
||||
const childs = await this.findLocationChilds(location._id);
|
||||
console.log(location._id,childs);
|
||||
retValue['children'] = childs.map(i => this.convert_Row_To_LocationDto(i));
|
||||
|
||||
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
|
||||
async findLocationChilds(parentId: string): Promise<LocationRawDto[]> {
|
||||
const childs = await this.locationModel.find({ parentLocationId: parentId }) as LocationRawDto[];
|
||||
return childs;
|
||||
}
|
||||
|
||||
async findAllChilds(id: string) {
|
||||
const location = await this.locationModel.findById(id);
|
||||
const childs = await this.locationModel.find({ parentLocationId: id });
|
||||
if (childs.length == 0) {
|
||||
return await this.locationModel.find({ parentLocationId: { $exists: false } }).lean();
|
||||
} else {
|
||||
return childs;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async getTree(): Promise<LocationNodeDto[]> {
|
||||
const locations = await this.locationModel.find().lean();
|
||||
|
||||
const map = new Map<string, LocationNodeDto>();
|
||||
locations.forEach(l => map.set(l._id.toString(), { ...l, children: [] }));
|
||||
|
||||
const tree: LocationNodeDto[] = [];
|
||||
|
||||
map.forEach(loc => {
|
||||
if (loc.parentLocationId) {
|
||||
map.get(loc.parentLocationId.toString())?.children.push(loc);
|
||||
} else {
|
||||
tree.push(loc);
|
||||
}
|
||||
});
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
|
||||
remove(id: string) {
|
||||
return this.locationModel.findByIdAndDelete(id);
|
||||
}
|
||||
|
||||
convert_Row_To_LocationDto(raw: LocationRawDto): LocationViewDto {
|
||||
|
||||
let item: LocationViewDto = {
|
||||
id: raw._id,
|
||||
name: raw.name
|
||||
}
|
||||
if (raw.parentLocationId) item['parentLocationId'] = raw.parentLocationId.toString();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
whitelist: true, // strips unknown fields
|
||||
forbidNonWhitelisted: true,
|
||||
transform: true, // auto-transform payloads to DTO classes
|
||||
})
|
||||
);
|
||||
await app.listen(process.env.PORT ?? 3000);
|
||||
}
|
||||
bootstrap();
|
||||
@@ -0,0 +1,59 @@
|
||||
|
||||
class DrawContainer{
|
||||
elements = new Map<number,DrawContainer|DrawElement>();
|
||||
|
||||
add(item:DrawContainer|DrawElement){
|
||||
const elNr = this.elements.size
|
||||
this.elements.set(elNr,item);
|
||||
}
|
||||
|
||||
getElements(){
|
||||
return this.elements;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class DrawElement{
|
||||
attributes = new Map<string,string|number>();
|
||||
|
||||
constructor(protected name:string){}
|
||||
|
||||
abstract getName():string;
|
||||
abstract getAttString():string;
|
||||
}
|
||||
|
||||
interface ElypI{
|
||||
x:number,
|
||||
y:number
|
||||
}
|
||||
|
||||
class Elipse extends DrawElement{
|
||||
constructor(name:string){
|
||||
super(name);
|
||||
}
|
||||
|
||||
getName(){ return this.name}
|
||||
|
||||
getAttString(): string {
|
||||
return "att1=1";
|
||||
}
|
||||
|
||||
setAtrr(att:Partial<ElypI>){
|
||||
Object.entries(att).forEach(([key, value]) => {
|
||||
this.attributes.set(key,value);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const c1 = new DrawContainer();
|
||||
const c2 = new DrawContainer();
|
||||
const ely1 = new Elipse('e1');
|
||||
const ely2 = new Elipse('e2');
|
||||
c1.add(ely1);
|
||||
c1.add(ely2);
|
||||
c1.add(c2);
|
||||
const ele = c1.getElements();
|
||||
|
||||
for (const [key, value] of ele) {
|
||||
if( value instanceof DrawElement) console.log(value.getName)
|
||||
console.log(key, value);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { IsString, IsEmail, IsOptional, IsInt, Min } from 'class-validator';
|
||||
|
||||
export class CreateUserDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsEmail()
|
||||
email: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
age?: number;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateUserDto } from './create-user.dto';
|
||||
|
||||
export class UpdateUserDto extends PartialType(CreateUserDto) {}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||
import { Document } from 'mongoose';
|
||||
|
||||
@Schema()
|
||||
export class User extends Document {
|
||||
@Prop({ required: true })
|
||||
name: string;
|
||||
|
||||
@Prop({ required: true, unique: true })
|
||||
email: string;
|
||||
|
||||
}
|
||||
|
||||
export const UserSchema = SchemaFactory.createForClass(User);
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { UsersService } from './users.service';
|
||||
import { CreateUserDto } from './dto/create-user.dto';
|
||||
import { UpdateUserDto } from './dto/update-user.dto';
|
||||
|
||||
@Controller('users')
|
||||
export class UsersController {
|
||||
constructor(private readonly usersService: UsersService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createUserDto: CreateUserDto) {
|
||||
return this.usersService.create(createUserDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.usersService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.usersService.findOne(id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
|
||||
return this.usersService.update(id, updateUserDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.usersService.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { User, UserSchema } from './entities/user.entity';
|
||||
import { UsersService } from './users.service';
|
||||
import { UsersController } from './users.controller';
|
||||
@Module({
|
||||
imports: [MongooseModule.forFeature([{ name: User.name, schema: UserSchema }])],
|
||||
controllers: [UsersController],
|
||||
providers: [UsersService],
|
||||
})
|
||||
export class UsersModule {}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
import { User } from './entities/user.entity';
|
||||
import { CreateUserDto } from './dto/create-user.dto';
|
||||
import { UpdateUserDto } from './dto/update-user.dto';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
constructor(@InjectModel(User.name) private userModel: Model<User>) { }
|
||||
|
||||
async create(createUserDto: CreateUserDto) {
|
||||
const createdUser = new this.userModel(createUserDto);
|
||||
return createdUser.save();
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
return this.userModel.find().exec();
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
const user = await this.userModel.findById(id).exec();
|
||||
if (!user) throw new NotFoundException(`User ${id} not found`);
|
||||
return user;
|
||||
}
|
||||
|
||||
async update(id: string, updateUserDto: UpdateUserDto) {
|
||||
const updatedUser = await this.userModel
|
||||
.findByIdAndUpdate(id, updateUserDto, { new: true })
|
||||
.exec();
|
||||
if (!updatedUser) throw new NotFoundException(`User ${id} not found`);
|
||||
return updatedUser;
|
||||
}
|
||||
|
||||
async remove(id: string):Promise<void> {
|
||||
const result = await this.userModel.findByIdAndDelete(id).exec();
|
||||
if (!result) throw new NotFoundException(`User ${id} not found`);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import request from 'supertest';
|
||||
import { App } from 'supertest/types';
|
||||
import { AppModule } from '../src/app.module.ts_ald';
|
||||
|
||||
describe('AppController (e2e)', () => {
|
||||
let app: INestApplication<App>;
|
||||
|
||||
beforeEach(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
}).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
await app.init();
|
||||
});
|
||||
|
||||
it('/ (GET)', () => {
|
||||
return request(app.getHttpServer())
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect('Hello World!');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"moduleFileExtensions": ["js", "json", "ts"],
|
||||
"rootDir": ".",
|
||||
"testEnvironment": "node",
|
||||
"testRegex": ".e2e-spec.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "nodenext",
|
||||
"moduleResolution": "nodenext",
|
||||
"resolvePackageJsonExports": true,
|
||||
"esModuleInterop": true,
|
||||
"isolatedModules": true,
|
||||
"declaration": true,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "ES2023",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
"strictNullChecks": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noImplicitAny": false,
|
||||
"strictBindCallApply": false,
|
||||
"noFallthroughCasesInSwitch": false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/versions
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# env files (can opt-in for committing if needed)
|
||||
.env*
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
@@ -0,0 +1,36 @@
|
||||
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
||||
|
||||
## Getting Started
|
||||
|
||||
First, run the development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
# or
|
||||
yarn dev
|
||||
# or
|
||||
pnpm dev
|
||||
# or
|
||||
bun dev
|
||||
```
|
||||
|
||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||
|
||||
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
||||
|
||||
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
||||
|
||||
## Learn More
|
||||
|
||||
To learn more about Next.js, take a look at the following resources:
|
||||
|
||||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||
|
||||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
||||
|
||||
## Deploy on Vercel
|
||||
|
||||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||
|
||||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
export const endpoints = {
|
||||
apiServer: { url: 'http://192.168.50.205/api' },
|
||||
test: { url: '/test' },
|
||||
category: {
|
||||
url: "/category",
|
||||
name:"Kategorien",
|
||||
new: { url: "/category/new" },
|
||||
update: { url: "/category/update", param: "id" }
|
||||
},
|
||||
manufacturer: {
|
||||
url: "/manufacturer",
|
||||
new: { url: "/manufacturer/new",name:"Hersteller" },
|
||||
update: { url: "/manufacturer/update", param: "id" }
|
||||
},
|
||||
article: {
|
||||
url: "/catalog/article/",
|
||||
new: { url: "/catalog/article/new" },
|
||||
update: { url: "/catalog/article/", param: "id" }
|
||||
},
|
||||
stock: {
|
||||
url: "/stock/movement/",
|
||||
new: { url: "/stock/movement/new" },
|
||||
update: { url: "/stock/", param: "id" }
|
||||
},
|
||||
location: {
|
||||
url: "/locations",
|
||||
name:"Lagerorte",
|
||||
treeView:{
|
||||
url:"/locations/childs",
|
||||
name:"Get Tree View",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
|
||||
|
||||
export const sites = {
|
||||
main: { url: '/' },
|
||||
test: { url: '/test' },
|
||||
category: {
|
||||
url: "/category",
|
||||
name:"Kategorien",
|
||||
new: { url: "/category/new" },
|
||||
update: { url: "/category/update", param: "id" }
|
||||
},
|
||||
manufacturer: {
|
||||
url: "/manufacturer",
|
||||
new: { url: "/manufacturer/new",name:"Hersteller" },
|
||||
update: { url: "/manufacturer/update", param: "id" }
|
||||
},
|
||||
article: {
|
||||
url: "/catalog/article/",
|
||||
new: { url: "/catalog/article/new" },
|
||||
update: { url: "/catalog/article/", param: "id" }
|
||||
},
|
||||
stock: {
|
||||
url: "/stock/movement/",
|
||||
new: { url: "/stock/movement/new" },
|
||||
update: { url: "/stock/", param: "id" }
|
||||
},
|
||||
location: {
|
||||
url: "/location/",
|
||||
name:"Lagerorte",
|
||||
new: { url: "/location/new",name:"Lagerort anlegen" },
|
||||
update: { url: "/location/edit", param: "id", name:"Lagerort bearbeiten" }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
export const checkEmail = {
|
||||
required: "Email ist Pflicht",
|
||||
pattern: {
|
||||
value: /^\S+@\S+$/i,
|
||||
message: "Ungültige Email",
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
'use server'
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { Article, ArticleCreate, ArticleUpsert } from "@/apps/frontend/types/catalog";
|
||||
import { sites } from '../_config/sites';
|
||||
|
||||
export async function articleCreate(data: ArticleCreate) {
|
||||
console.log(data);
|
||||
const result = await fetch('http://192.168.50.205/api/articles', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
|
||||
const resultData = await result.json();
|
||||
|
||||
if (!result.ok) {
|
||||
return {
|
||||
success: false,
|
||||
errors: resultData.message, // kommt aus NestJS
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
revalidatePath(sites.article.new.url)
|
||||
}
|
||||
|
||||
export async function articleUpdate(id: string, data: ArticleUpsert): Promise<ActionResult> {
|
||||
|
||||
const result = await fetch(`http://192.168.50.205/api/articles/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
|
||||
const resultData = await result.json();
|
||||
|
||||
if (!result.ok) {
|
||||
return {
|
||||
success: false,
|
||||
errors: resultData.message, // kommt aus NestJS
|
||||
};
|
||||
}
|
||||
|
||||
revalidatePath(sites.article.update.url + '/' + id);
|
||||
return { success: true };
|
||||
|
||||
}
|
||||
|
||||
export async function articleFindAll(): Promise<Article[]> {
|
||||
|
||||
const result = await fetch(`http://192.168.50.205/api/articles`, {
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
const data = await result.json() as Article[];
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function articleFindById(id: string): Promise<any> {
|
||||
|
||||
const result = await fetch(`http://192.168.50.205/api/articles/${id}`, {
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
const data = await result.json() as Article
|
||||
console.log('getArticle', data)
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
export async function articleDelete(id: string,revalidateUrl?:string): Promise<ActionResult> {
|
||||
|
||||
|
||||
const result = await fetch(`http://192.168.50.205/api/articles/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
|
||||
const resultData = await result.json();
|
||||
|
||||
if (!result.ok) {
|
||||
return {
|
||||
success: false,
|
||||
errors: resultData.message, // kommt aus NestJS
|
||||
};
|
||||
}
|
||||
|
||||
if(revalidateUrl) revalidatePath(revalidateUrl);
|
||||
|
||||
return { success: true };
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
'use server'
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { Category, CategoryCreate } from "@/apps/frontend/types/catalog";
|
||||
|
||||
export async function categoryCreate(data: CategoryCreate) {
|
||||
console.log(data);
|
||||
const result = await fetch('http://192.168.50.205/api/categories', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
console.log(result);
|
||||
|
||||
revalidatePath('/test')
|
||||
}
|
||||
|
||||
export async function categoryUpdate( id: string, data: Partial<CategoryCreate>) {
|
||||
console.log(data,id);
|
||||
const result = await fetch(`http://192.168.50.205/api/categories/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
console.log(result);
|
||||
revalidatePath('/test')
|
||||
}
|
||||
|
||||
export async function categoryFindAll():Promise<Category[]> {
|
||||
|
||||
const result = await fetch(`http://192.168.50.205/api/categories`, {
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
const data = await result.json();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function categoryFindById(id:string):Promise<Category> {
|
||||
|
||||
const result = await fetch(`http://192.168.50.205/api/categories/${id}`, {
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
const data = await result.json();
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
'use server'
|
||||
|
||||
import { Location, LocationCreate, LocationTreeNode, LocationUpdate } from "../types/inventory";
|
||||
import { endpoints } from '../_config/endpoints';
|
||||
import { revalidateTag, revalidatePath } from "next/cache"
|
||||
|
||||
export async function locationCreate(data: LocationCreate) {
|
||||
console.log(`${endpoints.apiServer}${endpoints.location}`);
|
||||
const result = await fetch(`${endpoints.apiServer.url}${endpoints.location.url}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
|
||||
const respData = await result.json();
|
||||
revalidateTag("location", "default");
|
||||
return respData;
|
||||
|
||||
console.log(data)
|
||||
}
|
||||
|
||||
export async function locationUpdate(id: string, data: LocationUpdate) {
|
||||
|
||||
const result = await fetch(`${endpoints.apiServer.url}${endpoints.location.url}/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
|
||||
const respData = await result.json();
|
||||
revalidateTag("location", "default");
|
||||
|
||||
return respData;
|
||||
}
|
||||
|
||||
export async function locationFindAll(): Promise<Location[]> {
|
||||
|
||||
const result = await fetch(`${endpoints.apiServer.url}${endpoints.location.url}`, {
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
const data = await result.json();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function locationTree(): Promise<LocationTreeNode[]> {
|
||||
|
||||
const result = await fetch(`${endpoints.apiServer.url}${endpoints.location.treeView.url}`, {
|
||||
next: { tags: ["location"] },
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
const data = await result.json();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
export async function locationFindById(id: string): Promise<Location> {
|
||||
|
||||
const result = await fetch(`${endpoints.apiServer.url}${endpoints.location.url}/${id}`, {
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
const respData = await result.json();
|
||||
|
||||
return respData;
|
||||
}
|
||||
Loaded 100 of 175 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user