@rytass/wms-module-core 0.7.0 → 0.8.1
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/docs/api-reference.md +4 -0
- package/docs/integration-guide.md +21 -1
- package/index.cjs.js +44 -23
- package/lib/services/allocate-inventory-order.service.js +1 -1
- package/lib/services/batch.service.js +17 -8
- package/lib/services/receive-inventory-order.service.js +1 -1
- package/lib/services/ship-inventory-order.service.js +3 -3
- package/lib/services/stock.service.js +16 -2
- package/lib/services/transfer-customer-order.service.js +1 -1
- package/lib/services/transfer-order.service.js +4 -6
- package/lib/services/transfer-vendor-order.service.js +1 -1
- package/lib/typings/find-stock.input.d.ts +9 -0
- package/package.json +2 -2
package/docs/api-reference.md
CHANGED
|
@@ -248,6 +248,10 @@ WmsModuleCoreModule.forRootAsync({
|
|
|
248
248
|
|
|
249
249
|
**庫存**
|
|
250
250
|
- `FindStockInput<U extends object>` (extends `PaginationInput`) — 來源: `lib/typings/find-stock.input.ts`
|
|
251
|
+
- `aggregated` 已 **deprecated 且被忽略**,下一個 minor 移除。每個讀這個 input 的方法都自己決定要不要聚合:
|
|
252
|
+
`findAggregatedStocks` / `findAggregatedStock` 一律聚合,`findMany` / `findChangeLogs` 一律不聚合。
|
|
253
|
+
在 0.8.0 之前對 `findAggregatedStocks` 傳 `false`(或省略)會拋 `column agg."saleSerialId" does not exist`,
|
|
254
|
+
而不是回傳未聚合的列——所以沒有任何行為依賴它。
|
|
251
255
|
- 除了 `materialKey` / `batchKey` / `locationKey` / `loaderKey`(皆為 ILIKE 模糊比對),另可用批號上的四個商業屬性
|
|
252
256
|
`vendorId` / `customerId` / `saleId` / `saleSerialId` 篩選。這四個是**完全比對**,不是模糊比對——它們是上游系統的識別碼,
|
|
253
257
|
模糊比對會讓 `SO-1` 撈到 `SO-10`。傳 `null` 等同不篩選。
|
|
@@ -348,13 +348,33 @@ combination the integration suite actually runs against.
|
|
|
348
348
|
|--------------------------|------------------------|--------------|-----------------------------------------------------------------------------|
|
|
349
349
|
| `@nestjs/common` | 10.x – 11.x | 11.1.x | **12.x is not accepted**: the whole NestJS 12 line is ESM-only, which this package (dual CJS+ESM) and a webpack-bundled host cannot consume yet |
|
|
350
350
|
| `@nestjs/typeorm` | 10.x – 11.x | 11.0.x | Three import sites (`InjectDataSource`, `forFeature`), stable across both |
|
|
351
|
-
| TypeORM | 0.3.x
|
|
351
|
+
| TypeORM | 0.3.x – 1.x | 1.1.1 | The suite is run against both 0.3.31 and 1.1.1. 0.2.x is not supported (different DataSource API). Note 0.3.x is now tagged `legacy` on npm |
|
|
352
|
+
| `@nestjs/typeorm` | 10.x – 11.x | 11.0.3 | **TypeORM 1.x needs `@nestjs/typeorm` >= 11.0.1** — earlier releases peer `^0.3.0` only |
|
|
352
353
|
| `reflect-metadata` | 0.1.13+ / 0.2.x | 0.1.x | Ambient requirement of the decorators |
|
|
353
354
|
| `rxjs` | not a peer | — | Never imported by this package; `@nestjs/common` peers it for you |
|
|
354
355
|
| `@rytass/wms-base-nestjs-module` | 0.4.x | 0.4.0 | **A peer since 0.7.0**, not a bundled dependency. It was pinned exactly under `dependencies`, which cannot prevent a second copy — it *causes* one as soon as you ask for any other 0.4.x. Two copies means two sets of entity classes and DI Symbols, the split-brain this package's Symbol discipline exists to avoid. Install it yourself so there is one |
|
|
355
356
|
| PostgreSQL | — | 14+ | Native dialect |
|
|
356
357
|
| Node.js | — | 20 LTS / 22 | 18 deprecated, 24 untested |
|
|
357
358
|
|
|
359
|
+
### Upgrading to TypeORM 1.x
|
|
360
|
+
|
|
361
|
+
Both majors are supported and both are exercised by the integration suite, so you can move
|
|
362
|
+
at your own pace. Two things changed upstream that are worth knowing before you do:
|
|
363
|
+
|
|
364
|
+
1. **`relations` no longer accepts an array.** `relations: ['items']` becomes
|
|
365
|
+
`relations: { items: true }`. The object form works in 0.3.x too, so it is safe to convert
|
|
366
|
+
before you upgrade.
|
|
367
|
+
2. **A bare `null` in a `where` is now an error**, not a silently-never-matching condition.
|
|
368
|
+
TypeORM 1.x raises `Null value encountered in property '…' of a where condition` and tells
|
|
369
|
+
you to use `IsNull()`. This is worth welcoming rather than working around: in 0.3.x such a
|
|
370
|
+
condition compiled to `= NULL`, which is never true in SQL, so the query quietly returned
|
|
371
|
+
nothing. Upgrading found exactly one such bug in this package — a batch-reuse lookup that
|
|
372
|
+
had been splitting duplicates instead of matching the batch already there.
|
|
373
|
+
|
|
374
|
+
If you have too many call sites to fix at once, TypeORM offers
|
|
375
|
+
`invalidWhereValuesBehavior.null` in the DataSource options as an escape hatch. Prefer
|
|
376
|
+
fixing them: each one is a query that was returning the wrong answer.
|
|
377
|
+
|
|
358
378
|
The GraphQL-side packages (`@nestjs/graphql`, `@nestjs/apollo`, `@apollo/server`,
|
|
359
379
|
`@as-integrations/express5`) are not peers of this package — see
|
|
360
380
|
[`@rytass/wms-module-graphql`](https://www.npmjs.com/package/@rytass/wms-module-graphql) §4.6.
|
package/index.cjs.js
CHANGED
|
@@ -3194,7 +3194,14 @@ exports.StockService = class StockService {
|
|
|
3194
3194
|
}
|
|
3195
3195
|
async findAggregatedStocks(options) {
|
|
3196
3196
|
// Create the aggregated subquery without pagination
|
|
3197
|
-
const aggregateSubquery = this.pipeSelectOptionsToQueryBuilder({ ...options, offset: undefined, limit: undefined }, this.selectQueryBuilder('stock'),
|
|
3197
|
+
const aggregateSubquery = this.pipeSelectOptionsToQueryBuilder({ ...options, offset: undefined, limit: undefined }, this.selectQueryBuilder('stock'),
|
|
3198
|
+
// Always aggregated. The outer projection below is hard-wired to the
|
|
3199
|
+
// aggregated shape (it selects agg."saleSerialId" and friends), so letting
|
|
3200
|
+
// the caller switch the inner subquery off asked the outer query for a
|
|
3201
|
+
// column the inner one never produced — a hard `column agg."saleSerialId"
|
|
3202
|
+
// does not exist`. There was never a working `false` here: this method
|
|
3203
|
+
// returns AggregatedStock[], so aggregating is its only meaning.
|
|
3204
|
+
true);
|
|
3198
3205
|
// Wrap the aggregated subquery and apply pagination on top
|
|
3199
3206
|
const paginatedQueryBuilder = this.dataSource
|
|
3200
3207
|
.createQueryBuilder()
|
|
@@ -3219,7 +3226,14 @@ exports.StockService = class StockService {
|
|
|
3219
3226
|
paginatedQueryBuilder.take(options.limit);
|
|
3220
3227
|
}
|
|
3221
3228
|
// Get total count from the aggregated subquery
|
|
3222
|
-
const countBuilder = this.pipeSelectOptionsToQueryBuilder({ ...options, offset: undefined, limit: undefined }, this.selectQueryBuilder('stock'),
|
|
3229
|
+
const countBuilder = this.pipeSelectOptionsToQueryBuilder({ ...options, offset: undefined, limit: undefined }, this.selectQueryBuilder('stock'),
|
|
3230
|
+
// Always aggregated. The outer projection below is hard-wired to the
|
|
3231
|
+
// aggregated shape (it selects agg."saleSerialId" and friends), so letting
|
|
3232
|
+
// the caller switch the inner subquery off asked the outer query for a
|
|
3233
|
+
// column the inner one never produced — a hard `column agg."saleSerialId"
|
|
3234
|
+
// does not exist`. There was never a working `false` here: this method
|
|
3235
|
+
// returns AggregatedStock[], so aggregating is its only meaning.
|
|
3236
|
+
true);
|
|
3223
3237
|
const countResult = await this.dataSource
|
|
3224
3238
|
.createQueryBuilder()
|
|
3225
3239
|
.select('COUNT(*)', 'count')
|
|
@@ -3777,7 +3791,7 @@ exports.BatchService = class BatchService {
|
|
|
3777
3791
|
const batchRepository = manager.getRepository(this.batchEntity);
|
|
3778
3792
|
const batch = await batchRepository.findOneOrFail({
|
|
3779
3793
|
where: { id: options.id },
|
|
3780
|
-
relations:
|
|
3794
|
+
relations: { batchGroup: true },
|
|
3781
3795
|
});
|
|
3782
3796
|
// Validate state transition before proceeding
|
|
3783
3797
|
this.validateStateTransition(batch, options);
|
|
@@ -3787,15 +3801,24 @@ exports.BatchService = class BatchService {
|
|
|
3787
3801
|
...options,
|
|
3788
3802
|
groupId: batch.batchGroup.id,
|
|
3789
3803
|
};
|
|
3790
|
-
|
|
3804
|
+
/*
|
|
3805
|
+
* Absent attributes have to be matched with `IsNull()`, not with a bare
|
|
3806
|
+
* `null`. A `null` on the right of a find condition compiles to `= NULL`,
|
|
3807
|
+
* which is never true in SQL — so this lookup used to miss every batch whose
|
|
3808
|
+
* attributes were unset and split off a duplicate instead of reusing the one
|
|
3809
|
+
* already there. `getBatch` above has always done it this way; this call
|
|
3810
|
+
* site did not. TypeORM 1.x refuses a bare `null` here outright, which is
|
|
3811
|
+
* how the bug surfaced.
|
|
3812
|
+
*/
|
|
3813
|
+
const orNull = (value) => value === null || value === undefined ? typeorm.IsNull() : value;
|
|
3791
3814
|
const whereCondition = {
|
|
3792
3815
|
groupId: mergedBatch.groupId,
|
|
3793
|
-
saleId: mergedBatch.saleId
|
|
3794
|
-
saleSerialId: mergedBatch.saleSerialId
|
|
3795
|
-
customerId: mergedBatch.customerId
|
|
3796
|
-
vendorId: mergedBatch.vendorId
|
|
3797
|
-
inspectionResult: mergedBatch.inspectionResult
|
|
3798
|
-
transferId: mergedBatch.transferId
|
|
3816
|
+
saleId: orNull(mergedBatch.saleId),
|
|
3817
|
+
saleSerialId: orNull(mergedBatch.saleSerialId),
|
|
3818
|
+
customerId: orNull(mergedBatch.customerId),
|
|
3819
|
+
vendorId: orNull(mergedBatch.vendorId),
|
|
3820
|
+
inspectionResult: orNull(mergedBatch.inspectionResult),
|
|
3821
|
+
transferId: orNull(mergedBatch.transferId),
|
|
3799
3822
|
held: mergedBatch.held ?? false,
|
|
3800
3823
|
inShipment: mergedBatch.inShipment ?? false,
|
|
3801
3824
|
};
|
|
@@ -4115,7 +4138,7 @@ exports.ReceiveInventoryOrderService = class ReceiveInventoryOrderService {
|
|
|
4115
4138
|
const stockRepository = manager.getRepository(this.entities.stock);
|
|
4116
4139
|
const items = await itemRepository.find({
|
|
4117
4140
|
where: { id: typeorm.In(options.map((o) => o.itemId)) },
|
|
4118
|
-
relations:
|
|
4141
|
+
relations: { changes: true },
|
|
4119
4142
|
});
|
|
4120
4143
|
const itemMap = new Map(items.map((i) => [i.id, i]));
|
|
4121
4144
|
await Promise.all(options.map(async (option) => {
|
|
@@ -4478,7 +4501,7 @@ exports.ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
|
4478
4501
|
// Find all items with changes to calculate cancellable quantities
|
|
4479
4502
|
const items = await itemRepository.find({
|
|
4480
4503
|
where: { orderId: id },
|
|
4481
|
-
relations:
|
|
4504
|
+
relations: { changes: true },
|
|
4482
4505
|
});
|
|
4483
4506
|
// Build cancel inputs for items with remaining prepared quantity
|
|
4484
4507
|
const cancelInputs = [];
|
|
@@ -4520,7 +4543,7 @@ exports.ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
|
4520
4543
|
const stockRepository = manager.getRepository(this.entities.stock);
|
|
4521
4544
|
const items = await itemRepository.find({
|
|
4522
4545
|
where: { id: typeorm.In(options.map((o) => o.itemId)) },
|
|
4523
|
-
relations:
|
|
4546
|
+
relations: { changes: true },
|
|
4524
4547
|
});
|
|
4525
4548
|
const itemMap = new Map(items.map((item) => [item.id, item]));
|
|
4526
4549
|
await Promise.all(options.map(async (option) => {
|
|
@@ -4677,7 +4700,7 @@ exports.ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
|
4677
4700
|
const stockRepository = manager.getRepository(this.entities.stock);
|
|
4678
4701
|
const items = await itemRepository.find({
|
|
4679
4702
|
where: { id: typeorm.In(options.map((option) => option.itemId)) },
|
|
4680
|
-
relations:
|
|
4703
|
+
relations: { changes: true },
|
|
4681
4704
|
});
|
|
4682
4705
|
const itemMap = new Map(items.map((item) => [item.id, item]));
|
|
4683
4706
|
await Promise.all(options.map(async (option) => {
|
|
@@ -4949,7 +4972,7 @@ exports.TransferOrderService = class TransferOrderService {
|
|
|
4949
4972
|
const repos = this.getRepositories(manager);
|
|
4950
4973
|
const items = await repos.transferOrderItem.find({
|
|
4951
4974
|
where: { id: typeorm.In(options.map((o) => o.itemId)) },
|
|
4952
|
-
relations:
|
|
4975
|
+
relations: { changes: true },
|
|
4953
4976
|
});
|
|
4954
4977
|
const itemMap = new Map(items.map((item) => [item.id, item]));
|
|
4955
4978
|
// Whole-loader transfer cancel validation (Phase 2d-sync).
|
|
@@ -5048,7 +5071,7 @@ exports.TransferOrderService = class TransferOrderService {
|
|
|
5048
5071
|
// Find all items with changes to calculate cancellable quantities
|
|
5049
5072
|
const items = await repos.transferOrderItem.find({
|
|
5050
5073
|
where: { orderId: id },
|
|
5051
|
-
relations:
|
|
5074
|
+
relations: { changes: true },
|
|
5052
5075
|
});
|
|
5053
5076
|
// Build cancel inputs for items with remaining pending quantity
|
|
5054
5077
|
const cancelInputs = [];
|
|
@@ -5091,7 +5114,6 @@ exports.TransferOrderService = class TransferOrderService {
|
|
|
5091
5114
|
for (const srcLoaderId of wholeLoaderSourceIds) {
|
|
5092
5115
|
const [aggRows] = await this.stockService.findAggregatedStocks({
|
|
5093
5116
|
loaderId: srcLoaderId,
|
|
5094
|
-
aggregated: true,
|
|
5095
5117
|
});
|
|
5096
5118
|
// Gate 1
|
|
5097
5119
|
const nonFree = aggRows.filter((r) => r.status !== exports.StockStatus.FREE);
|
|
@@ -5257,7 +5279,7 @@ exports.TransferOrderService = class TransferOrderService {
|
|
|
5257
5279
|
const stockRepository = manager.getRepository(this.stockEntity);
|
|
5258
5280
|
const items = await itemRepository.find({
|
|
5259
5281
|
where: { id: typeorm.In(options.map((o) => o.itemId)) },
|
|
5260
|
-
relations:
|
|
5282
|
+
relations: { changes: true },
|
|
5261
5283
|
});
|
|
5262
5284
|
const itemMap = new Map(items.map((item) => [item.id, item]));
|
|
5263
5285
|
const inputMap = new Map(options.map((o) => [o.itemId, o]));
|
|
@@ -5283,7 +5305,7 @@ exports.TransferOrderService = class TransferOrderService {
|
|
|
5283
5305
|
if (orderId) {
|
|
5284
5306
|
const allOrderItems = await itemRepository.find({
|
|
5285
5307
|
where: { orderId },
|
|
5286
|
-
relations:
|
|
5308
|
+
relations: { changes: true },
|
|
5287
5309
|
});
|
|
5288
5310
|
for (const orderItem of allOrderItems) {
|
|
5289
5311
|
if (orderItem.removedAt)
|
|
@@ -5322,7 +5344,6 @@ exports.TransferOrderService = class TransferOrderService {
|
|
|
5322
5344
|
for (const [srcLoaderId, subTotalQty] of wholeLoaderGroupSums) {
|
|
5323
5345
|
const [aggRows] = await this.stockService.findAggregatedStocks({
|
|
5324
5346
|
loaderId: srcLoaderId,
|
|
5325
|
-
aggregated: true,
|
|
5326
5347
|
});
|
|
5327
5348
|
const loaderTotalQty = aggRows.reduce((s, r) => s + Number(r.quantity), 0);
|
|
5328
5349
|
if (subTotalQty !== loaderTotalQty) {
|
|
@@ -5764,7 +5785,7 @@ exports.AllocateInventoryOrderService = class AllocateInventoryOrderService {
|
|
|
5764
5785
|
if (items?.length) {
|
|
5765
5786
|
const existingItemIds = new Set((await repos.allocateInventoryOrderItem.find({
|
|
5766
5787
|
where: { orderId: id },
|
|
5767
|
-
relations:
|
|
5788
|
+
relations: { changes: true },
|
|
5768
5789
|
})).map((item) => item.id));
|
|
5769
5790
|
const newItems = [];
|
|
5770
5791
|
const existingItems = [];
|
|
@@ -6384,7 +6405,7 @@ exports.TransferVendorOrderService = class TransferVendorOrderService {
|
|
|
6384
6405
|
if (items?.length) {
|
|
6385
6406
|
const existingItemIds = new Set((await repos.transferVendorOrderItem.find({
|
|
6386
6407
|
where: { orderId: id },
|
|
6387
|
-
relations:
|
|
6408
|
+
relations: { changes: true },
|
|
6388
6409
|
})).map((item) => item.id));
|
|
6389
6410
|
const newItems = [];
|
|
6390
6411
|
const existingItems = [];
|
|
@@ -6689,7 +6710,7 @@ exports.TransferCustomerOrderService = class TransferCustomerOrderService {
|
|
|
6689
6710
|
if (items?.length) {
|
|
6690
6711
|
const existingItemIds = new Set((await repos.transferCustomerOrderItem.find({
|
|
6691
6712
|
where: { orderId: id },
|
|
6692
|
-
relations:
|
|
6713
|
+
relations: { changes: true },
|
|
6693
6714
|
})).map((item) => item.id));
|
|
6694
6715
|
const newItems = [];
|
|
6695
6716
|
const existingItems = [];
|
|
@@ -170,7 +170,7 @@ let AllocateInventoryOrderService = class AllocateInventoryOrderService {
|
|
|
170
170
|
if (items?.length) {
|
|
171
171
|
const existingItemIds = new Set((await repos.allocateInventoryOrderItem.find({
|
|
172
172
|
where: { orderId: id },
|
|
173
|
-
relations:
|
|
173
|
+
relations: { changes: true },
|
|
174
174
|
})).map((item) => item.id));
|
|
175
175
|
const newItems = [];
|
|
176
176
|
const existingItems = [];
|
|
@@ -158,7 +158,7 @@ let BatchService = class BatchService {
|
|
|
158
158
|
const batchRepository = manager.getRepository(this.batchEntity);
|
|
159
159
|
const batch = await batchRepository.findOneOrFail({
|
|
160
160
|
where: { id: options.id },
|
|
161
|
-
relations:
|
|
161
|
+
relations: { batchGroup: true },
|
|
162
162
|
});
|
|
163
163
|
// Validate state transition before proceeding
|
|
164
164
|
this.validateStateTransition(batch, options);
|
|
@@ -168,15 +168,24 @@ let BatchService = class BatchService {
|
|
|
168
168
|
...options,
|
|
169
169
|
groupId: batch.batchGroup.id,
|
|
170
170
|
};
|
|
171
|
-
|
|
171
|
+
/*
|
|
172
|
+
* Absent attributes have to be matched with `IsNull()`, not with a bare
|
|
173
|
+
* `null`. A `null` on the right of a find condition compiles to `= NULL`,
|
|
174
|
+
* which is never true in SQL — so this lookup used to miss every batch whose
|
|
175
|
+
* attributes were unset and split off a duplicate instead of reusing the one
|
|
176
|
+
* already there. `getBatch` above has always done it this way; this call
|
|
177
|
+
* site did not. TypeORM 1.x refuses a bare `null` here outright, which is
|
|
178
|
+
* how the bug surfaced.
|
|
179
|
+
*/
|
|
180
|
+
const orNull = (value) => value === null || value === undefined ? IsNull() : value;
|
|
172
181
|
const whereCondition = {
|
|
173
182
|
groupId: mergedBatch.groupId,
|
|
174
|
-
saleId: mergedBatch.saleId
|
|
175
|
-
saleSerialId: mergedBatch.saleSerialId
|
|
176
|
-
customerId: mergedBatch.customerId
|
|
177
|
-
vendorId: mergedBatch.vendorId
|
|
178
|
-
inspectionResult: mergedBatch.inspectionResult
|
|
179
|
-
transferId: mergedBatch.transferId
|
|
183
|
+
saleId: orNull(mergedBatch.saleId),
|
|
184
|
+
saleSerialId: orNull(mergedBatch.saleSerialId),
|
|
185
|
+
customerId: orNull(mergedBatch.customerId),
|
|
186
|
+
vendorId: orNull(mergedBatch.vendorId),
|
|
187
|
+
inspectionResult: orNull(mergedBatch.inspectionResult),
|
|
188
|
+
transferId: orNull(mergedBatch.transferId),
|
|
180
189
|
held: mergedBatch.held ?? false,
|
|
181
190
|
inShipment: mergedBatch.inShipment ?? false,
|
|
182
191
|
};
|
|
@@ -314,7 +314,7 @@ let ReceiveInventoryOrderService = class ReceiveInventoryOrderService {
|
|
|
314
314
|
const stockRepository = manager.getRepository(this.entities.stock);
|
|
315
315
|
const items = await itemRepository.find({
|
|
316
316
|
where: { id: In(options.map((o) => o.itemId)) },
|
|
317
|
-
relations:
|
|
317
|
+
relations: { changes: true },
|
|
318
318
|
});
|
|
319
319
|
const itemMap = new Map(items.map((i) => [i.id, i]));
|
|
320
320
|
await Promise.all(options.map(async (option) => {
|
|
@@ -325,7 +325,7 @@ let ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
|
325
325
|
// Find all items with changes to calculate cancellable quantities
|
|
326
326
|
const items = await itemRepository.find({
|
|
327
327
|
where: { orderId: id },
|
|
328
|
-
relations:
|
|
328
|
+
relations: { changes: true },
|
|
329
329
|
});
|
|
330
330
|
// Build cancel inputs for items with remaining prepared quantity
|
|
331
331
|
const cancelInputs = [];
|
|
@@ -367,7 +367,7 @@ let ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
|
367
367
|
const stockRepository = manager.getRepository(this.entities.stock);
|
|
368
368
|
const items = await itemRepository.find({
|
|
369
369
|
where: { id: In(options.map((o) => o.itemId)) },
|
|
370
|
-
relations:
|
|
370
|
+
relations: { changes: true },
|
|
371
371
|
});
|
|
372
372
|
const itemMap = new Map(items.map((item) => [item.id, item]));
|
|
373
373
|
await Promise.all(options.map(async (option) => {
|
|
@@ -524,7 +524,7 @@ let ShipInventoryOrderService = class ShipInventoryOrderService {
|
|
|
524
524
|
const stockRepository = manager.getRepository(this.entities.stock);
|
|
525
525
|
const items = await itemRepository.find({
|
|
526
526
|
where: { id: In(options.map((option) => option.itemId)) },
|
|
527
|
-
relations:
|
|
527
|
+
relations: { changes: true },
|
|
528
528
|
});
|
|
529
529
|
const itemMap = new Map(items.map((item) => [item.id, item]));
|
|
530
530
|
await Promise.all(options.map(async (option) => {
|
|
@@ -380,7 +380,14 @@ let StockService = class StockService {
|
|
|
380
380
|
}
|
|
381
381
|
async findAggregatedStocks(options) {
|
|
382
382
|
// Create the aggregated subquery without pagination
|
|
383
|
-
const aggregateSubquery = this.pipeSelectOptionsToQueryBuilder({ ...options, offset: undefined, limit: undefined }, this.selectQueryBuilder('stock'),
|
|
383
|
+
const aggregateSubquery = this.pipeSelectOptionsToQueryBuilder({ ...options, offset: undefined, limit: undefined }, this.selectQueryBuilder('stock'),
|
|
384
|
+
// Always aggregated. The outer projection below is hard-wired to the
|
|
385
|
+
// aggregated shape (it selects agg."saleSerialId" and friends), so letting
|
|
386
|
+
// the caller switch the inner subquery off asked the outer query for a
|
|
387
|
+
// column the inner one never produced — a hard `column agg."saleSerialId"
|
|
388
|
+
// does not exist`. There was never a working `false` here: this method
|
|
389
|
+
// returns AggregatedStock[], so aggregating is its only meaning.
|
|
390
|
+
true);
|
|
384
391
|
// Wrap the aggregated subquery and apply pagination on top
|
|
385
392
|
const paginatedQueryBuilder = this.dataSource
|
|
386
393
|
.createQueryBuilder()
|
|
@@ -405,7 +412,14 @@ let StockService = class StockService {
|
|
|
405
412
|
paginatedQueryBuilder.take(options.limit);
|
|
406
413
|
}
|
|
407
414
|
// Get total count from the aggregated subquery
|
|
408
|
-
const countBuilder = this.pipeSelectOptionsToQueryBuilder({ ...options, offset: undefined, limit: undefined }, this.selectQueryBuilder('stock'),
|
|
415
|
+
const countBuilder = this.pipeSelectOptionsToQueryBuilder({ ...options, offset: undefined, limit: undefined }, this.selectQueryBuilder('stock'),
|
|
416
|
+
// Always aggregated. The outer projection below is hard-wired to the
|
|
417
|
+
// aggregated shape (it selects agg."saleSerialId" and friends), so letting
|
|
418
|
+
// the caller switch the inner subquery off asked the outer query for a
|
|
419
|
+
// column the inner one never produced — a hard `column agg."saleSerialId"
|
|
420
|
+
// does not exist`. There was never a working `false` here: this method
|
|
421
|
+
// returns AggregatedStock[], so aggregating is its only meaning.
|
|
422
|
+
true);
|
|
409
423
|
const countResult = await this.dataSource
|
|
410
424
|
.createQueryBuilder()
|
|
411
425
|
.select('COUNT(*)', 'count')
|
|
@@ -174,7 +174,7 @@ let TransferCustomerOrderService = class TransferCustomerOrderService {
|
|
|
174
174
|
if (items?.length) {
|
|
175
175
|
const existingItemIds = new Set((await repos.transferCustomerOrderItem.find({
|
|
176
176
|
where: { orderId: id },
|
|
177
|
-
relations:
|
|
177
|
+
relations: { changes: true },
|
|
178
178
|
})).map((item) => item.id));
|
|
179
179
|
const newItems = [];
|
|
180
180
|
const existingItems = [];
|
|
@@ -162,7 +162,7 @@ let TransferOrderService = class TransferOrderService {
|
|
|
162
162
|
const repos = this.getRepositories(manager);
|
|
163
163
|
const items = await repos.transferOrderItem.find({
|
|
164
164
|
where: { id: In(options.map((o) => o.itemId)) },
|
|
165
|
-
relations:
|
|
165
|
+
relations: { changes: true },
|
|
166
166
|
});
|
|
167
167
|
const itemMap = new Map(items.map((item) => [item.id, item]));
|
|
168
168
|
// Whole-loader transfer cancel validation (Phase 2d-sync).
|
|
@@ -261,7 +261,7 @@ let TransferOrderService = class TransferOrderService {
|
|
|
261
261
|
// Find all items with changes to calculate cancellable quantities
|
|
262
262
|
const items = await repos.transferOrderItem.find({
|
|
263
263
|
where: { orderId: id },
|
|
264
|
-
relations:
|
|
264
|
+
relations: { changes: true },
|
|
265
265
|
});
|
|
266
266
|
// Build cancel inputs for items with remaining pending quantity
|
|
267
267
|
const cancelInputs = [];
|
|
@@ -304,7 +304,6 @@ let TransferOrderService = class TransferOrderService {
|
|
|
304
304
|
for (const srcLoaderId of wholeLoaderSourceIds) {
|
|
305
305
|
const [aggRows] = await this.stockService.findAggregatedStocks({
|
|
306
306
|
loaderId: srcLoaderId,
|
|
307
|
-
aggregated: true,
|
|
308
307
|
});
|
|
309
308
|
// Gate 1
|
|
310
309
|
const nonFree = aggRows.filter((r) => r.status !== StockStatus.FREE);
|
|
@@ -470,7 +469,7 @@ let TransferOrderService = class TransferOrderService {
|
|
|
470
469
|
const stockRepository = manager.getRepository(this.stockEntity);
|
|
471
470
|
const items = await itemRepository.find({
|
|
472
471
|
where: { id: In(options.map((o) => o.itemId)) },
|
|
473
|
-
relations:
|
|
472
|
+
relations: { changes: true },
|
|
474
473
|
});
|
|
475
474
|
const itemMap = new Map(items.map((item) => [item.id, item]));
|
|
476
475
|
const inputMap = new Map(options.map((o) => [o.itemId, o]));
|
|
@@ -496,7 +495,7 @@ let TransferOrderService = class TransferOrderService {
|
|
|
496
495
|
if (orderId) {
|
|
497
496
|
const allOrderItems = await itemRepository.find({
|
|
498
497
|
where: { orderId },
|
|
499
|
-
relations:
|
|
498
|
+
relations: { changes: true },
|
|
500
499
|
});
|
|
501
500
|
for (const orderItem of allOrderItems) {
|
|
502
501
|
if (orderItem.removedAt)
|
|
@@ -535,7 +534,6 @@ let TransferOrderService = class TransferOrderService {
|
|
|
535
534
|
for (const [srcLoaderId, subTotalQty] of wholeLoaderGroupSums) {
|
|
536
535
|
const [aggRows] = await this.stockService.findAggregatedStocks({
|
|
537
536
|
loaderId: srcLoaderId,
|
|
538
|
-
aggregated: true,
|
|
539
537
|
});
|
|
540
538
|
const loaderTotalQty = aggRows.reduce((s, r) => s + Number(r.quantity), 0);
|
|
541
539
|
if (subTotalQty !== loaderTotalQty) {
|
|
@@ -174,7 +174,7 @@ let TransferVendorOrderService = class TransferVendorOrderService {
|
|
|
174
174
|
if (items?.length) {
|
|
175
175
|
const existingItemIds = new Set((await repos.transferVendorOrderItem.find({
|
|
176
176
|
where: { orderId: id },
|
|
177
|
-
relations:
|
|
177
|
+
relations: { changes: true },
|
|
178
178
|
})).map((item) => item.id));
|
|
179
179
|
const newItems = [];
|
|
180
180
|
const existingItems = [];
|
|
@@ -12,6 +12,15 @@ export type FindStockInput<U extends object> = PaginationInput & {
|
|
|
12
12
|
};
|
|
13
13
|
status?: StockStatus;
|
|
14
14
|
negateStatus?: StockStatus;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Ignored, and slated for removal in the next minor.
|
|
17
|
+
*
|
|
18
|
+
* Every method that reads this input already fixes its own aggregation:
|
|
19
|
+
* `findAggregatedStocks` and `findAggregatedStock` always aggregate,
|
|
20
|
+
* `findMany` and `findChangeLogs` never do. Passing `false` to an
|
|
21
|
+
* `findAggregated*` call used to produce a SQL error rather than un-aggregated
|
|
22
|
+
* rows, which is how we know nobody was relying on it.
|
|
23
|
+
*/
|
|
15
24
|
aggregated?: boolean;
|
|
16
25
|
aggregatedKeys?: string[];
|
|
17
26
|
materialKey?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rytass/wms-module-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Rytass WMS Module — NestJS services and TypeORM entities for warehouse management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rytass",
|
|
@@ -48,6 +48,6 @@
|
|
|
48
48
|
"@nestjs/typeorm": "^10.0.0 || ^11.0.0",
|
|
49
49
|
"@rytass/wms-base-nestjs-module": "^0.4.0",
|
|
50
50
|
"reflect-metadata": "^0.1.13 || ^0.2.0",
|
|
51
|
-
"typeorm": "^0.3.0"
|
|
51
|
+
"typeorm": "^0.3.0 || ^1.0.0"
|
|
52
52
|
}
|
|
53
53
|
}
|