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