@things-factory/warehouse-base 4.3.107 → 4.3.108
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/dist-server/controllers/warehouse-controller.js.map +1 -1
- package/dist-server/service/inventory/inventory-query.js +26 -20
- package/dist-server/service/inventory/inventory-query.js.map +1 -1
- package/dist-server/service/inventory/inventory-types.js +16 -12
- package/dist-server/service/inventory/inventory-types.js.map +1 -1
- package/dist-server/service/inventory/inventory.js +4 -1
- package/dist-server/service/inventory/inventory.js.map +1 -1
- package/dist-server/service/inventory-change/inventory-change-mutation.js +6 -2
- package/dist-server/service/inventory-change/inventory-change-mutation.js.map +1 -1
- package/dist-server/service/inventory-history/inventory-history-query.js +5 -3
- package/dist-server/service/inventory-history/inventory-history-query.js.map +1 -1
- package/dist-server/service/inventory-item/inventory-item.js +8 -3
- package/dist-server/service/inventory-item/inventory-item.js.map +1 -1
- package/dist-server/service/inventory-product/inventory-product.js +8 -3
- package/dist-server/service/inventory-product/inventory-product.js.map +1 -1
- package/dist-server/service/location/location-mutation.js +3 -1
- package/dist-server/service/location/location-mutation.js.map +1 -1
- package/dist-server/service/pallet/pallet-mutation.js +35 -33
- package/dist-server/service/pallet/pallet-mutation.js.map +1 -1
- package/dist-server/service/tote/tote-mutation.js +1 -1
- package/dist-server/service/tote/tote-mutation.js.map +1 -1
- package/dist-server/service/tote/tote-query.js +7 -5
- package/dist-server/service/tote/tote-query.js.map +1 -1
- package/dist-server/service/warehouse/warehouse-mutation.js +33 -1
- package/dist-server/service/warehouse/warehouse-mutation.js.map +1 -1
- package/dist-server/utils/inventory-util.js +86 -25
- package/dist-server/utils/inventory-util.js.map +1 -1
- package/package.json +8 -8
- package/server/controllers/warehouse-controller.ts +0 -1
- package/server/service/inventory/inventory-query.ts +25 -21
- package/server/service/inventory/inventory-types.ts +3 -0
- package/server/service/inventory/inventory.ts +3 -1
- package/server/service/inventory-change/inventory-change-mutation.ts +8 -5
- package/server/service/inventory-history/inventory-history-query.ts +43 -8
- package/server/service/inventory-item/inventory-item.ts +9 -2
- package/server/service/inventory-product/inventory-product.ts +5 -1
- package/server/service/location/location-mutation.ts +3 -1
- package/server/service/pallet/pallet-mutation.ts +50 -69
- package/server/service/tote/tote-mutation.ts +1 -1
- package/server/service/tote/tote-query.ts +9 -7
- package/server/service/warehouse/warehouse-mutation.ts +41 -2
- package/server/utils/inventory-util.ts +116 -51
- package/translations/en.json +4 -2
- package/translations/ko.json +4 -2
- package/translations/ms.json +4 -2
- package/translations/zh.json +14 -12
|
@@ -66,10 +66,11 @@ export class InventoryQuery {
|
|
|
66
66
|
|
|
67
67
|
qb.leftJoinAndSelect('inventory.bizplace', 'bizplace')
|
|
68
68
|
.leftJoinAndSelect('inventory.product', 'product')
|
|
69
|
+
.leftJoinAndSelect('inventory.productDetail', 'productDetail')
|
|
69
70
|
.leftJoinAndSelect(
|
|
70
71
|
'product.productDetails',
|
|
71
|
-
'
|
|
72
|
-
'
|
|
72
|
+
'productDetails',
|
|
73
|
+
'productDetails.id = inventory.product_detail_id'
|
|
73
74
|
)
|
|
74
75
|
.leftJoinAndSelect('inventory.warehouse', 'warehouse')
|
|
75
76
|
.leftJoinAndSelect('inventory.location', 'location')
|
|
@@ -153,12 +154,7 @@ export class InventoryQuery {
|
|
|
153
154
|
let items = (await qb.getRawMany()).map(item => {
|
|
154
155
|
return {
|
|
155
156
|
...new Inventory(item),
|
|
156
|
-
serialNumbers: item.serial_numbers
|
|
157
|
-
productDetail: {
|
|
158
|
-
id: item.productDetail_id,
|
|
159
|
-
name: item.productDetail_name,
|
|
160
|
-
gtin: item.productDetail_gtin
|
|
161
|
-
}
|
|
157
|
+
serialNumbers: item.serial_numbers
|
|
162
158
|
}
|
|
163
159
|
})
|
|
164
160
|
let total = await qb.getCount()
|
|
@@ -401,6 +397,7 @@ export class InventoryQuery {
|
|
|
401
397
|
AND "Inventory"."domain_id" = $1
|
|
402
398
|
${bizplaceQuery}
|
|
403
399
|
${productQuery}
|
|
400
|
+
${inventoryQuery}
|
|
404
401
|
GROUP BY "Product"."id", "Bizplace"."id", "ProductDetailBizplaceSetting"."id", "Inventory"."packing_type", "Location"."type", "ProductRef"."id"
|
|
405
402
|
HAVING 1 = 1
|
|
406
403
|
${availableStockQuery}
|
|
@@ -583,23 +580,27 @@ export class InventoryQuery {
|
|
|
583
580
|
@Arg('bizplaceName') bizplaceName: string,
|
|
584
581
|
@Ctx() context: any
|
|
585
582
|
): Promise<Boolean> {
|
|
586
|
-
|
|
587
|
-
|
|
583
|
+
try {
|
|
584
|
+
const invRepo: Repository<Inventory> = getRepository(Inventory)
|
|
585
|
+
const bizRepo: Repository<Bizplace> = getRepository(Bizplace)
|
|
588
586
|
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
587
|
+
const inventory: Inventory = await invRepo.findOne({
|
|
588
|
+
where: { domain: context.state.domain, palletId, status: INVENTORY_STATUS.STORED },
|
|
589
|
+
relations: ['bizplace']
|
|
590
|
+
})
|
|
593
591
|
|
|
594
|
-
|
|
592
|
+
if (!inventory) throw new Error('This inventory status is not stored.')
|
|
595
593
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
594
|
+
const ownerBizplace: Bizplace = await bizRepo.findOne({
|
|
595
|
+
where: { name: bizplaceName }
|
|
596
|
+
})
|
|
599
597
|
|
|
600
|
-
|
|
598
|
+
const foundBizplace: Bizplace = inventory.bizplace
|
|
601
599
|
|
|
602
|
-
|
|
600
|
+
return Boolean(ownerBizplace.id === foundBizplace.id)
|
|
601
|
+
} catch (e) {
|
|
602
|
+
return false
|
|
603
|
+
}
|
|
603
604
|
}
|
|
604
605
|
|
|
605
606
|
@Directive('@privilege(category: "inventory", privilege: "query")')
|
|
@@ -659,7 +660,7 @@ export class InventoryQuery {
|
|
|
659
660
|
|
|
660
661
|
const productBundleSettings: ProductBundleSetting[] = await getRepository(ProductBundleSetting).find({
|
|
661
662
|
where: { productBundle: productBundleId },
|
|
662
|
-
relations: ['product', 'productBundle']
|
|
663
|
+
relations: ['product', 'productDetail', 'productBundle']
|
|
663
664
|
})
|
|
664
665
|
|
|
665
666
|
if (!productBundleSettings.length) {
|
|
@@ -670,6 +671,7 @@ export class InventoryQuery {
|
|
|
670
671
|
buildQuery(qb, params, context)
|
|
671
672
|
|
|
672
673
|
qb.select('iv.product_id', 'productId')
|
|
674
|
+
.addSelect('iv.product_detail_id', 'productDetailId')
|
|
673
675
|
.addSelect('iv.batch_id', 'batchId')
|
|
674
676
|
.addSelect('iv.batch_id_ref', 'batchIdRef')
|
|
675
677
|
.addSelect('iv.packing_type', 'packingType')
|
|
@@ -698,6 +700,7 @@ export class InventoryQuery {
|
|
|
698
700
|
productIds: productBundleSettings.map(productBundle => productBundle.product.id)
|
|
699
701
|
})
|
|
700
702
|
.groupBy('iv.product_id')
|
|
703
|
+
.addGroupBy('iv.product_detail_id')
|
|
701
704
|
.addGroupBy('iv.batch_id')
|
|
702
705
|
.addGroupBy('iv.batch_id_ref')
|
|
703
706
|
.addGroupBy('iv.packing_type')
|
|
@@ -726,6 +729,7 @@ export class InventoryQuery {
|
|
|
726
729
|
return {
|
|
727
730
|
id: pbs.id,
|
|
728
731
|
productId: pbs.product.id,
|
|
732
|
+
productDetailId: pbs.productDetail.id,
|
|
729
733
|
bundleId: pbs.productBundle.id,
|
|
730
734
|
bundleQty: pbs.bundleQty,
|
|
731
735
|
releaseQty: bundleReleaseQty * pbs.bundleQty,
|
|
@@ -210,6 +210,9 @@ export class Inventory {
|
|
|
210
210
|
@Field({ nullable: true })
|
|
211
211
|
productId: string
|
|
212
212
|
|
|
213
|
+
@Field({ nullable: true })
|
|
214
|
+
productDetailId: string
|
|
215
|
+
|
|
213
216
|
@Field({ nullable: true })
|
|
214
217
|
productName: string
|
|
215
218
|
|
|
@@ -302,7 +305,6 @@ export class Inventory {
|
|
|
302
305
|
description: obj.bizplace_description
|
|
303
306
|
}
|
|
304
307
|
this.product = new Product(obj)
|
|
305
|
-
this.productDetail = new ProductDetail(obj)
|
|
306
308
|
this.location = new Location(obj)
|
|
307
309
|
this.warehouse = new Warehouse(obj)
|
|
308
310
|
this.name = obj.inventory_name
|
|
@@ -6,8 +6,7 @@ import { Bizplace } from '@things-factory/biz-base'
|
|
|
6
6
|
import { generateId } from '@things-factory/id-rule-base'
|
|
7
7
|
import { MarketplaceStore } from '@things-factory/integration-marketplace'
|
|
8
8
|
import { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'
|
|
9
|
-
import {
|
|
10
|
-
import { Product } from '@things-factory/product-base'
|
|
9
|
+
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
11
10
|
import { PartnerSetting, Setting } from '@things-factory/setting-base'
|
|
12
11
|
import { Domain } from '@things-factory/shell'
|
|
13
12
|
|
|
@@ -203,7 +202,9 @@ export class InventoryChangeMutation {
|
|
|
203
202
|
newRecord.bizplace = await tx.getRepository(Bizplace).findOne(newRecord.bizplace.id)
|
|
204
203
|
|
|
205
204
|
var product: Product = await tx.getRepository(Product).findOne(newRecord.product.id)
|
|
205
|
+
var productDetail: ProductDetail = await tx.getRepository(ProductDetail).findOne(newRecord.productDetailId)
|
|
206
206
|
newRecord.product = product
|
|
207
|
+
newRecord.productDetail = productDetail
|
|
207
208
|
|
|
208
209
|
newRecord.status = 'PENDING'
|
|
209
210
|
newRecord.transactionType = 'NEW'
|
|
@@ -530,6 +531,7 @@ async function upsertInventoryItems(context, inventoryChange, approvalStatus, tx
|
|
|
530
531
|
inventoryItem.serialNumber = inventoryItemChange.serialNumber
|
|
531
532
|
inventoryItem.status = INVENTORY_STATUS.STORED
|
|
532
533
|
inventoryItem.product = inventoryChange.inventory.product
|
|
534
|
+
inventoryItem.productDetail = inventoryChange.inventory.productDetail
|
|
533
535
|
inventoryItem.domain = inventoryItemChange.domain
|
|
534
536
|
inventoryItem.inventory = inventoryChange.inventory
|
|
535
537
|
inventoryItem.source = INVENTORY_ITEM_SOURCE.ADJUSTMENT
|
|
@@ -549,7 +551,8 @@ async function upsertInventoryItems(context, inventoryChange, approvalStatus, tx
|
|
|
549
551
|
inventoryItem = {
|
|
550
552
|
...existingInventoryItem,
|
|
551
553
|
serialNumber: inventoryItemChange.serialNumber,
|
|
552
|
-
product: inventoryItemChange.inventory.product
|
|
554
|
+
product: inventoryItemChange.inventory.product,
|
|
555
|
+
productDetail: inventoryItemChange.inventory.productDetail
|
|
553
556
|
}
|
|
554
557
|
} else if (changeType == INVENTORY_ITEM_CHANGE_TYPE.REMOVED) {
|
|
555
558
|
inventoryItem = {
|
|
@@ -586,6 +589,7 @@ export async function approveInventoryChanges(patches: any, context: any) {
|
|
|
586
589
|
'bizplace.company',
|
|
587
590
|
'bizplace.company.domain',
|
|
588
591
|
'product',
|
|
592
|
+
'productDetail',
|
|
589
593
|
'product.productDetails',
|
|
590
594
|
'product.productDetails.childProductDetail',
|
|
591
595
|
'location'
|
|
@@ -621,6 +625,7 @@ export async function approveInventoryChanges(patches: any, context: any) {
|
|
|
621
625
|
'bizplace.company',
|
|
622
626
|
'bizplace.company.domain',
|
|
623
627
|
'product',
|
|
628
|
+
'productDetail',
|
|
624
629
|
'product.productDetails',
|
|
625
630
|
'product.productDetails.childProductDetail',
|
|
626
631
|
'warehouse',
|
|
@@ -630,8 +635,6 @@ export async function approveInventoryChanges(patches: any, context: any) {
|
|
|
630
635
|
]
|
|
631
636
|
})
|
|
632
637
|
|
|
633
|
-
const customerDomain: Domain = inventory.bizplace.domain
|
|
634
|
-
|
|
635
638
|
// Check for locked inventory, and stop from udpating inventory
|
|
636
639
|
if (inventory.qty < inventory.lockedQty) {
|
|
637
640
|
arrLockedInventory.push(_inventoryChanges[i])
|
|
@@ -1,10 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
Arg,
|
|
3
|
+
Args,
|
|
4
|
+
Ctx,
|
|
5
|
+
Directive,
|
|
6
|
+
FieldResolver,
|
|
7
|
+
Query,
|
|
8
|
+
Resolver,
|
|
9
|
+
Root
|
|
10
|
+
} from 'type-graphql'
|
|
11
|
+
import {
|
|
12
|
+
Between,
|
|
13
|
+
Brackets,
|
|
14
|
+
EntityManager,
|
|
15
|
+
getRepository,
|
|
16
|
+
In,
|
|
17
|
+
IsNull,
|
|
18
|
+
Raw,
|
|
19
|
+
SelectQueryBuilder
|
|
20
|
+
} from 'typeorm'
|
|
3
21
|
|
|
4
22
|
import { User } from '@things-factory/auth-base'
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
23
|
+
import {
|
|
24
|
+
Bizplace,
|
|
25
|
+
getMyBizplace,
|
|
26
|
+
getPermittedBizplaceIds
|
|
27
|
+
} from '@things-factory/biz-base'
|
|
28
|
+
import {
|
|
29
|
+
Product,
|
|
30
|
+
ProductDetail
|
|
31
|
+
} from '@things-factory/product-base'
|
|
32
|
+
import {
|
|
33
|
+
buildQuery,
|
|
34
|
+
convertListParams,
|
|
35
|
+
Domain,
|
|
36
|
+
Filter,
|
|
37
|
+
ListParam,
|
|
38
|
+
Pagination,
|
|
39
|
+
Sorting
|
|
40
|
+
} from '@things-factory/shell'
|
|
8
41
|
|
|
9
42
|
import { RawInventoryHistoryList } from '../'
|
|
10
43
|
import { InventoryList } from '../inventory/inventory-types'
|
|
@@ -230,6 +263,8 @@ export class InventoryHistoryQuery {
|
|
|
230
263
|
Lower(prd.name) LIKE ANY(ARRAY[${productValue}])
|
|
231
264
|
OR Lower(prd.sku) LIKE ANY(ARRAY[${productValue}])
|
|
232
265
|
OR Lower(prd.description) LIKE ANY(ARRAY[${productValue}])
|
|
266
|
+
OR Lower(prd.brand) LIKE ANY(ARRAY[${productValue}])
|
|
267
|
+
OR Lower(prd.brand_sku) LIKE ANY(ARRAY[${productValue}])
|
|
233
268
|
)`
|
|
234
269
|
}
|
|
235
270
|
|
|
@@ -1425,7 +1460,7 @@ export class InventoryHistoryQuery {
|
|
|
1425
1460
|
rih.bizplace_id as bizplace_id,
|
|
1426
1461
|
cast(rih.created_at + (interval '8 hour') as DATE) as "tempDate"
|
|
1427
1462
|
from reduced_inventory_histories rih
|
|
1428
|
-
left join product_details pd on pd.
|
|
1463
|
+
left join product_details pd on pd.id = rih.product_detail_id
|
|
1429
1464
|
where rih.status not like 'TERMINATED' and rih.bizplace_id = $1
|
|
1430
1465
|
group by CAST(rih.created_at + (interval '8 hour') as DATE), rih.bizplace_id
|
|
1431
1466
|
)
|
|
@@ -1465,8 +1500,8 @@ export class InventoryHistoryQuery {
|
|
|
1465
1500
|
await tx.query(
|
|
1466
1501
|
`
|
|
1467
1502
|
create temp table temp_result ON COMMIT drop as(
|
|
1468
|
-
select lag(sub."closingQty", 1, 0) over (partition by sub.bizplace_id order by sub.date) as "openingQty",
|
|
1469
|
-
lag(sub."closingVolume", 1, 0) over (partition by sub.bizplace_id order by sub.date) as "openingVolume", sub.* from(
|
|
1503
|
+
select lag(sub."closingQty", 1, 0::double precision) over (partition by sub.bizplace_id order by sub.date) as "openingQty",
|
|
1504
|
+
lag(sub."closingVolume", 1, 0::numeric) over (partition by sub.bizplace_id order by sub.date) as "openingVolume", sub.* from(
|
|
1470
1505
|
select (select sum(tmp2.total) from temp_reduced_inventory_histories_with_date_range tmp2 where tmp2.row <= tmp.row) as "closingQty",
|
|
1471
1506
|
(select sum(tmp2."totalVolume") from temp_reduced_inventory_histories_with_date_range tmp2 where tmp2.row <= tmp.row) as "closingVolume", tmp.* from
|
|
1472
1507
|
temp_reduced_inventory_histories_with_date_range tmp) sub
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from 'typeorm'
|
|
12
12
|
|
|
13
13
|
import { User } from '@things-factory/auth-base'
|
|
14
|
-
import { Product } from '@things-factory/product-base'
|
|
14
|
+
import { Product, ProductDetail} from '@things-factory/product-base'
|
|
15
15
|
import { Domain } from '@things-factory/shell'
|
|
16
16
|
|
|
17
17
|
import { Inventory } from '../inventory/inventory'
|
|
@@ -32,7 +32,8 @@ export class InventoryItem {
|
|
|
32
32
|
|
|
33
33
|
@RelationId((inventoryItem: InventoryItem) => inventoryItem.domain)
|
|
34
34
|
domainId?: string
|
|
35
|
-
|
|
35
|
+
|
|
36
|
+
|
|
36
37
|
@Column()
|
|
37
38
|
@Field()
|
|
38
39
|
name: string
|
|
@@ -57,13 +58,19 @@ export class InventoryItem {
|
|
|
57
58
|
@Field({ nullable: true })
|
|
58
59
|
outboundOrderId: string
|
|
59
60
|
|
|
61
|
+
|
|
60
62
|
@ManyToOne(type => Product)
|
|
61
63
|
@Field(type => Product, { nullable: true })
|
|
62
64
|
product?: Product
|
|
63
65
|
|
|
66
|
+
|
|
64
67
|
@RelationId((inventoryItem: InventoryItem) => inventoryItem.product)
|
|
65
68
|
productId?: string
|
|
66
69
|
|
|
70
|
+
@ManyToOne(type => ProductDetail, { nullable: true })
|
|
71
|
+
@Field({ nullable: true })
|
|
72
|
+
productDetail: ProductDetail
|
|
73
|
+
|
|
67
74
|
@ManyToOne(type => Inventory)
|
|
68
75
|
@Field(type => Inventory)
|
|
69
76
|
inventory?: Inventory
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from 'typeorm'
|
|
12
12
|
|
|
13
13
|
import { User } from '@things-factory/auth-base'
|
|
14
|
-
import { Product } from '@things-factory/product-base'
|
|
14
|
+
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
15
15
|
import { Domain } from '@things-factory/shell'
|
|
16
16
|
|
|
17
17
|
@Entity()
|
|
@@ -60,6 +60,10 @@ export class InventoryProduct {
|
|
|
60
60
|
@RelationId((inventoryProduct: InventoryProduct) => inventoryProduct.product)
|
|
61
61
|
productId?: string
|
|
62
62
|
|
|
63
|
+
@ManyToOne(type => ProductDetail, { nullable: true })
|
|
64
|
+
@Field({ nullable: true })
|
|
65
|
+
productDetail: ProductDetail
|
|
66
|
+
|
|
63
67
|
@CreateDateColumn()
|
|
64
68
|
@Field({ nullable: true })
|
|
65
69
|
createdAt?: Date
|
|
@@ -77,10 +77,12 @@ export class LocationMutation {
|
|
|
77
77
|
@Mutation(returns => Boolean)
|
|
78
78
|
async deleteAllLocations(@Arg('warehouseId') warehouseId: string, @Ctx() context: any) {
|
|
79
79
|
const { tx }: { tx: EntityManager } = context.state
|
|
80
|
+
let warehouse = await tx.getRepository(Warehouse).findOne(warehouseId)
|
|
80
81
|
|
|
81
82
|
await tx.getRepository(Location).delete({
|
|
82
|
-
warehouse
|
|
83
|
+
warehouse
|
|
83
84
|
})
|
|
85
|
+
return true
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
88
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
-
import { EntityManager, In } from 'typeorm'
|
|
2
|
+
import { EntityManager, In, getRepository } from 'typeorm'
|
|
3
3
|
|
|
4
4
|
import { User } from '@things-factory/auth-base'
|
|
5
5
|
import { Bizplace } from '@things-factory/biz-base'
|
|
@@ -8,6 +8,7 @@ import { Domain } from '@things-factory/shell'
|
|
|
8
8
|
import { PalletHistory } from '../pallet-history/pallet-history'
|
|
9
9
|
import { Pallet } from './pallet'
|
|
10
10
|
import { NewPallet, PalletPatch } from './pallet-types'
|
|
11
|
+
import i18next from 'i18next'
|
|
11
12
|
|
|
12
13
|
@Resolver(Pallet)
|
|
13
14
|
export class PalletMutation {
|
|
@@ -25,12 +26,8 @@ export class PalletMutation {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
@Directive('@transaction')
|
|
28
|
-
@Mutation(returns =>
|
|
29
|
-
async updatePallet(
|
|
30
|
-
@Arg('name') name: string,
|
|
31
|
-
@Arg('patch') patch: PalletPatch,
|
|
32
|
-
@Ctx() context: any
|
|
33
|
-
): Promise<Pallet> {
|
|
29
|
+
@Mutation(returns => Boolean)
|
|
30
|
+
async updatePallet(@Arg('name') name: string, @Arg('patch') patch: PalletPatch, @Ctx() context: any) {
|
|
34
31
|
const { domain, user, tx }: { domain: Domain; user: User; tx: EntityManager } = context.state
|
|
35
32
|
|
|
36
33
|
const repository = tx.getRepository(Pallet)
|
|
@@ -46,80 +43,66 @@ export class PalletMutation {
|
|
|
46
43
|
}
|
|
47
44
|
|
|
48
45
|
@Directive('@transaction')
|
|
49
|
-
@Mutation(returns =>
|
|
50
|
-
async updateMultiplePallet(
|
|
51
|
-
@Arg('patches', type => [PalletPatch]) patches: PalletPatch[],
|
|
52
|
-
@Ctx() context: any
|
|
53
|
-
): Promise<Pallet[]> {
|
|
46
|
+
@Mutation(returns => Boolean)
|
|
47
|
+
async updateMultiplePallet(@Arg('patches', type => [PalletPatch]) patches: PalletPatch[], @Ctx() context: any) {
|
|
54
48
|
const { domain, user, tx }: { domain: Domain; user: User; tx: EntityManager } = context.state
|
|
55
49
|
|
|
56
|
-
let
|
|
57
|
-
|
|
58
|
-
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
59
|
-
|
|
60
|
-
if (_createRecords.length > 0) {
|
|
61
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
62
|
-
const newRecord = _createRecords[i]
|
|
50
|
+
for (let patch of patches) {
|
|
51
|
+
let foundPallet: Pallet
|
|
63
52
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
if (patch.name) {
|
|
54
|
+
foundPallet = await getRepository(Pallet).findOne({
|
|
55
|
+
where: {
|
|
56
|
+
domain,
|
|
57
|
+
name: patch.name
|
|
58
|
+
},
|
|
59
|
+
relations: ['owner', 'holder']
|
|
60
|
+
})
|
|
61
|
+
} else if (patch.id) {
|
|
62
|
+
foundPallet = await getRepository(Pallet).findOne({
|
|
63
|
+
where: {
|
|
64
|
+
domain,
|
|
65
|
+
id: patch.id
|
|
66
|
+
},
|
|
67
|
+
relations: ['owner', 'holder']
|
|
68
|
+
})
|
|
69
|
+
}
|
|
67
70
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
+
if (!foundPallet) {
|
|
72
|
+
delete patch?.id
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
domain: domain,
|
|
74
|
-
creator: user,
|
|
75
|
-
updater: user,
|
|
76
|
-
...newRecord
|
|
77
|
-
})
|
|
74
|
+
let newPallet = await tx.getRepository(Pallet).save({ ...patch, domain, creator: user, updater: user })
|
|
78
75
|
|
|
79
76
|
await tx.getRepository(PalletHistory).save({
|
|
80
|
-
...
|
|
81
|
-
pallet:
|
|
77
|
+
...patch,
|
|
78
|
+
pallet: newPallet,
|
|
82
79
|
domain: domain,
|
|
83
80
|
creator: user,
|
|
84
81
|
updater: user,
|
|
85
82
|
transactionType: 'NEW'
|
|
86
83
|
})
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (_updateRecords.length > 0) {
|
|
93
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
94
|
-
const newRecord = _updateRecords[i]
|
|
95
|
-
const pallet = await tx.getRepository(Pallet).findOne({
|
|
96
|
-
where: { id: newRecord.id },
|
|
97
|
-
relations: ['owner', 'holder']
|
|
98
|
-
})
|
|
99
|
-
const seq = pallet.seq + 1
|
|
100
|
-
|
|
101
|
-
if (newRecord.owner && newRecord.owner.id) {
|
|
102
|
-
newRecord.owner = await tx.getRepository(Bizplace).findOne(newRecord.owner.id)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (newRecord.holder && newRecord.holder.id) {
|
|
106
|
-
newRecord.holder = await tx.getRepository(Bizplace).findOne(newRecord.holder.id)
|
|
84
|
+
} else {
|
|
85
|
+
if (patch.cuFlag === '+') {
|
|
86
|
+
throw new Error(i18next.t('error.pallet (x) already exists', { x: patch.name }))
|
|
107
87
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
88
|
+
delete patch.cuFlag
|
|
89
|
+
|
|
90
|
+
let updatedPallet: any = await tx.getRepository(Pallet).update(
|
|
91
|
+
{ id: foundPallet.id },
|
|
92
|
+
{
|
|
93
|
+
...patch,
|
|
94
|
+
updater: user,
|
|
95
|
+
seq: foundPallet.seq++,
|
|
96
|
+
refOrderNo: null
|
|
97
|
+
}
|
|
98
|
+
)
|
|
116
99
|
|
|
117
100
|
let newHistory = {
|
|
118
|
-
...
|
|
119
|
-
...
|
|
120
|
-
pallet:
|
|
121
|
-
seq,
|
|
122
|
-
domain
|
|
101
|
+
...foundPallet,
|
|
102
|
+
...patch,
|
|
103
|
+
pallet: updatedPallet,
|
|
104
|
+
seq: updatedPallet.seq,
|
|
105
|
+
domain,
|
|
123
106
|
creator: user,
|
|
124
107
|
updater: user,
|
|
125
108
|
transactionType: 'UPDATE'
|
|
@@ -130,12 +113,10 @@ export class PalletMutation {
|
|
|
130
113
|
await tx.getRepository(PalletHistory).save({
|
|
131
114
|
...newHistory
|
|
132
115
|
})
|
|
133
|
-
|
|
134
|
-
results.push({ ...result, cuFlag: 'M' })
|
|
135
116
|
}
|
|
136
117
|
}
|
|
137
118
|
|
|
138
|
-
return
|
|
119
|
+
return true
|
|
139
120
|
}
|
|
140
121
|
|
|
141
122
|
@Directive('@transaction')
|
|
@@ -97,7 +97,7 @@ export class ToteMutation {
|
|
|
97
97
|
|
|
98
98
|
let foundTote = await tx
|
|
99
99
|
.getRepository(Tote)
|
|
100
|
-
.findOne({ where: { domain, name:
|
|
100
|
+
.findOne({ where: { domain, name: tote.name, bizplace: newRecord.bizplace } })
|
|
101
101
|
|
|
102
102
|
if (foundTote) {
|
|
103
103
|
throw new Error('Duplicated tote found')
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Arg, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
-
import { getRepository, IsNull } from 'typeorm'
|
|
1
|
+
import { Arg, Ctx, FieldResolver, Query, Resolver, Root, Directive } from 'type-graphql'
|
|
2
|
+
import { getRepository, IsNull, EntityManager } from 'typeorm'
|
|
3
3
|
|
|
4
4
|
import { User } from '@things-factory/auth-base'
|
|
5
5
|
import { Bizplace } from '@things-factory/biz-base'
|
|
@@ -10,6 +10,7 @@ import { ToteList } from './tote-types'
|
|
|
10
10
|
|
|
11
11
|
@Resolver(Tote)
|
|
12
12
|
export class ToteQuery {
|
|
13
|
+
@Directive('@transaction')
|
|
13
14
|
@Query(returns => ToteList)
|
|
14
15
|
async totes(
|
|
15
16
|
@Ctx() context: any,
|
|
@@ -17,11 +18,12 @@ export class ToteQuery {
|
|
|
17
18
|
@Arg('pagination', type => Pagination, { nullable: true }) pagination?: Pagination,
|
|
18
19
|
@Arg('sortings', type => [Sorting], { nullable: true }) sortings?: Sorting[]
|
|
19
20
|
): Promise<ToteList> {
|
|
20
|
-
const { domain }: { domain: Domain } = context.state
|
|
21
|
+
const { domain, tx }: { domain: Domain; tx: EntityManager } = context.state
|
|
21
22
|
|
|
22
|
-
const deletedFilter: any = filters.find((filter: any) => filter.name === '
|
|
23
|
+
const deletedFilter: any = filters.find((filter: any) => filter.name === 'deleted_at')
|
|
24
|
+
delete filters[filters.indexOf(deletedFilter)]
|
|
23
25
|
|
|
24
|
-
const queryBuilder = getRepository(Tote).createQueryBuilder()
|
|
26
|
+
const queryBuilder = tx.getRepository(Tote).createQueryBuilder()
|
|
25
27
|
buildQuery(queryBuilder, { filters, pagination, sortings }, context)
|
|
26
28
|
|
|
27
29
|
queryBuilder
|
|
@@ -29,9 +31,9 @@ export class ToteQuery {
|
|
|
29
31
|
.leftJoinAndSelect('Tote.bizplace', 'Bizplace')
|
|
30
32
|
.leftJoinAndSelect('Tote.creator', 'Creator')
|
|
31
33
|
.leftJoinAndSelect('Tote.updater', 'Updater')
|
|
32
|
-
.
|
|
34
|
+
.andWhere('Domain.id = :domainId', { domainId: domain.id })
|
|
33
35
|
|
|
34
|
-
if (deletedFilter) {
|
|
36
|
+
if (deletedFilter.value) {
|
|
35
37
|
queryBuilder.andWhere('Tote.deletedAt IS NOT NULL')
|
|
36
38
|
} else {
|
|
37
39
|
queryBuilder.andWhere('Tote.deletedAt IS NULL')
|
|
@@ -7,6 +7,8 @@ import { Domain } from '@things-factory/shell'
|
|
|
7
7
|
import { Warehouse } from './warehouse'
|
|
8
8
|
import { NewWarehouse, WarehousePatch } from './warehouse-types'
|
|
9
9
|
|
|
10
|
+
import i18next from 'i18next'
|
|
11
|
+
|
|
10
12
|
@Resolver(Warehouse)
|
|
11
13
|
export class WarehouseMutation {
|
|
12
14
|
@Directive('@privilege(category: "warehouse", privilege: "mutation")')
|
|
@@ -29,11 +31,48 @@ export class WarehouseMutation {
|
|
|
29
31
|
|
|
30
32
|
@Directive('@privilege(category: "warehouse", privilege: "mutation")')
|
|
31
33
|
@Directive('@transaction')
|
|
32
|
-
@Mutation(returns =>
|
|
34
|
+
@Mutation(returns => Boolean)
|
|
33
35
|
async updateMultipleWarehouse(
|
|
34
36
|
@Arg('patches', type => [WarehousePatch]) patches: WarehousePatch[],
|
|
35
37
|
@Ctx() context: any
|
|
36
|
-
)
|
|
38
|
+
) {
|
|
39
|
+
const { tx, domain, user }: { tx: EntityManager; domain: Domain; user: User } = context.state
|
|
40
|
+
|
|
41
|
+
for (let patch of patches) {
|
|
42
|
+
let foundWarehouse: Warehouse
|
|
43
|
+
|
|
44
|
+
if (patch?.name) {
|
|
45
|
+
foundWarehouse = await tx.getRepository(Warehouse).findOne({
|
|
46
|
+
domain,
|
|
47
|
+
name: patch.name
|
|
48
|
+
})
|
|
49
|
+
} else if (patch?.id) {
|
|
50
|
+
foundWarehouse = await tx.getRepository(Warehouse).findOne({
|
|
51
|
+
domain,
|
|
52
|
+
id: patch.id
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!foundWarehouse) {
|
|
57
|
+
delete patch?.id
|
|
58
|
+
await tx.getRepository(Warehouse).save({ ...patch, domain, creator: user, updater: user })
|
|
59
|
+
} else {
|
|
60
|
+
if (patch.cuFlag === '+') {
|
|
61
|
+
throw new Error(i18next.t('error.warehouse (x) already exists', { x: patch.name }))
|
|
62
|
+
}
|
|
63
|
+
delete patch.cuFlag
|
|
64
|
+
await tx.getRepository(Warehouse).update(
|
|
65
|
+
{ id: foundWarehouse.id },
|
|
66
|
+
{
|
|
67
|
+
...patch,
|
|
68
|
+
updater: user
|
|
69
|
+
}
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return true
|
|
75
|
+
|
|
37
76
|
let results = []
|
|
38
77
|
const _createRecords = patches.filter((patch: any) => patch.cuFlag === '+')
|
|
39
78
|
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|