@rytass/wms-module-core 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -1
- package/docs/README.md +2 -0
- package/docs/api-reference.md +21 -1
- package/docs/custom-entities.md +192 -0
- package/index.cjs.js +80 -7
- package/lib/core.module.js +35 -1
- package/lib/models/models.module.js +14 -1
- package/lib/services/material.service.d.ts +15 -1
- package/lib/services/material.service.js +20 -0
- package/lib/services/receive-inventory-order.service.js +2 -2
- package/lib/services/reclassify-inventory-order.service.js +2 -2
- package/lib/services/ship-inventory-order.service.js +3 -3
- package/lib/services/stock.service.d.ts +1 -1
- package/lib/services/stock.service.js +10 -3
- package/lib/typings/entity-overrides.d.ts +34 -0
- package/lib/typings/entity-overrides.js +7 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -69,7 +69,33 @@ Exported services include `LoaderService`, `MaterialService`, `BatchService`, `S
|
|
|
69
69
|
|
|
70
70
|
## Extending entities
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
Each entity is exported in two forms — `MaterialEntity` (a `Symbol` DI token) and `MaterialEntityClass` (the entity class the token is bound to). Everything inside the module resolves entities through the token, so rebinding the token swaps the entity everywhere at once.
|
|
73
|
+
|
|
74
|
+
`materialEntity` is the override that is wired all the way through today. Give it a `@ChildEntity()` of `MaterialEntityClass` and your own table *is* the WMS material master — no second table, no double writes:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { ChildEntity, Column } from 'typeorm';
|
|
78
|
+
import { MaterialEntityClass, WmsModuleCoreModule } from '@rytass/wms-module-core';
|
|
79
|
+
|
|
80
|
+
@ChildEntity()
|
|
81
|
+
export class ItemMasterEntity extends MaterialEntityClass {
|
|
82
|
+
@Column({ type: 'varchar', nullable: true })
|
|
83
|
+
erpCode!: string | null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
WmsModuleCoreModule.forRootAsync({
|
|
87
|
+
useFactory: async () => ({ materialEntity: ItemMasterEntity }),
|
|
88
|
+
defaultLoaderSerialId: 'DEFAULT',
|
|
89
|
+
defaultLoaderTypeKey: 'DEFAULT',
|
|
90
|
+
defaultLocationKey: 'DEFAULT',
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
It is an ordinary `WMSBaseModuleOptions` field, so `forRoot` and the async factory both work. The base module resolves its repository from it and this package binds its `MaterialEntity` Symbol from the same `PROVIDE_MATERIAL_ENTITY` token at injection time — one option, two consumers, no way for them to drift. This needs `@rytass/wms-base-nestjs-module` >= 0.3.0, the release that exports those tokens.
|
|
95
|
+
|
|
96
|
+
**You register the entity with TypeORM yourself** (`TypeOrmModule.forFeature([ItemMasterEntity])`, or the DataSource's `entities`). The module cannot: `forFeature()` runs while Nest assembles the module graph, before the options resolve. Forgetting it almost works — TypeORM still creates your columns in `materials` — so the module checks at startup and refuses to boot with a message telling you what to add.
|
|
97
|
+
|
|
98
|
+
The remaining entity options on `WMSBaseModuleOptions` (`batchEntity`, `locationEntity`, `stockEntity`, `orderEntity`, `warehouseMapEntity`) still resolve only a base-module repository this package does not read — setting them has no effect above the base layer. [`docs/custom-entities.md`](./docs/custom-entities.md) has the full picture, the single-table-inheritance caveats for pre-existing rows, and the per-option audit.
|
|
73
99
|
|
|
74
100
|
## Module options token
|
|
75
101
|
|
|
@@ -83,6 +109,7 @@ Full documentation is shipped inside this package under the `docs/` directory (a
|
|
|
83
109
|
|---|---|
|
|
84
110
|
| [`docs/integration-guide.md`](./docs/integration-guide.md) | Step-by-step wiring guide for NestJS + Next.js consumers |
|
|
85
111
|
| [`docs/api-reference.md`](./docs/api-reference.md) | Complete export catalog with signatures and usage examples |
|
|
112
|
+
| [`docs/custom-entities.md`](./docs/custom-entities.md) | Using your own entity as the WMS material master, and the audit of the other entity options |
|
|
86
113
|
|
|
87
114
|
GitHub hosted links (always up-to-date):
|
|
88
115
|
|
package/docs/README.md
CHANGED
|
@@ -8,6 +8,7 @@ Reference material for consumers of `@rytass/wms-module-{core,graphql,react}`.
|
|
|
8
8
|
|------------------------------------------------|---------------------------------------------------------------------------------------------------|
|
|
9
9
|
| [Integration Guide](./integration-guide.md) | Step-by-step instructions for wiring the three packages into a new consumer project (NestJS + Next.js + PostgreSQL). Includes ready-to-paste `_app.tsx`, `app.module.ts`, `next.config.ts`, the 19 Pages Router shell pattern, AuthGuard stub, seed script template, deployment notes, and known issues. |
|
|
10
10
|
| [API Reference](./api-reference.md) | Complete export catalog for all three packages — every NestJS module, TypeORM entity, GraphQL resolver, DTO, React component, hook, and utility, organized by role with source paths and usage examples. Mirrors the actual `src/index.ts` barrel exports of v0.1.2. |
|
|
11
|
+
| [Custom Entities](./custom-entities.md) | How to make a downstream project's own table serve as the WMS's own — the `materialEntity` override, why entity classes are configured synchronously, what single-table inheritance means for existing rows, and an audit of the entity options that are not honoured above the base layer yet. |
|
|
11
12
|
|
|
12
13
|
## Quick links
|
|
13
14
|
|
|
@@ -25,6 +26,7 @@ Reference material for consumers of `@rytass/wms-module-{core,graphql,react}`.
|
|
|
25
26
|
| Replace the `AuthGuard` stub with real auth | [Integration Guide section 8.4](./integration-guide.md#84-real-auth-integration) |
|
|
26
27
|
| Decide between PostgreSQL and SQLite | [Integration Guide section 9](./integration-guide.md#9-database-support-matrix) |
|
|
27
28
|
| Build a custom UI on top of the lib's GraphQL operations| [Integration Guide section 7.3](./integration-guide.md#73-graphql-operations--typed-hooks) |
|
|
29
|
+
| Use your own item master as the WMS material entity | [Custom Entities](./custom-entities.md) |
|
|
28
30
|
|
|
29
31
|
## Versioning
|
|
30
32
|
|
package/docs/api-reference.md
CHANGED
|
@@ -26,7 +26,7 @@ This document mirrors the actual `src/index.ts` barrel exports and is generated
|
|
|
26
26
|
**`forRoot(options, coreOptions): DynamicModule`**
|
|
27
27
|
```ts
|
|
28
28
|
static forRoot(
|
|
29
|
-
options: WMSBaseModuleOptions,
|
|
29
|
+
options: WMSBaseModuleOptions, // @rytass/wms-base-nestjs-module 選項(DB 連線、entity override 等)
|
|
30
30
|
coreOptions: WmsModuleCoreModuleOptions, // defaultLoaderSerialId / defaultLoaderTypeKey / defaultLocationKey
|
|
31
31
|
): DynamicModule
|
|
32
32
|
```
|
|
@@ -38,8 +38,28 @@ static forRootAsync(
|
|
|
38
38
|
): DynamicModule
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
**Entity override(since 0.4.0,需 `@rytass/wms-base-nestjs-module` >= 0.3.0)**
|
|
42
|
+
|
|
43
|
+
`WMSBaseModuleOptions.materialEntity` 現在會一路作用到 core 與 graphql。傳入的 class 必須是 `MaterialEntityClass` 的 `@ChildEntity()`:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
WmsModuleCoreModule.forRootAsync({
|
|
47
|
+
useFactory: async () => ({ materialEntity: ItemMasterEntity }),
|
|
48
|
+
defaultLoaderSerialId: 'DEFAULT',
|
|
49
|
+
defaultLoaderTypeKey: 'DEFAULT',
|
|
50
|
+
defaultLocationKey: 'DEFAULT',
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
- `forRoot` 與 async factory 皆可,因為 `MaterialEntity` Symbol 是在 **DI 時**由基座 export 的 `PROVIDE_MATERIAL_ENTITY` 綁定,不是在 module graph 組裝時。
|
|
55
|
+
- 基座的 `RESOLVED_MATERIAL_REPO` 與 core 的 `MaterialEntity` 由**同一個 option** 推導,結構上不可能不一致。
|
|
56
|
+
- **entity 需自行註冊給 TypeORM**(`TypeOrmModule.forFeature([ItemMasterEntity])` 或 DataSource `entities`);模組無法代勞,漏掉時會在啟動階段丟出明確錯誤。
|
|
57
|
+
- 非 `MaterialEntityClass` 子類會在啟動時被拒絕(TypeScript 結構型別擋不住兄弟類別)。
|
|
58
|
+
- 其餘 entity 選項(`batchEntity` / `locationEntity` / `stockEntity` / `orderEntity` / `warehouseMapEntity`)目前仍只作用於 base module。詳見 [`custom-entities.md`](./custom-entities.md)。
|
|
59
|
+
|
|
41
60
|
### `ModelsModule`
|
|
42
61
|
- 用途: 內部模組,向 TypeORM 註冊所有 WMS 實體(via DI token 形式),並透過 `ResolvedEntitiesProviders` 提供 DI。**消費端不直接 import**;它由 `WmsModuleCoreModule.forRoot` 自動引入並 re-export。
|
|
62
|
+
- `MaterialEntity` Symbol **不由此模組綁定**:它在 `WmsModuleCoreModule` 內由 `PROVIDE_MATERIAL_ENTITY` 推導,避免同一個 token 出現兩個繫結。`MaterialEntityClass` 仍註冊進 `forFeature()`(它是單表繼承的根)。
|
|
43
63
|
- 來源: `lib/models/models.module.ts`
|
|
44
64
|
|
|
45
65
|
---
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# Custom entities
|
|
2
|
+
|
|
3
|
+
How to make a downstream project's own table the WMS's table, instead of keeping
|
|
4
|
+
a second one in sync.
|
|
5
|
+
|
|
6
|
+
> Applies to `@rytass/wms-module-core` and `@rytass/wms-module-graphql`.
|
|
7
|
+
> Currently supported for **materials**; see the [audit](#6-audit-of-the-remaining-entity-options)
|
|
8
|
+
> for where the other entities stand.
|
|
9
|
+
>
|
|
10
|
+
> Requires `@rytass/wms-base-nestjs-module` >= 0.3.0, which is the release that
|
|
11
|
+
> exports the resolved entity tokens this depends on.
|
|
12
|
+
|
|
13
|
+
## Table of Contents
|
|
14
|
+
|
|
15
|
+
1. [What the option does](#1-what-the-option-does)
|
|
16
|
+
2. [Writing the entity](#2-writing-the-entity)
|
|
17
|
+
3. [Passing it to the module](#3-passing-it-to-the-module)
|
|
18
|
+
4. [Registering the entity with TypeORM](#4-registering-the-entity-with-typeorm)
|
|
19
|
+
5. [What single-table inheritance means for your data](#5-what-single-table-inheritance-means-for-your-data)
|
|
20
|
+
6. [Audit of the remaining entity options](#6-audit-of-the-remaining-entity-options)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 1. What the option does
|
|
25
|
+
|
|
26
|
+
`@rytass/wms-base-nestjs-module` has always accepted a `materialEntity` in
|
|
27
|
+
`WMSBaseModuleOptions`, but it kept the resolved entity to itself: the token was
|
|
28
|
+
never exported, so `@rytass/wms-module-core` could not read it and bound its
|
|
29
|
+
`MaterialEntity` Symbol to the built-in `MaterialEntityClass` unconditionally.
|
|
30
|
+
The option therefore changed nothing above the base layer.
|
|
31
|
+
|
|
32
|
+
`wms-base` 0.3.0 exports `PROVIDE_MATERIAL_ENTITY` and `RESOLVED_MATERIAL_REPO`
|
|
33
|
+
(the same shape `@rytass/member-base-nestjs-module` has always used for
|
|
34
|
+
`memberEntity`), and the core module now binds its Symbol from that token at
|
|
35
|
+
injection time.
|
|
36
|
+
|
|
37
|
+
Passing `materialEntity` now rebinds every place the module reads or writes
|
|
38
|
+
materials:
|
|
39
|
+
|
|
40
|
+
| Consumer of the material entity | Where it lives |
|
|
41
|
+
|--------------------------------------------------------|-----------------------------------------------------------|
|
|
42
|
+
| `MaterialEntity` Symbol (and its TypeORM registration) | `libs/core/src/lib/models/models.module.ts` |
|
|
43
|
+
| `MaterialService` (create / update / find) | `libs/core/src/lib/services/material.service.ts` |
|
|
44
|
+
| Receive order item resolution | `libs/core/src/lib/services/receive-inventory-order.service.ts` |
|
|
45
|
+
| Ship order reference resolution (create and update) | `libs/core/src/lib/services/ship-inventory-order.service.ts` |
|
|
46
|
+
| Reclassify target resolution | `libs/core/src/lib/services/reclassify-inventory-order.service.ts` |
|
|
47
|
+
| `materialKey` stock filter and material grouping | `libs/core/src/lib/services/stock.service.ts` |
|
|
48
|
+
| Every GraphQL `material` DataLoader | `libs/graphql/src/lib/resolvers/*.resolver.ts` |
|
|
49
|
+
| `RESOLVED_MATERIAL_REPO` in the base module | resolved from the same option — cannot drift |
|
|
50
|
+
|
|
51
|
+
## 2. Writing the entity
|
|
52
|
+
|
|
53
|
+
The entity must be a TypeORM `@ChildEntity()` extending `MaterialEntityClass`.
|
|
54
|
+
It joins the existing `materials` table through single-table inheritance; it does
|
|
55
|
+
not move the data anywhere.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { ChildEntity, Column, Index } from 'typeorm';
|
|
59
|
+
import { MaterialEntityClass } from '@rytass/wms-module-core';
|
|
60
|
+
|
|
61
|
+
@ChildEntity()
|
|
62
|
+
export class ItemMasterEntity extends MaterialEntityClass {
|
|
63
|
+
@Column({ type: 'varchar', nullable: true })
|
|
64
|
+
@Index()
|
|
65
|
+
erpCode!: string | null;
|
|
66
|
+
|
|
67
|
+
@Column({ type: 'varchar', nullable: true })
|
|
68
|
+
vendorPartNumber!: string | null;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Rules:
|
|
73
|
+
|
|
74
|
+
- **Extend `MaterialEntityClass`, not the base `MaterialEntity`.** The module's
|
|
75
|
+
services and the `MaterialDto` GraphQL type read `description`, `baseUnit` and
|
|
76
|
+
`isActive`, which `MaterialEntityClass` declares.
|
|
77
|
+
- **New columns must be nullable or have a default.** Rows written before the
|
|
78
|
+
override existed carry the old discriminator and have no value for them.
|
|
79
|
+
- **Do not re-declare `@Entity()` or `@TableInheritance()`.** Both belong to the
|
|
80
|
+
base `MaterialEntity`; `@ChildEntity()` is the whole decoration you need.
|
|
81
|
+
|
|
82
|
+
## 3. Passing it to the module
|
|
83
|
+
|
|
84
|
+
`materialEntity` is a `WMSBaseModuleOptions` field, so it goes wherever the rest
|
|
85
|
+
of the base options go — including the async factory:
|
|
86
|
+
|
|
87
|
+
### `forRootAsync`
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
WmsModuleGraphqlModule.forRootAsync({
|
|
91
|
+
imports: [VaultModule],
|
|
92
|
+
inject: [VaultService],
|
|
93
|
+
useFactory: async (vault: VaultService) => ({
|
|
94
|
+
allowNegativeStock: await vault.get<boolean>('ALLOW_NEGATIVE_STOCK'),
|
|
95
|
+
materialEntity: ItemMasterEntity,
|
|
96
|
+
}),
|
|
97
|
+
|
|
98
|
+
defaultLoaderSerialId: 'DEFAULT',
|
|
99
|
+
defaultLoaderTypeKey: 'DEFAULT',
|
|
100
|
+
defaultLocationKey: 'DEFAULT',
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### `forRoot`
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
WmsModuleCoreModule.forRoot(
|
|
108
|
+
{ materialEntity: ItemMasterEntity },
|
|
109
|
+
{
|
|
110
|
+
defaultLoaderSerialId: 'DEFAULT',
|
|
111
|
+
defaultLoaderTypeKey: 'DEFAULT',
|
|
112
|
+
defaultLocationKey: 'DEFAULT',
|
|
113
|
+
},
|
|
114
|
+
);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
You pass it once. The base module resolves its repository from it and the core
|
|
118
|
+
module binds its `MaterialEntity` Symbol from it; both read the same option, so
|
|
119
|
+
there is no forwarding step that could get them out of step.
|
|
120
|
+
|
|
121
|
+
If the class does not extend `MaterialEntityClass`, the module refuses to boot —
|
|
122
|
+
`WMSBaseModuleOptions` only asks for a child of the *base* `MaterialEntity`, and
|
|
123
|
+
TypeScript's structural typing will not catch a sibling that happens to look
|
|
124
|
+
right.
|
|
125
|
+
|
|
126
|
+
## 4. Registering the entity with TypeORM
|
|
127
|
+
|
|
128
|
+
**You** register the override; the module cannot. `TypeOrmModule.forFeature()`
|
|
129
|
+
runs while Nest assembles the module graph, and the entity is not known until the
|
|
130
|
+
options resolve.
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
@Module({
|
|
134
|
+
imports: [
|
|
135
|
+
TypeOrmModule.forRoot({ /* ... */ autoLoadEntities: true }),
|
|
136
|
+
TypeOrmModule.forFeature([ItemMasterEntity]),
|
|
137
|
+
WmsModuleGraphqlModule.forRootAsync({ /* ... */ }),
|
|
138
|
+
],
|
|
139
|
+
})
|
|
140
|
+
export class AppModule {}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
`entities: [ItemMasterEntity, ...]` on the DataSource works just as well.
|
|
144
|
+
|
|
145
|
+
This is easy to forget, because forgetting it *almost* works: TypeORM copies a
|
|
146
|
+
single-table child's columns into its parent, so `synchronize` still creates your
|
|
147
|
+
columns in `materials` and the schema looks correct. Only the queries fail. The
|
|
148
|
+
module checks for it at startup and refuses to boot rather than letting an
|
|
149
|
+
`EntityMetadataNotFoundError` surface later from inside a resolver:
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
WmsModuleCoreModule: the configured materialEntity "ItemMasterEntity" is not
|
|
153
|
+
registered with TypeORM. Add it to your DataSource "entities", or import
|
|
154
|
+
TypeOrmModule.forFeature([ItemMasterEntity]) somewhere in your app when using
|
|
155
|
+
autoLoadEntities.
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## 5. What single-table inheritance means for your data
|
|
159
|
+
|
|
160
|
+
All material rows live in `materials`, and the `entityName` column records which
|
|
161
|
+
class wrote each one.
|
|
162
|
+
|
|
163
|
+
- Rows written **after** you configure the override carry your class's name.
|
|
164
|
+
- Rows written **before** it carry `MaterialEntityClass`, and your entity's
|
|
165
|
+
queries will not see them: a single-table query matches its own class and its
|
|
166
|
+
descendants, never its ancestors or siblings. Backfilling those rows
|
|
167
|
+
(`UPDATE materials SET "entityName" = 'ItemMasterEntity' WHERE …`) is a
|
|
168
|
+
consumer-side migration; the module does not attempt it.
|
|
169
|
+
- Reading through `MaterialEntityClass` still returns your rows, because your
|
|
170
|
+
class is a descendant of it. The asymmetry only bites in the other direction.
|
|
171
|
+
|
|
172
|
+
## 6. Audit of the remaining entity options
|
|
173
|
+
|
|
174
|
+
`WMSBaseModuleOptions` exposes six entity overrides. Only `materialEntity` is
|
|
175
|
+
honoured above the base layer today. The rest resolve a base-module repository
|
|
176
|
+
that `@rytass/wms-module-core` never reads, so setting them has no effect on core
|
|
177
|
+
or graphql:
|
|
178
|
+
|
|
179
|
+
| Option | Base token | Core Symbol | Status | Hard-coded call sites remaining |
|
|
180
|
+
|-----------------------|-------------------------------|---------------------|--------|------------------------------------------------------------------|
|
|
181
|
+
| `materialEntity` | `RESOLVED_MATERIAL_REPO` | `MaterialEntity` | supported | 0 |
|
|
182
|
+
| `batchEntity` | `RESOLVED_BATCH_REPO` | `BatchEntity` | not supported | 5 `getRepository(BatchEntityClass)` in core, 11 resolver `__entity` |
|
|
183
|
+
| `locationEntity` | `RESOLVED_TREE_LOCATION_REPO` | `LocationEntity` | not supported | 5 in core, 12 resolver `__entity` |
|
|
184
|
+
| `stockEntity` | `RESOLVED_STOCK_REPO` | `StockEntity` | not supported | 8 in core (services inject the Symbol *and* hard-code the class) |
|
|
185
|
+
| `orderEntity` | `RESOLVED_ORDER_REPO` | none | not supported | 17 `getRepository(OrderEntity)` on the base class directly |
|
|
186
|
+
| `warehouseMapEntity` | `RESOLVED_WAREHOUSE_MAP_REPO` | `WarehouseMapEntity`| not supported | `WarehouseMapDataService` resolves the base class directly |
|
|
187
|
+
|
|
188
|
+
All six tokens are exported by `wms-base` 0.3.0, so extending support to another
|
|
189
|
+
entity no longer needs a base-module change: bind its Symbol from the matching
|
|
190
|
+
`PROVIDE_*_ENTITY` in `WmsModuleCoreModule` the way `MaterialEntity` is bound,
|
|
191
|
+
then sweep the call sites listed above. `orderEntity` is the largest job and the
|
|
192
|
+
only one with no core Symbol at all.
|
package/index.cjs.js
CHANGED
|
@@ -2395,7 +2395,20 @@ const entities = [
|
|
|
2395
2395
|
[ScrapeOrderItemEntity, exports.ScrapeOrderItemEntityClass],
|
|
2396
2396
|
[ScrapeOrderChangeEntity, exports.ScrapeOrderChangeEntityClass],
|
|
2397
2397
|
];
|
|
2398
|
-
|
|
2398
|
+
/**
|
|
2399
|
+
* `MaterialEntity` is deliberately absent: `WmsModuleCoreModule` binds it to
|
|
2400
|
+
* whatever `WMSBaseModuleOptions.materialEntity` resolved to, which only a module
|
|
2401
|
+
* importing `WMSBaseModule` can read. Binding it here as well would leave two
|
|
2402
|
+
* live bindings for one token, and the loser would be whichever module the
|
|
2403
|
+
* injector happened to reach first.
|
|
2404
|
+
*
|
|
2405
|
+
* The class stays in `entities` above so TypeORM still registers it — it is the
|
|
2406
|
+
* root of the single-table hierarchy a consumer's override extends.
|
|
2407
|
+
*/
|
|
2408
|
+
const EXTERNALLY_BOUND_ENTITIES = new Set([MaterialEntity]);
|
|
2409
|
+
const ResolvedEntitiesProviders = entities
|
|
2410
|
+
.filter(([token]) => !EXTERNALLY_BOUND_ENTITIES.has(token))
|
|
2411
|
+
.map(([token, entity]) => ({
|
|
2399
2412
|
provide: token,
|
|
2400
2413
|
useValue: entity,
|
|
2401
2414
|
}));
|
|
@@ -2591,7 +2604,14 @@ exports.StockService = class StockService {
|
|
|
2591
2604
|
}
|
|
2592
2605
|
}
|
|
2593
2606
|
if (options.materialKey)
|
|
2594
|
-
queryBuilder.innerJoin(
|
|
2607
|
+
queryBuilder.innerJoin(
|
|
2608
|
+
// The configured entity, not the built-in class: this follows whatever
|
|
2609
|
+
// table that entity is mapped to. (TypeORM resolves an entity in a
|
|
2610
|
+
// hand-written join to its table name and does not append the
|
|
2611
|
+
// single-table discriminator, so for a child of `MaterialEntityClass` the
|
|
2612
|
+
// emitted SQL is unchanged — this keeps the service from reaching past
|
|
2613
|
+
// its own configuration, it is not a behaviour fix on its own.)
|
|
2614
|
+
this.materialEntity, 'mk', 'mk.id = stock."materialId" AND mk.key ILIKE :materialKey', {
|
|
2595
2615
|
materialKey: `%${options.materialKey}%`,
|
|
2596
2616
|
});
|
|
2597
2617
|
if (options.batchKey)
|
|
@@ -2827,7 +2847,7 @@ exports.StockService = tslib.__decorate([
|
|
|
2827
2847
|
tslib.__param(1, common.Inject(StockEntity)),
|
|
2828
2848
|
tslib.__param(2, common.Inject(MaterialEntity)),
|
|
2829
2849
|
tslib.__param(3, common.Inject(WMS_CORE_MODULE_OPTIONS)),
|
|
2830
|
-
tslib.__metadata("design:paramtypes", [typeorm.DataSource, Object,
|
|
2850
|
+
tslib.__metadata("design:paramtypes", [typeorm.DataSource, Object, Function, Object])
|
|
2831
2851
|
], exports.StockService);
|
|
2832
2852
|
|
|
2833
2853
|
/**
|
|
@@ -3078,6 +3098,26 @@ exports.MaterialService = class MaterialService {
|
|
|
3078
3098
|
this.materialRepository = this.dataSource.getRepository(this.materialEntity);
|
|
3079
3099
|
this.materialUnitRepository = this.dataSource.getRepository(this.materialUnitEntity);
|
|
3080
3100
|
}
|
|
3101
|
+
/**
|
|
3102
|
+
* Fail at boot if the configured `materialEntity` was never registered with
|
|
3103
|
+
* TypeORM.
|
|
3104
|
+
*
|
|
3105
|
+
* The module cannot register it: `TypeOrmModule.forFeature()` runs while the
|
|
3106
|
+
* module graph is assembled, and the entity is only known once the options
|
|
3107
|
+
* resolve. Registering the base class does bring the override's *columns* into
|
|
3108
|
+
* the `materials` schema (TypeORM copies a single-table child's columns into
|
|
3109
|
+
* its parent), which makes the omission easy to miss — everything looks right
|
|
3110
|
+
* until the first query fails with a bare `EntityMetadataNotFoundError` from
|
|
3111
|
+
* somewhere deep in a resolver.
|
|
3112
|
+
*/
|
|
3113
|
+
onModuleInit() {
|
|
3114
|
+
if (this.dataSource.hasMetadata(this.materialEntity))
|
|
3115
|
+
return;
|
|
3116
|
+
const name = typeof this.materialEntity === 'function'
|
|
3117
|
+
? this.materialEntity.name
|
|
3118
|
+
: String(this.materialEntity);
|
|
3119
|
+
throw new Error(`WmsModuleCoreModule: the configured materialEntity "${name}" is not registered with TypeORM. Add it to your DataSource "entities", or import TypeOrmModule.forFeature([${name}]) somewhere in your app when using autoLoadEntities.`);
|
|
3120
|
+
}
|
|
3081
3121
|
async getConversionFactor(materialId, unitId) {
|
|
3082
3122
|
const materialUnitRepository = this.dataSource.getRepository(this.materialUnitEntity);
|
|
3083
3123
|
if (!unitId)
|
|
@@ -3431,7 +3471,7 @@ exports.ReceiveInventoryOrderService = class ReceiveInventoryOrderService {
|
|
|
3431
3471
|
};
|
|
3432
3472
|
}
|
|
3433
3473
|
processReceiveInventoryOrderItems(items, orderId, manager) {
|
|
3434
|
-
const materialRepository = manager.getRepository(
|
|
3474
|
+
const materialRepository = manager.getRepository(this.materialService.materialEntity);
|
|
3435
3475
|
const locationRepository = manager.getRepository(exports.LocationEntityClass);
|
|
3436
3476
|
const loaderRepository = manager.getRepository(exports.LoadersEntityClass);
|
|
3437
3477
|
return items.reduce(async (accPromise, item) => {
|
|
@@ -3772,7 +3812,7 @@ exports.ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
|
3772
3812
|
};
|
|
3773
3813
|
}
|
|
3774
3814
|
processShipInventoryOrderReferences(references, manager) {
|
|
3775
|
-
const materialRepository = manager.getRepository(
|
|
3815
|
+
const materialRepository = manager.getRepository(this.materialService.materialEntity);
|
|
3776
3816
|
const saleOrderRepository = manager.getRepository(this.saleOrderEntity);
|
|
3777
3817
|
return references.reduce(async (accPromise, reference) => {
|
|
3778
3818
|
const acc = await accPromise;
|
|
@@ -3883,7 +3923,7 @@ exports.ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
|
3883
3923
|
const shipInventoryOrderRepository = manager.getRepository(this.shipInventoryOrderEntity);
|
|
3884
3924
|
const shipInventoryOrderReferenceRepository = manager.getRepository(this.shipInventoryOrderReferenceEntity);
|
|
3885
3925
|
const shipInventoryOrderItemRepository = manager.getRepository(this.shipInventoryOrderItemEntity);
|
|
3886
|
-
const materialRepository = manager.getRepository(
|
|
3926
|
+
const materialRepository = manager.getRepository(this.materialService.materialEntity);
|
|
3887
3927
|
const order = await shipInventoryOrderRepository.findOneByOrFail({
|
|
3888
3928
|
id,
|
|
3889
3929
|
removedAt: typeorm.IsNull(),
|
|
@@ -5652,7 +5692,7 @@ exports.ReclassifyInventoryOrderService = class ReclassifyInventoryOrderService
|
|
|
5652
5692
|
const orderRepository = manager.getRepository(wmsBaseNestjsModule.OrderEntity);
|
|
5653
5693
|
const stockRepository = manager.getRepository(exports.StockEntityClass);
|
|
5654
5694
|
const batchRepository = manager.getRepository(exports.BatchEntityClass);
|
|
5655
|
-
const materialRepository = manager.getRepository(
|
|
5695
|
+
const materialRepository = manager.getRepository(this.materialService.materialEntity);
|
|
5656
5696
|
// Ensure new material exists
|
|
5657
5697
|
const material = await materialRepository.findOneOrFail({
|
|
5658
5698
|
where: { key: options.materialKey },
|
|
@@ -6561,6 +6601,35 @@ StockChangeSubscriber = tslib.__decorate([
|
|
|
6561
6601
|
], StockChangeSubscriber);
|
|
6562
6602
|
|
|
6563
6603
|
var WmsModuleCoreModule_1;
|
|
6604
|
+
/**
|
|
6605
|
+
* Binds the `MaterialEntity` Symbol to the entity the consumer configured
|
|
6606
|
+
* through `WMSBaseModuleOptions.materialEntity`, falling back to the built-in
|
|
6607
|
+
* `MaterialEntityClass`.
|
|
6608
|
+
*
|
|
6609
|
+
* This is the single seam that makes the option real above the base layer.
|
|
6610
|
+
* `PROVIDE_MATERIAL_ENTITY` is resolved by `WMSBaseModule` from its own options
|
|
6611
|
+
* — so it works identically for `forRoot` and for an async factory — and every
|
|
6612
|
+
* service, DataLoader and query in this package reads the entity through this
|
|
6613
|
+
* Symbol rather than importing the class. Rebinding here therefore swaps the
|
|
6614
|
+
* material entity everywhere at once, and cannot drift from the repository the
|
|
6615
|
+
* base module resolved: both are derived from the same option.
|
|
6616
|
+
*/
|
|
6617
|
+
const MaterialEntityProvider = {
|
|
6618
|
+
provide: MaterialEntity,
|
|
6619
|
+
useFactory: (configured) => {
|
|
6620
|
+
if (!configured)
|
|
6621
|
+
return exports.MaterialEntityClass;
|
|
6622
|
+
// `WMSBaseModuleOptions` only asks for a child of the base `MaterialEntity`,
|
|
6623
|
+
// but this package's services and its `MaterialDto` read `description`,
|
|
6624
|
+
// `baseUnit` and `isActive` — the columns `MaterialEntityClass` adds. A
|
|
6625
|
+
// sibling would type-check against the base contract and then fail as a
|
|
6626
|
+
// missing column at query time, which is a far worse error to debug.
|
|
6627
|
+
if (!(configured.prototype instanceof exports.MaterialEntityClass))
|
|
6628
|
+
throw new Error(`WmsModuleCoreModule: materialEntity "${configured.name}" must extend MaterialEntityClass (a @ChildEntity() of it). @rytass/wms-module-core reads description / baseUnit / isActive from it, which the base MaterialEntity does not declare.`);
|
|
6629
|
+
return configured;
|
|
6630
|
+
},
|
|
6631
|
+
inject: [wmsBaseNestjsModule.PROVIDE_MATERIAL_ENTITY],
|
|
6632
|
+
};
|
|
6564
6633
|
const exportDependencies = [
|
|
6565
6634
|
exports.LoaderService,
|
|
6566
6635
|
exports.MaterialService,
|
|
@@ -6593,6 +6662,7 @@ exports.WmsModuleCoreModule = WmsModuleCoreModule_1 = class WmsModuleCoreModule
|
|
|
6593
6662
|
providers: [
|
|
6594
6663
|
...exportDependencies,
|
|
6595
6664
|
StockChangeSubscriber,
|
|
6665
|
+
MaterialEntityProvider,
|
|
6596
6666
|
{ provide: WMS_CORE_MODULE_OPTIONS, useValue: coreOptions },
|
|
6597
6667
|
{ provide: WMS_STOCK_ENRICH, useValue: !!coreOptions.enrichStockEvents },
|
|
6598
6668
|
],
|
|
@@ -6600,6 +6670,7 @@ exports.WmsModuleCoreModule = WmsModuleCoreModule_1 = class WmsModuleCoreModule
|
|
|
6600
6670
|
...exportDependencies,
|
|
6601
6671
|
coreModule,
|
|
6602
6672
|
ModelsModule,
|
|
6673
|
+
MaterialEntity,
|
|
6603
6674
|
WMS_CORE_MODULE_OPTIONS,
|
|
6604
6675
|
],
|
|
6605
6676
|
};
|
|
@@ -6613,6 +6684,7 @@ exports.WmsModuleCoreModule = WmsModuleCoreModule_1 = class WmsModuleCoreModule
|
|
|
6613
6684
|
providers: [
|
|
6614
6685
|
...exportDependencies,
|
|
6615
6686
|
StockChangeSubscriber,
|
|
6687
|
+
MaterialEntityProvider,
|
|
6616
6688
|
{
|
|
6617
6689
|
provide: WMS_CORE_MODULE_OPTIONS,
|
|
6618
6690
|
useValue: {
|
|
@@ -6627,6 +6699,7 @@ exports.WmsModuleCoreModule = WmsModuleCoreModule_1 = class WmsModuleCoreModule
|
|
|
6627
6699
|
...exportDependencies,
|
|
6628
6700
|
coreModule,
|
|
6629
6701
|
ModelsModule,
|
|
6702
|
+
MaterialEntity,
|
|
6630
6703
|
WMS_CORE_MODULE_OPTIONS,
|
|
6631
6704
|
],
|
|
6632
6705
|
};
|
package/lib/core.module.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
2
|
import { Module } from '@nestjs/common';
|
|
3
|
-
import { WMSBaseModule } from '@rytass/wms-base-nestjs-module';
|
|
3
|
+
import { WMSBaseModule, PROVIDE_MATERIAL_ENTITY } from '@rytass/wms-base-nestjs-module';
|
|
4
4
|
import { ModelsModule } from './models/models.module.js';
|
|
5
|
+
import { MaterialEntity, MaterialEntityClass } from './models/metadata/material.entity.js';
|
|
5
6
|
import { StockService } from './services/stock.service.js';
|
|
6
7
|
import { LoaderService } from './services/loader.service.js';
|
|
7
8
|
import { MaterialService } from './services/material.service.js';
|
|
@@ -28,6 +29,35 @@ import { WMS_STOCK_ENRICH } from './events/wms-event.tokens.js';
|
|
|
28
29
|
import { WMS_CORE_MODULE_OPTIONS } from './typings/core-module-options.js';
|
|
29
30
|
|
|
30
31
|
var WmsModuleCoreModule_1;
|
|
32
|
+
/**
|
|
33
|
+
* Binds the `MaterialEntity` Symbol to the entity the consumer configured
|
|
34
|
+
* through `WMSBaseModuleOptions.materialEntity`, falling back to the built-in
|
|
35
|
+
* `MaterialEntityClass`.
|
|
36
|
+
*
|
|
37
|
+
* This is the single seam that makes the option real above the base layer.
|
|
38
|
+
* `PROVIDE_MATERIAL_ENTITY` is resolved by `WMSBaseModule` from its own options
|
|
39
|
+
* — so it works identically for `forRoot` and for an async factory — and every
|
|
40
|
+
* service, DataLoader and query in this package reads the entity through this
|
|
41
|
+
* Symbol rather than importing the class. Rebinding here therefore swaps the
|
|
42
|
+
* material entity everywhere at once, and cannot drift from the repository the
|
|
43
|
+
* base module resolved: both are derived from the same option.
|
|
44
|
+
*/
|
|
45
|
+
const MaterialEntityProvider = {
|
|
46
|
+
provide: MaterialEntity,
|
|
47
|
+
useFactory: (configured) => {
|
|
48
|
+
if (!configured)
|
|
49
|
+
return MaterialEntityClass;
|
|
50
|
+
// `WMSBaseModuleOptions` only asks for a child of the base `MaterialEntity`,
|
|
51
|
+
// but this package's services and its `MaterialDto` read `description`,
|
|
52
|
+
// `baseUnit` and `isActive` — the columns `MaterialEntityClass` adds. A
|
|
53
|
+
// sibling would type-check against the base contract and then fail as a
|
|
54
|
+
// missing column at query time, which is a far worse error to debug.
|
|
55
|
+
if (!(configured.prototype instanceof MaterialEntityClass))
|
|
56
|
+
throw new Error(`WmsModuleCoreModule: materialEntity "${configured.name}" must extend MaterialEntityClass (a @ChildEntity() of it). @rytass/wms-module-core reads description / baseUnit / isActive from it, which the base MaterialEntity does not declare.`);
|
|
57
|
+
return configured;
|
|
58
|
+
},
|
|
59
|
+
inject: [PROVIDE_MATERIAL_ENTITY],
|
|
60
|
+
};
|
|
31
61
|
const exportDependencies = [
|
|
32
62
|
LoaderService,
|
|
33
63
|
MaterialService,
|
|
@@ -60,6 +90,7 @@ let WmsModuleCoreModule = WmsModuleCoreModule_1 = class WmsModuleCoreModule {
|
|
|
60
90
|
providers: [
|
|
61
91
|
...exportDependencies,
|
|
62
92
|
StockChangeSubscriber,
|
|
93
|
+
MaterialEntityProvider,
|
|
63
94
|
{ provide: WMS_CORE_MODULE_OPTIONS, useValue: coreOptions },
|
|
64
95
|
{ provide: WMS_STOCK_ENRICH, useValue: !!coreOptions.enrichStockEvents },
|
|
65
96
|
],
|
|
@@ -67,6 +98,7 @@ let WmsModuleCoreModule = WmsModuleCoreModule_1 = class WmsModuleCoreModule {
|
|
|
67
98
|
...exportDependencies,
|
|
68
99
|
coreModule,
|
|
69
100
|
ModelsModule,
|
|
101
|
+
MaterialEntity,
|
|
70
102
|
WMS_CORE_MODULE_OPTIONS,
|
|
71
103
|
],
|
|
72
104
|
};
|
|
@@ -80,6 +112,7 @@ let WmsModuleCoreModule = WmsModuleCoreModule_1 = class WmsModuleCoreModule {
|
|
|
80
112
|
providers: [
|
|
81
113
|
...exportDependencies,
|
|
82
114
|
StockChangeSubscriber,
|
|
115
|
+
MaterialEntityProvider,
|
|
83
116
|
{
|
|
84
117
|
provide: WMS_CORE_MODULE_OPTIONS,
|
|
85
118
|
useValue: {
|
|
@@ -94,6 +127,7 @@ let WmsModuleCoreModule = WmsModuleCoreModule_1 = class WmsModuleCoreModule {
|
|
|
94
127
|
...exportDependencies,
|
|
95
128
|
coreModule,
|
|
96
129
|
ModelsModule,
|
|
130
|
+
MaterialEntity,
|
|
97
131
|
WMS_CORE_MODULE_OPTIONS,
|
|
98
132
|
],
|
|
99
133
|
};
|
|
@@ -106,7 +106,20 @@ const entities = [
|
|
|
106
106
|
[ScrapeOrderItemEntity, ScrapeOrderItemEntityClass],
|
|
107
107
|
[ScrapeOrderChangeEntity, ScrapeOrderChangeEntityClass],
|
|
108
108
|
];
|
|
109
|
-
|
|
109
|
+
/**
|
|
110
|
+
* `MaterialEntity` is deliberately absent: `WmsModuleCoreModule` binds it to
|
|
111
|
+
* whatever `WMSBaseModuleOptions.materialEntity` resolved to, which only a module
|
|
112
|
+
* importing `WMSBaseModule` can read. Binding it here as well would leave two
|
|
113
|
+
* live bindings for one token, and the loser would be whichever module the
|
|
114
|
+
* injector happened to reach first.
|
|
115
|
+
*
|
|
116
|
+
* The class stays in `entities` above so TypeORM still registers it — it is the
|
|
117
|
+
* root of the single-table hierarchy a consumer's override extends.
|
|
118
|
+
*/
|
|
119
|
+
const EXTERNALLY_BOUND_ENTITIES = new Set([MaterialEntity]);
|
|
120
|
+
const ResolvedEntitiesProviders = entities
|
|
121
|
+
.filter(([token]) => !EXTERNALLY_BOUND_ENTITIES.has(token))
|
|
122
|
+
.map(([token, entity]) => ({
|
|
110
123
|
provide: token,
|
|
111
124
|
useValue: entity,
|
|
112
125
|
}));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type OnModuleInit } from '@nestjs/common';
|
|
1
2
|
import { CreateMaterialInput, UpdateMaterialInput } from '../typings/create-material.input';
|
|
2
3
|
import { MaterialEntityClass } from '../models/metadata/material.entity';
|
|
3
4
|
import { MaterialUnitEntityClass } from '../models/metadata/material-unit.entity';
|
|
@@ -9,13 +10,26 @@ import { FindMaterialInput } from '../typings/find-material.input';
|
|
|
9
10
|
* T - Material entity type
|
|
10
11
|
* K - Material Unit entity type
|
|
11
12
|
*/
|
|
12
|
-
export declare class MaterialService<T extends MaterialEntityClass = MaterialEntityClass, K extends MaterialUnitEntityClass = MaterialUnitEntityClass> {
|
|
13
|
+
export declare class MaterialService<T extends MaterialEntityClass = MaterialEntityClass, K extends MaterialUnitEntityClass = MaterialUnitEntityClass> implements OnModuleInit {
|
|
13
14
|
private readonly dataSource;
|
|
14
15
|
readonly materialEntity: EntityTarget<T>;
|
|
15
16
|
readonly materialUnitEntity: EntityTarget<K>;
|
|
16
17
|
readonly materialRepository: Repository<T>;
|
|
17
18
|
readonly materialUnitRepository: Repository<K>;
|
|
18
19
|
constructor(dataSource: DataSource, materialEntity: EntityTarget<T>, materialUnitEntity: EntityTarget<K>);
|
|
20
|
+
/**
|
|
21
|
+
* Fail at boot if the configured `materialEntity` was never registered with
|
|
22
|
+
* TypeORM.
|
|
23
|
+
*
|
|
24
|
+
* The module cannot register it: `TypeOrmModule.forFeature()` runs while the
|
|
25
|
+
* module graph is assembled, and the entity is only known once the options
|
|
26
|
+
* resolve. Registering the base class does bring the override's *columns* into
|
|
27
|
+
* the `materials` schema (TypeORM copies a single-table child's columns into
|
|
28
|
+
* its parent), which makes the omission easy to miss — everything looks right
|
|
29
|
+
* until the first query fails with a bare `EntityMetadataNotFoundError` from
|
|
30
|
+
* somewhere deep in a resolver.
|
|
31
|
+
*/
|
|
32
|
+
onModuleInit(): void;
|
|
19
33
|
getConversionFactor(materialId: string, unitId?: string): Promise<number>;
|
|
20
34
|
createMaterial({ manager, ...options }: CreateMaterialInput & {
|
|
21
35
|
manager?: EntityManager;
|
|
@@ -69,6 +69,26 @@ let MaterialService = class MaterialService {
|
|
|
69
69
|
this.materialRepository = this.dataSource.getRepository(this.materialEntity);
|
|
70
70
|
this.materialUnitRepository = this.dataSource.getRepository(this.materialUnitEntity);
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Fail at boot if the configured `materialEntity` was never registered with
|
|
74
|
+
* TypeORM.
|
|
75
|
+
*
|
|
76
|
+
* The module cannot register it: `TypeOrmModule.forFeature()` runs while the
|
|
77
|
+
* module graph is assembled, and the entity is only known once the options
|
|
78
|
+
* resolve. Registering the base class does bring the override's *columns* into
|
|
79
|
+
* the `materials` schema (TypeORM copies a single-table child's columns into
|
|
80
|
+
* its parent), which makes the omission easy to miss — everything looks right
|
|
81
|
+
* until the first query fails with a bare `EntityMetadataNotFoundError` from
|
|
82
|
+
* somewhere deep in a resolver.
|
|
83
|
+
*/
|
|
84
|
+
onModuleInit() {
|
|
85
|
+
if (this.dataSource.hasMetadata(this.materialEntity))
|
|
86
|
+
return;
|
|
87
|
+
const name = typeof this.materialEntity === 'function'
|
|
88
|
+
? this.materialEntity.name
|
|
89
|
+
: String(this.materialEntity);
|
|
90
|
+
throw new Error(`WmsModuleCoreModule: the configured materialEntity "${name}" is not registered with TypeORM. Add it to your DataSource "entities", or import TypeOrmModule.forFeature([${name}]) somewhere in your app when using autoLoadEntities.`);
|
|
91
|
+
}
|
|
72
92
|
async getConversionFactor(materialId, unitId) {
|
|
73
93
|
const materialUnitRepository = this.dataSource.getRepository(this.materialUnitEntity);
|
|
74
94
|
if (!unitId)
|
|
@@ -11,7 +11,7 @@ import { LoadersEntityClass } from '../models/metadata/loader.entity.js';
|
|
|
11
11
|
import '../models/metadata/loader-type.entity.js';
|
|
12
12
|
import '../models/metadata/loader-unit.entity.js';
|
|
13
13
|
import { LocationEntityClass } from '../models/metadata/location.entity.js';
|
|
14
|
-
import
|
|
14
|
+
import '../models/metadata/material.entity.js';
|
|
15
15
|
import '../models/metadata/material-unit.entity.js';
|
|
16
16
|
import '../models/metadata/sale-order.entity.js';
|
|
17
17
|
import { StockEntityClass } from '../models/metadata/stock.entity.js';
|
|
@@ -122,7 +122,7 @@ let ReceiveInventoryOrderService = class ReceiveInventoryOrderService {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
processReceiveInventoryOrderItems(items, orderId, manager) {
|
|
125
|
-
const materialRepository = manager.getRepository(
|
|
125
|
+
const materialRepository = manager.getRepository(this.materialService.materialEntity);
|
|
126
126
|
const locationRepository = manager.getRepository(LocationEntityClass);
|
|
127
127
|
const loaderRepository = manager.getRepository(LoadersEntityClass);
|
|
128
128
|
return items.reduce(async (accPromise, item) => {
|
|
@@ -6,7 +6,7 @@ import '../models/metadata/loader.entity.js';
|
|
|
6
6
|
import '../models/metadata/loader-type.entity.js';
|
|
7
7
|
import '../models/metadata/loader-unit.entity.js';
|
|
8
8
|
import '../models/metadata/location.entity.js';
|
|
9
|
-
import
|
|
9
|
+
import '../models/metadata/material.entity.js';
|
|
10
10
|
import '../models/metadata/material-unit.entity.js';
|
|
11
11
|
import '../models/metadata/sale-order.entity.js';
|
|
12
12
|
import { StockEntityClass } from '../models/metadata/stock.entity.js';
|
|
@@ -81,7 +81,7 @@ let ReclassifyInventoryOrderService = class ReclassifyInventoryOrderService {
|
|
|
81
81
|
const orderRepository = manager.getRepository(OrderEntity);
|
|
82
82
|
const stockRepository = manager.getRepository(StockEntityClass);
|
|
83
83
|
const batchRepository = manager.getRepository(BatchEntityClass);
|
|
84
|
-
const materialRepository = manager.getRepository(
|
|
84
|
+
const materialRepository = manager.getRepository(this.materialService.materialEntity);
|
|
85
85
|
// Ensure new material exists
|
|
86
86
|
const material = await materialRepository.findOneOrFail({
|
|
87
87
|
where: { key: options.materialKey },
|
|
@@ -11,7 +11,7 @@ import '../models/metadata/loader.entity.js';
|
|
|
11
11
|
import '../models/metadata/loader-type.entity.js';
|
|
12
12
|
import '../models/metadata/loader-unit.entity.js';
|
|
13
13
|
import '../models/metadata/location.entity.js';
|
|
14
|
-
import
|
|
14
|
+
import '../models/metadata/material.entity.js';
|
|
15
15
|
import '../models/metadata/material-unit.entity.js';
|
|
16
16
|
import { SaleOrderEntity } from '../models/metadata/sale-order.entity.js';
|
|
17
17
|
import { StockEntityClass } from '../models/metadata/stock.entity.js';
|
|
@@ -114,7 +114,7 @@ let ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
116
|
processShipInventoryOrderReferences(references, manager) {
|
|
117
|
-
const materialRepository = manager.getRepository(
|
|
117
|
+
const materialRepository = manager.getRepository(this.materialService.materialEntity);
|
|
118
118
|
const saleOrderRepository = manager.getRepository(this.saleOrderEntity);
|
|
119
119
|
return references.reduce(async (accPromise, reference) => {
|
|
120
120
|
const acc = await accPromise;
|
|
@@ -225,7 +225,7 @@ let ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
|
225
225
|
const shipInventoryOrderRepository = manager.getRepository(this.shipInventoryOrderEntity);
|
|
226
226
|
const shipInventoryOrderReferenceRepository = manager.getRepository(this.shipInventoryOrderReferenceEntity);
|
|
227
227
|
const shipInventoryOrderItemRepository = manager.getRepository(this.shipInventoryOrderItemEntity);
|
|
228
|
-
const materialRepository = manager.getRepository(
|
|
228
|
+
const materialRepository = manager.getRepository(this.materialService.materialEntity);
|
|
229
229
|
const order = await shipInventoryOrderRepository.findOneByOrFail({
|
|
230
230
|
id,
|
|
231
231
|
removedAt: IsNull(),
|
|
@@ -24,7 +24,7 @@ export declare class StockService<T extends StockEntityClass = StockEntityClass,
|
|
|
24
24
|
loaderId: string;
|
|
25
25
|
status: StockStatus;
|
|
26
26
|
};
|
|
27
|
-
constructor(dataSource: DataSource, stockEntity: EntityTarget<T>, materialEntity:
|
|
27
|
+
constructor(dataSource: DataSource, stockEntity: EntityTarget<T>, materialEntity: new () => K, coreOptions: WmsModuleCoreModuleOptions);
|
|
28
28
|
onModuleInit(): Promise<void>;
|
|
29
29
|
resolveLoaderId(loaderId: string | null | undefined): string;
|
|
30
30
|
resolveLocationId(locationId: string | null | undefined): string;
|
|
@@ -2,7 +2,7 @@ import { __decorate, __param, __metadata } from 'tslib';
|
|
|
2
2
|
import { Injectable, Inject } from '@nestjs/common';
|
|
3
3
|
import { StockEntity } from '../models/metadata/stock.entity.js';
|
|
4
4
|
import { DataSource } from 'typeorm';
|
|
5
|
-
import { MaterialEntity
|
|
5
|
+
import { MaterialEntity } from '../models/metadata/material.entity.js';
|
|
6
6
|
import { StockStatus, ChangeType } from '../constants/stock-status.js';
|
|
7
7
|
import { BatchEntity } from '@rytass/wms-base-nestjs-module';
|
|
8
8
|
import '../models/metadata/batch.entity.js';
|
|
@@ -235,7 +235,14 @@ let StockService = class StockService {
|
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
if (options.materialKey)
|
|
238
|
-
queryBuilder.innerJoin(
|
|
238
|
+
queryBuilder.innerJoin(
|
|
239
|
+
// The configured entity, not the built-in class: this follows whatever
|
|
240
|
+
// table that entity is mapped to. (TypeORM resolves an entity in a
|
|
241
|
+
// hand-written join to its table name and does not append the
|
|
242
|
+
// single-table discriminator, so for a child of `MaterialEntityClass` the
|
|
243
|
+
// emitted SQL is unchanged — this keeps the service from reaching past
|
|
244
|
+
// its own configuration, it is not a behaviour fix on its own.)
|
|
245
|
+
this.materialEntity, 'mk', 'mk.id = stock."materialId" AND mk.key ILIKE :materialKey', {
|
|
239
246
|
materialKey: `%${options.materialKey}%`,
|
|
240
247
|
});
|
|
241
248
|
if (options.batchKey)
|
|
@@ -471,7 +478,7 @@ StockService = __decorate([
|
|
|
471
478
|
__param(1, Inject(StockEntity)),
|
|
472
479
|
__param(2, Inject(MaterialEntity)),
|
|
473
480
|
__param(3, Inject(WMS_CORE_MODULE_OPTIONS)),
|
|
474
|
-
__metadata("design:paramtypes", [DataSource, Object,
|
|
481
|
+
__metadata("design:paramtypes", [DataSource, Object, Function, Object])
|
|
475
482
|
], StockService);
|
|
476
483
|
|
|
477
484
|
export { StockService };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { MaterialEntityClass } from '../models/metadata/material.entity';
|
|
2
|
+
/**
|
|
3
|
+
* Consumer-supplied replacements for the entity classes the module binds its
|
|
4
|
+
* entity Symbols to.
|
|
5
|
+
*
|
|
6
|
+
* An override has to be a `@ChildEntity()` of the class it replaces: the tables
|
|
7
|
+
* (`materials`, …) and their `@TableInheritance()` discriminator columns are part
|
|
8
|
+
* of the module's schema contract, so an override *joins* the existing
|
|
9
|
+
* single-table hierarchy — it never moves the data to another table.
|
|
10
|
+
*
|
|
11
|
+
* Entity classes are static, so — unlike the credentials in
|
|
12
|
+
* `WMSBaseModuleOptions` — they are configured **synchronously**, even on
|
|
13
|
+
* `forRootAsync`. `TypeOrmModule.forFeature()` and the `Symbol` → entity
|
|
14
|
+
* providers are built while the module graph is assembled, long before an async
|
|
15
|
+
* options factory has resolved; an entity that only appears in the factory's
|
|
16
|
+
* result would be too late to register. `WmsModuleCoreModule.forRootAsync`
|
|
17
|
+
* therefore takes these next to `defaultLocationKey` and forwards them into the
|
|
18
|
+
* base module's options for you, and throws if the async factory tries to set
|
|
19
|
+
* one behind their back.
|
|
20
|
+
*/
|
|
21
|
+
export interface WmsModuleEntityOverrides {
|
|
22
|
+
/**
|
|
23
|
+
* Replaces `MaterialEntityClass` everywhere the module reads or writes
|
|
24
|
+
* materials: the `MaterialEntity` Symbol, `MaterialService`, the receive /
|
|
25
|
+
* ship / reclassify order services, `StockService`'s `materialKey` filter and
|
|
26
|
+
* the GraphQL `material` DataLoaders.
|
|
27
|
+
*/
|
|
28
|
+
readonly materialEntity?: new () => MaterialEntityClass;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The overridable entity options, paired for `Object.keys`-style iteration over
|
|
32
|
+
* {@link WmsModuleEntityOverrides} without losing the key type.
|
|
33
|
+
*/
|
|
34
|
+
export declare const WMS_ENTITY_OVERRIDE_KEYS: readonly (keyof WmsModuleEntityOverrides)[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rytass/wms-module-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Rytass WMS Module — NestJS services and TypeORM entities for warehouse management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rytass",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@rytass/wms-base-nestjs-module": "0.
|
|
44
|
+
"@rytass/wms-base-nestjs-module": "0.3.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@nestjs/common": "^11.0.0",
|