@rytass/wms-module-core 0.3.1 → 0.5.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 +48 -1
- package/docs/README.md +2 -0
- package/docs/api-reference.md +38 -1
- package/docs/custom-entities.md +229 -0
- package/index.cjs.js +325 -98
- package/index.js +3 -0
- package/lib/core.module.js +88 -1
- package/lib/models/extensions/allocate-inventory-order/allocate-inventory-order-item.entity.js +1 -0
- package/lib/models/extensions/hold-inventory-order/hold-inventory-order-item.entity.js +1 -0
- package/lib/models/extensions/merge-batch-order/merge-batch-order-item.entity.js +1 -0
- package/lib/models/extensions/quality-inspection-order/quality-inspection-order-item.entity.js +1 -0
- package/lib/models/extensions/reclassify-inventory-order/reclassify-inventory-order-item.entity.js +1 -0
- package/lib/models/extensions/scrape-order/scrape-order-item.entity.js +1 -0
- package/lib/models/extensions/split-batch-order/split-batch-order-item.entity.js +1 -0
- package/lib/models/extensions/transfer-customer-order/transfer-customer-order-item.entity.js +1 -0
- package/lib/models/extensions/transfer-order/transfer-order-item.entity.js +1 -0
- package/lib/models/extensions/transfer-vendor-order/transfer-vendor-order-item.entity.js +1 -0
- package/lib/models/index.d.ts +1 -0
- package/lib/models/metadata/index.d.ts +1 -0
- package/lib/models/metadata/order.entity.d.ts +9 -0
- package/lib/models/metadata/order.entity.js +5 -0
- package/lib/models/models.module.js +21 -1
- package/lib/models/wms-entities.d.ts +45 -0
- package/lib/models/wms-entities.js +82 -0
- package/lib/services/allocate-inventory-order.service.d.ts +3 -1
- package/lib/services/allocate-inventory-order.service.js +10 -6
- package/lib/services/batch.service.js +5 -3
- package/lib/services/hold-inventory-order.service.d.ts +3 -1
- package/lib/services/hold-inventory-order.service.js +10 -6
- package/lib/services/loader.service.js +2 -0
- package/lib/services/location.service.js +2 -0
- package/lib/services/material.service.js +2 -0
- package/lib/services/merge-batch-order.service.d.ts +3 -1
- package/lib/services/merge-batch-order.service.js +13 -9
- package/lib/services/quality-inspection-order.service.d.ts +3 -1
- package/lib/services/quality-inspection-order.service.js +12 -8
- package/lib/services/receive-inventory-order.service.d.ts +3 -1
- package/lib/services/receive-inventory-order.service.js +17 -13
- package/lib/services/reclassify-inventory-order.service.d.ts +3 -1
- package/lib/services/reclassify-inventory-order.service.js +15 -11
- package/lib/services/scrape.service.d.ts +3 -1
- package/lib/services/scrape.service.js +9 -5
- package/lib/services/ship-inventory-order.service.d.ts +3 -1
- package/lib/services/ship-inventory-order.service.js +21 -17
- package/lib/services/split-batch-order.service.d.ts +3 -1
- package/lib/services/split-batch-order.service.js +13 -9
- package/lib/services/stock.service.d.ts +3 -1
- package/lib/services/stock.service.js +23 -12
- package/lib/services/transfer-customer-order.service.d.ts +3 -1
- package/lib/services/transfer-customer-order.service.js +12 -8
- package/lib/services/transfer-order.service.d.ts +3 -1
- package/lib/services/transfer-order.service.js +11 -7
- package/lib/services/transfer-vendor-order.service.d.ts +3 -1
- package/lib/services/transfer-vendor-order.service.js +12 -8
- package/lib/services/unit.service.js +2 -0
- package/lib/services/warehouse-map.service.d.ts +3 -1
- package/lib/services/warehouse-map.service.js +9 -6
- 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,53 @@ 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
|
+
All six entity options `WMSBaseModuleOptions` exposes — `materialEntity`, `batchEntity`, `locationEntity`, `stockEntity`, `orderEntity`, `warehouseMapEntity` — are wired all the way through. Give one a `@ChildEntity()` of the class it replaces and your own table *is* the WMS table — no second table, no double writes:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { ChildEntity, Column } from 'typeorm';
|
|
78
|
+
import {
|
|
79
|
+
BatchEntityClass,
|
|
80
|
+
MaterialEntityClass,
|
|
81
|
+
WmsModuleCoreModule,
|
|
82
|
+
} from '@rytass/wms-module-core';
|
|
83
|
+
|
|
84
|
+
@ChildEntity()
|
|
85
|
+
export class ItemMasterEntity extends MaterialEntityClass {
|
|
86
|
+
@Column({ type: 'varchar', nullable: true })
|
|
87
|
+
erpCode!: string | null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@ChildEntity()
|
|
91
|
+
export class LotEntity extends BatchEntityClass {
|
|
92
|
+
@Column({ type: 'date', nullable: true })
|
|
93
|
+
expiresOn!: Date | null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
WmsModuleCoreModule.forRootAsync({
|
|
97
|
+
useFactory: async () => ({
|
|
98
|
+
materialEntity: ItemMasterEntity,
|
|
99
|
+
batchEntity: LotEntity,
|
|
100
|
+
}),
|
|
101
|
+
defaultLoaderSerialId: 'DEFAULT',
|
|
102
|
+
defaultLoaderTypeKey: 'DEFAULT',
|
|
103
|
+
defaultLocationKey: 'DEFAULT',
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
They are ordinary `WMSBaseModuleOptions` fields, so `forRoot` and the async factory both work, and you can override as few or as many as you like. The base module resolves its repositories from them and this package binds its entity Symbols from the same `PROVIDE_*_ENTITY` tokens at injection time — one option, two consumers, no way for them to drift. Needs `@rytass/wms-base-nestjs-module` >= 0.4.0.
|
|
108
|
+
|
|
109
|
+
`WmsEntities` is exported for consumers who need the resolved classes themselves:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
constructor(private readonly entities: WmsEntities) {}
|
|
113
|
+
// this.entities.material / .batch / .location / .stock / .order / .warehouseMap
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**You register the entities with TypeORM yourself** (`TypeOrmModule.forFeature([...])`, or the DataSource's `entities`). The module cannot: `forFeature()` runs while Nest assembles the module graph, before the options resolve. Forgetting almost works — TypeORM still creates your columns in the parent table — so the module checks at startup and refuses to boot with a message naming what to add.
|
|
117
|
+
|
|
118
|
+
[`docs/custom-entities.md`](./docs/custom-entities.md) has the full picture, including what single-table inheritance means for rows written before the override existed.
|
|
73
119
|
|
|
74
120
|
## Module options token
|
|
75
121
|
|
|
@@ -83,6 +129,7 @@ Full documentation is shipped inside this package under the `docs/` directory (a
|
|
|
83
129
|
|---|---|
|
|
84
130
|
| [`docs/integration-guide.md`](./docs/integration-guide.md) | Step-by-step wiring guide for NestJS + Next.js consumers |
|
|
85
131
|
| [`docs/api-reference.md`](./docs/api-reference.md) | Complete export catalog with signatures and usage examples |
|
|
132
|
+
| [`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
133
|
|
|
87
134
|
GitHub hosted links (always up-to-date):
|
|
88
135
|
|
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,44 @@ static forRootAsync(
|
|
|
38
38
|
): DynamicModule
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
**Entity override(since 0.5.0,需 `@rytass/wms-base-nestjs-module` >= 0.4.0)**
|
|
42
|
+
|
|
43
|
+
`WMSBaseModuleOptions` 的六個 entity 選項現在會一路作用到 core 與 graphql。每個都必須是它所取代的 class 的 `@ChildEntity()`:
|
|
44
|
+
|
|
45
|
+
| 選項 | 資料表 | 取代 |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| `materialEntity` | `materials` | `MaterialEntityClass` |
|
|
48
|
+
| `batchEntity` | `batches` | `BatchEntityClass` |
|
|
49
|
+
| `locationEntity` | `locations` | `LocationEntityClass` |
|
|
50
|
+
| `stockEntity` | `stocks` | `StockEntityClass` |
|
|
51
|
+
| `orderEntity` | `orders` | `OrderEntityClass` |
|
|
52
|
+
| `warehouseMapEntity` | `warehouse_maps` | `WarehouseMapEntity`(基座) |
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
WmsModuleCoreModule.forRootAsync({
|
|
56
|
+
useFactory: async () => ({
|
|
57
|
+
materialEntity: ItemMasterEntity,
|
|
58
|
+
batchEntity: LotEntity,
|
|
59
|
+
}),
|
|
60
|
+
defaultLoaderSerialId: 'DEFAULT',
|
|
61
|
+
defaultLoaderTypeKey: 'DEFAULT',
|
|
62
|
+
defaultLocationKey: 'DEFAULT',
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- `forRoot` 與 async factory 皆可,因為各 Symbol 是在 **DI 時**由基座 export 的 `PROVIDE_*_ENTITY` 綁定,不是在 module graph 組裝時。
|
|
67
|
+
- 基座的 `RESOLVED_*_REPO` 與 core 的 Symbol 由**同一個 option** 推導,結構上不可能不一致。
|
|
68
|
+
- **entity 需自行註冊給 TypeORM**(`TypeOrmModule.forFeature([...])` 或 DataSource `entities`);模組無法代勞,漏掉時會在啟動階段列出缺哪幾個。
|
|
69
|
+
- 未繼承正確 class 者會在啟動時被拒絕(TypeScript 結構型別擋不住兄弟類別)。
|
|
70
|
+
- 可只覆寫其中幾個,其餘沿用內建 class。詳見 [`custom-entities.md`](./custom-entities.md)。
|
|
71
|
+
|
|
72
|
+
### `WmsEntities`
|
|
73
|
+
- 用途: 套用覆寫後**實際**被讀寫的 entity class 集合。`material` / `batch` / `location` / `stock` / `order` / `warehouseMap` 六個唯讀屬性。消費端需要同一份答案時可直接注入。建構時會驗證每個 entity 都已註冊給 TypeORM。
|
|
74
|
+
- 來源: `lib/models/wms-entities.ts`
|
|
75
|
+
|
|
41
76
|
### `ModelsModule`
|
|
42
77
|
- 用途: 內部模組,向 TypeORM 註冊所有 WMS 實體(via DI token 形式),並透過 `ResolvedEntitiesProviders` 提供 DI。**消費端不直接 import**;它由 `WmsModuleCoreModule.forRoot` 自動引入並 re-export。
|
|
78
|
+
- 六個可覆寫的 Symbol **不由此模組綁定**:它們在 `WmsModuleCoreModule` 內由對應的 `PROVIDE_*_ENTITY` 推導,避免同一個 token 出現兩個繫結。內建 class 仍註冊進 `forFeature()`(它們是各自單表繼承的根)。
|
|
43
79
|
- 來源: `lib/models/models.module.ts`
|
|
44
80
|
|
|
45
81
|
---
|
|
@@ -52,6 +88,7 @@ static forRootAsync(
|
|
|
52
88
|
|---|---|---|---|
|
|
53
89
|
| `UnitEntity` | `UnitEntityClass` | 單位主檔(kg / pcs 等) | `lib/models/metadata/unit.entity.ts` |
|
|
54
90
|
| `MaterialEntity` | `MaterialEntityClass` | 料號主檔,繼承 `BaseMaterialEntity` | `lib/models/metadata/material.entity.ts` |
|
|
91
|
+
| `OrderEntity` | `OrderEntityClass` | 訂單基底(本套件未加欄位,`OrderEntityClass` 即基座 class) | `lib/models/metadata/order.entity.ts` |
|
|
55
92
|
| `MaterialUnitEntity` | `MaterialUnitEntityClass` | 料號換算單位(含換算係數) | `lib/models/metadata/material-unit.entity.ts` |
|
|
56
93
|
| `BatchEntity` | `BatchEntityClass` | 批號主檔,繼承 `BaseBatchEntity` | `lib/models/metadata/batch.entity.ts` |
|
|
57
94
|
| `BatchGroupEntity` | `BatchGroupEntityClass` | 批號群組,支援多批合併情境 | `lib/models/metadata/batch-group.entity.ts` |
|
|
@@ -0,0 +1,229 @@
|
|
|
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
|
+
> All six entities `WMSBaseModuleOptions` exposes are supported. Requires
|
|
8
|
+
> `@rytass/wms-base-nestjs-module` >= 0.4.0.
|
|
9
|
+
|
|
10
|
+
## Table of Contents
|
|
11
|
+
|
|
12
|
+
1. [What the option does](#1-what-the-option-does)
|
|
13
|
+
2. [Writing the entity](#2-writing-the-entity)
|
|
14
|
+
3. [Passing it to the module](#3-passing-it-to-the-module)
|
|
15
|
+
4. [Registering the entity with TypeORM](#4-registering-the-entity-with-typeorm)
|
|
16
|
+
5. [What single-table inheritance means for your data](#5-what-single-table-inheritance-means-for-your-data)
|
|
17
|
+
6. [Overriding more than one](#6-overriding-more-than-one)
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 1. What the option does
|
|
22
|
+
|
|
23
|
+
`@rytass/wms-base-nestjs-module` has always accepted entity overrides in
|
|
24
|
+
`WMSBaseModuleOptions`, but it kept the resolved entities to itself: the tokens
|
|
25
|
+
were never exported, so `@rytass/wms-module-core` could not read them and bound
|
|
26
|
+
its own entity Symbols to the built-in classes unconditionally. The options
|
|
27
|
+
therefore changed nothing above the base layer.
|
|
28
|
+
|
|
29
|
+
`wms-base` 0.3.0 exports `PROVIDE_*_ENTITY` and `RESOLVED_*_REPO` (the same
|
|
30
|
+
shape `@rytass/member-base-nestjs-module` has always used for `memberEntity`),
|
|
31
|
+
and the core module binds its Symbols from those tokens at injection time.
|
|
32
|
+
|
|
33
|
+
| Option | Table | Replaces | Also reached by |
|
|
34
|
+
|----------------------|------------------|------------------------|------------------------------------------------------------|
|
|
35
|
+
| `materialEntity` | `materials` | `MaterialEntityClass` | `MaterialService`, receive / ship / reclassify, stock filters |
|
|
36
|
+
| `batchEntity` | `batches` | `BatchEntityClass` | `BatchService`, split / merge / reclassify |
|
|
37
|
+
| `locationEntity` | `locations` | `LocationEntityClass` | `LocationService`, receive, transfers, startup seeding |
|
|
38
|
+
| `stockEntity` | `stocks` | `StockEntityClass` | `StockService` and every path that moves stock |
|
|
39
|
+
| `orderEntity` | `orders` | `OrderEntityClass` | every order service — one row per stock movement |
|
|
40
|
+
| `warehouseMapEntity` | `warehouse_maps` | `WarehouseMapEntity` | `WarehouseMapDataService` and the map mutation |
|
|
41
|
+
|
|
42
|
+
Nothing in either package imports these classes as values any more. Every
|
|
43
|
+
service, DataLoader and query reaches them through a `Symbol`, so rebinding one
|
|
44
|
+
swaps that entity everywhere at once — including the GraphQL DataLoaders, which
|
|
45
|
+
would otherwise resolve `null` for an override and fail their non-nullable
|
|
46
|
+
fields.
|
|
47
|
+
|
|
48
|
+
`WmsEntities` is the injectable holding the resolved classes, exported for
|
|
49
|
+
consumers who need the same answer:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { WmsEntities } from '@rytass/wms-module-core';
|
|
53
|
+
|
|
54
|
+
@Injectable()
|
|
55
|
+
export class MyService {
|
|
56
|
+
constructor(private readonly entities: WmsEntities) {}
|
|
57
|
+
|
|
58
|
+
find(): Promise<unknown[]> {
|
|
59
|
+
return this.dataSource.getRepository(this.entities.material).find();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 2. Writing the entity
|
|
65
|
+
|
|
66
|
+
Each override must be a TypeORM `@ChildEntity()` extending the class it replaces.
|
|
67
|
+
It joins the existing table through single-table inheritance; it does not move
|
|
68
|
+
the data anywhere.
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { ChildEntity, Column, Index } from 'typeorm';
|
|
72
|
+
import {
|
|
73
|
+
BatchEntityClass,
|
|
74
|
+
LocationEntityClass,
|
|
75
|
+
MaterialEntityClass,
|
|
76
|
+
} from '@rytass/wms-module-core';
|
|
77
|
+
|
|
78
|
+
@ChildEntity()
|
|
79
|
+
export class ItemMasterEntity extends MaterialEntityClass {
|
|
80
|
+
@Column({ type: 'varchar', nullable: true })
|
|
81
|
+
@Index()
|
|
82
|
+
erpCode!: string | null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@ChildEntity()
|
|
86
|
+
export class LotEntity extends BatchEntityClass {
|
|
87
|
+
@Column({ type: 'date', nullable: true })
|
|
88
|
+
expiresOn!: Date | null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@ChildEntity()
|
|
92
|
+
export class BinEntity extends LocationEntityClass {
|
|
93
|
+
@Column({ type: 'varchar', nullable: true })
|
|
94
|
+
zone!: string | null;
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Rules:
|
|
99
|
+
|
|
100
|
+
- **Extend the class this package exports, not the base one.** `MaterialEntityClass`,
|
|
101
|
+
`BatchEntityClass`, `LocationEntityClass` and `StockEntityClass` add the columns
|
|
102
|
+
the services and DTOs read; the base classes do not declare them. `OrderEntityClass`
|
|
103
|
+
and the warehouse map entity are the base classes — this package adds nothing to
|
|
104
|
+
those two — and are re-exported so every override reads the same way.
|
|
105
|
+
- **New columns must be nullable or have a default.** Rows written before the
|
|
106
|
+
override existed carry the old discriminator and have no value for them.
|
|
107
|
+
- **Do not re-declare `@Entity()` or `@TableInheritance()`.** Both belong to the
|
|
108
|
+
class you are extending; `@ChildEntity()` is the whole decoration you need. The
|
|
109
|
+
same goes for `@Tree()` on a location override — inherit it, do not repeat it.
|
|
110
|
+
- The module refuses to boot if an override does not extend the right class.
|
|
111
|
+
`WMSBaseModuleOptions` only asks for a child of the *base* entity, and
|
|
112
|
+
TypeScript's structural typing will happily accept a sibling that never
|
|
113
|
+
declares the columns this package reads.
|
|
114
|
+
|
|
115
|
+
## 3. Passing it to the module
|
|
116
|
+
|
|
117
|
+
`materialEntity` is a `WMSBaseModuleOptions` field, so it goes wherever the rest
|
|
118
|
+
of the base options go — including the async factory:
|
|
119
|
+
|
|
120
|
+
### `forRootAsync`
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
WmsModuleGraphqlModule.forRootAsync({
|
|
124
|
+
imports: [VaultModule],
|
|
125
|
+
inject: [VaultService],
|
|
126
|
+
useFactory: async (vault: VaultService) => ({
|
|
127
|
+
allowNegativeStock: await vault.get<boolean>('ALLOW_NEGATIVE_STOCK'),
|
|
128
|
+
materialEntity: ItemMasterEntity,
|
|
129
|
+
batchEntity: LotEntity,
|
|
130
|
+
locationEntity: BinEntity,
|
|
131
|
+
}),
|
|
132
|
+
|
|
133
|
+
defaultLoaderSerialId: 'DEFAULT',
|
|
134
|
+
defaultLoaderTypeKey: 'DEFAULT',
|
|
135
|
+
defaultLocationKey: 'DEFAULT',
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Override as few or as many as you like; anything left out keeps its built-in
|
|
140
|
+
class.
|
|
141
|
+
|
|
142
|
+
### `forRoot`
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
WmsModuleCoreModule.forRoot(
|
|
146
|
+
{ materialEntity: ItemMasterEntity, batchEntity: LotEntity },
|
|
147
|
+
{
|
|
148
|
+
defaultLoaderSerialId: 'DEFAULT',
|
|
149
|
+
defaultLoaderTypeKey: 'DEFAULT',
|
|
150
|
+
defaultLocationKey: 'DEFAULT',
|
|
151
|
+
},
|
|
152
|
+
);
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
You pass it once. The base module resolves its repository from it and the core
|
|
156
|
+
module binds its `MaterialEntity` Symbol from it; both read the same option, so
|
|
157
|
+
there is no forwarding step that could get them out of step.
|
|
158
|
+
|
|
159
|
+
If a class does not extend the one it replaces, the module refuses to boot —
|
|
160
|
+
`WMSBaseModuleOptions` only asks for a child of the *base* entity, and
|
|
161
|
+
TypeScript's structural typing will not catch a sibling that happens to look
|
|
162
|
+
right.
|
|
163
|
+
|
|
164
|
+
## 4. Registering the entity with TypeORM
|
|
165
|
+
|
|
166
|
+
**You** register the override; the module cannot. `TypeOrmModule.forFeature()`
|
|
167
|
+
runs while Nest assembles the module graph, and the entity is not known until the
|
|
168
|
+
options resolve.
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
@Module({
|
|
172
|
+
imports: [
|
|
173
|
+
TypeOrmModule.forRoot({ /* ... */ autoLoadEntities: true }),
|
|
174
|
+
TypeOrmModule.forFeature([ItemMasterEntity, LotEntity, BinEntity]),
|
|
175
|
+
WmsModuleGraphqlModule.forRootAsync({ /* ... */ }),
|
|
176
|
+
],
|
|
177
|
+
})
|
|
178
|
+
export class AppModule {}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`entities: [ItemMasterEntity, ...]` on the DataSource works just as well.
|
|
182
|
+
|
|
183
|
+
This is easy to forget, because forgetting it *almost* works: TypeORM copies a
|
|
184
|
+
single-table child's columns into its parent, so `synchronize` still creates your
|
|
185
|
+
columns in `materials` and the schema looks correct. Only the queries fail. The
|
|
186
|
+
module checks for it at startup and refuses to boot rather than letting an
|
|
187
|
+
`EntityMetadataNotFoundError` surface later from inside a resolver:
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
WmsModuleCoreModule: configured entities are not registered with TypeORM
|
|
191
|
+
(materialEntity: ItemMasterEntity, batchEntity: LotEntity). Add them to your
|
|
192
|
+
DataSource "entities", or import TypeOrmModule.forFeature([ItemMasterEntity,
|
|
193
|
+
LotEntity]) somewhere in your app when using autoLoadEntities.
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## 5. What single-table inheritance means for your data
|
|
197
|
+
|
|
198
|
+
All material rows live in `materials`, and the `entityName` column records which
|
|
199
|
+
class wrote each one.
|
|
200
|
+
|
|
201
|
+
- Rows written **after** you configure the override carry your class's name.
|
|
202
|
+
- Rows written **before** it carry `MaterialEntityClass`, and your entity's
|
|
203
|
+
queries will not see them: a single-table query matches its own class and its
|
|
204
|
+
descendants, never its ancestors or siblings. Backfilling those rows
|
|
205
|
+
(`UPDATE materials SET "entityName" = 'ItemMasterEntity' WHERE …`) is a
|
|
206
|
+
consumer-side migration; the module does not attempt it.
|
|
207
|
+
- Reading through `MaterialEntityClass` still returns your rows, because your
|
|
208
|
+
class is a descendant of it. The asymmetry only bites in the other direction.
|
|
209
|
+
|
|
210
|
+
## 6. Overriding more than one
|
|
211
|
+
|
|
212
|
+
The overrides are independent — take one, take all six, mix and match. They are
|
|
213
|
+
resolved from the same options object and validated together at startup, so a
|
|
214
|
+
partial configuration is a normal state rather than a special case.
|
|
215
|
+
|
|
216
|
+
One caveat worth knowing when overriding `warehouseMapEntity`: its table gained
|
|
217
|
+
its `entityName` discriminator column in `wms-base` 0.4.0, and it is **nullable**
|
|
218
|
+
precisely so existing rows survive the upgrade. A single-table root is queried
|
|
219
|
+
without a discriminator filter, so rows written before the upgrade stay readable
|
|
220
|
+
through the built-in class. They are *not* visible to an override, for the same
|
|
221
|
+
reason described in section 5 — backfill them if you need them:
|
|
222
|
+
|
|
223
|
+
```sql
|
|
224
|
+
UPDATE warehouse_maps SET "entityName" = 'YourMapEntity' WHERE "entityName" IS NULL;
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
The other five tables have carried a discriminator since long before this
|
|
228
|
+
feature, so only `warehouse_maps` needs the column added. If you run migrations
|
|
229
|
+
rather than `synchronize`, generate one for it.
|