@things-factory/warehouse-base 8.0.2 → 8.0.5
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/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/server/constants/index.ts +0 -5
- package/server/constants/inventory.ts +0 -67
- package/server/constants/location.ts +0 -14
- package/server/constants/pallet.ts +0 -10
- package/server/constants/rule-type.ts +0 -5
- package/server/constants/tote.ts +0 -5
- package/server/controllers/ecommerce/ecommerce-controller.ts +0 -108
- package/server/controllers/ecommerce/index.ts +0 -2
- package/server/controllers/ecommerce/sellercraft-controller.ts +0 -100
- package/server/controllers/index.ts +0 -2
- package/server/controllers/warehouse-controller.ts +0 -181
- package/server/index.ts +0 -9
- package/server/middlewares/index.ts +0 -0
- package/server/migrations/index.ts +0 -9
- package/server/service/index.ts +0 -80
- package/server/service/inventory/index.ts +0 -6
- package/server/service/inventory/inventory-mutation.ts +0 -530
- package/server/service/inventory/inventory-query.ts +0 -1263
- package/server/service/inventory/inventory-types.ts +0 -367
- package/server/service/inventory/inventory.ts +0 -408
- package/server/service/inventory-change/index.ts +0 -6
- package/server/service/inventory-change/inventory-change-mutation.ts +0 -969
- package/server/service/inventory-change/inventory-change-query.ts +0 -93
- package/server/service/inventory-change/inventory-change-types.ts +0 -36
- package/server/service/inventory-change/inventory-change.ts +0 -164
- package/server/service/inventory-history/index.ts +0 -6
- package/server/service/inventory-history/inventory-history-mutation.ts +0 -116
- package/server/service/inventory-history/inventory-history-query.ts +0 -1845
- package/server/service/inventory-history/inventory-history-types.ts +0 -444
- package/server/service/inventory-history/inventory-history.ts +0 -203
- package/server/service/inventory-item/index.ts +0 -6
- package/server/service/inventory-item/inventory-item-mutation.ts +0 -217
- package/server/service/inventory-item/inventory-item-query.ts +0 -226
- package/server/service/inventory-item/inventory-item-type.ts +0 -74
- package/server/service/inventory-item/inventory-item.ts +0 -105
- package/server/service/inventory-item-change/index.ts +0 -6
- package/server/service/inventory-item-change/inventory-item-change-mutation.ts +0 -119
- package/server/service/inventory-item-change/inventory-item-change-query.ts +0 -47
- package/server/service/inventory-item-change/inventory-item-change-type.ts +0 -68
- package/server/service/inventory-item-change/inventory-item-change.ts +0 -92
- package/server/service/inventory-product/index.ts +0 -6
- package/server/service/inventory-product/inventory-product-mutation.ts +0 -116
- package/server/service/inventory-product/inventory-product-query.ts +0 -47
- package/server/service/inventory-product/inventory-product-type.ts +0 -59
- package/server/service/inventory-product/inventory-product.ts +0 -88
- package/server/service/location/index.ts +0 -6
- package/server/service/location/location-mutation.ts +0 -134
- package/server/service/location/location-query.ts +0 -244
- package/server/service/location/location-types.ts +0 -173
- package/server/service/location/location.ts +0 -121
- package/server/service/movement/index.ts +0 -6
- package/server/service/movement/movement-mutation.ts +0 -60
- package/server/service/movement/movement-query.ts +0 -263
- package/server/service/movement/movement-types.ts +0 -74
- package/server/service/movement/movement.ts +0 -81
- package/server/service/pallet/index.ts +0 -6
- package/server/service/pallet/pallet-mutation.ts +0 -242
- package/server/service/pallet/pallet-query.ts +0 -106
- package/server/service/pallet/pallet-types.ts +0 -80
- package/server/service/pallet/pallet.ts +0 -92
- package/server/service/pallet-count/index.ts +0 -6
- package/server/service/pallet-count/pallet-count-mutation.ts +0 -151
- package/server/service/pallet-count/pallet-count-query.ts +0 -45
- package/server/service/pallet-count/pallet-count-types.ts +0 -36
- package/server/service/pallet-count/pallet-count.ts +0 -70
- package/server/service/pallet-history/index.ts +0 -6
- package/server/service/pallet-history/pallet-history-mutation.ts +0 -114
- package/server/service/pallet-history/pallet-history-query.ts +0 -48
- package/server/service/pallet-history/pallet-history-types.ts +0 -36
- package/server/service/pallet-history/pallet-history.ts +0 -89
- package/server/service/reduced-inventory-history/index.ts +0 -3
- package/server/service/reduced-inventory-history/reduced-inventory-history.ts +0 -92
- package/server/service/tote/index.ts +0 -6
- package/server/service/tote/tote-mutation.ts +0 -201
- package/server/service/tote/tote-query.ts +0 -106
- package/server/service/tote/tote-types.ts +0 -44
- package/server/service/tote/tote.ts +0 -77
- package/server/service/warehouse/index.ts +0 -6
- package/server/service/warehouse/warehouse-mutation.ts +0 -152
- package/server/service/warehouse/warehouse-query.ts +0 -58
- package/server/service/warehouse/warehouse-types.ts +0 -50
- package/server/service/warehouse/warehouse.ts +0 -95
- package/server/utils/datetime-util.ts +0 -54
- package/server/utils/index.ts +0 -3
- package/server/utils/inventory-no-generator.ts +0 -15
- package/server/utils/inventory-util.ts +0 -490
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
-
import { In } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { Product } from '@things-factory/product-base'
|
|
5
|
-
|
|
6
|
-
import { INVENTORY_ITEM_SOURCE, INVENTORY_STATUS } from '../../constants'
|
|
7
|
-
import { InventoryNoGenerator } from '../../utils'
|
|
8
|
-
import { InventoryItem } from './inventory-item'
|
|
9
|
-
import { InventoryItemPatch, NewInventoryItem } from './inventory-item-type'
|
|
10
|
-
|
|
11
|
-
@Resolver(InventoryItem)
|
|
12
|
-
export class InventoryItemMutation {
|
|
13
|
-
@Directive('@transaction')
|
|
14
|
-
@Mutation(returns => InventoryItem, { description: 'To create new InventoryItem' })
|
|
15
|
-
async createInventoryItem(
|
|
16
|
-
@Arg('inventoryItem') inventoryItem: NewInventoryItem,
|
|
17
|
-
@Ctx() context: ResolverContext
|
|
18
|
-
): Promise<InventoryItem> {
|
|
19
|
-
const { domain, user, tx } = context.state
|
|
20
|
-
|
|
21
|
-
return await tx.getRepository(InventoryItem).save({
|
|
22
|
-
...inventoryItem,
|
|
23
|
-
domain,
|
|
24
|
-
creator: user,
|
|
25
|
-
updater: user
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@Directive('@transaction')
|
|
30
|
-
@Mutation(returns => InventoryItem, { description: 'To modify InventoryItem information' })
|
|
31
|
-
async updateInventoryItem(
|
|
32
|
-
@Arg('id') id: string,
|
|
33
|
-
@Arg('patch') patch: InventoryItemPatch,
|
|
34
|
-
@Ctx() context: ResolverContext
|
|
35
|
-
): Promise<InventoryItem> {
|
|
36
|
-
const { domain, user, tx } = context.state
|
|
37
|
-
|
|
38
|
-
const repository = tx.getRepository(InventoryItem)
|
|
39
|
-
const inventoryItem = await repository.findOne({
|
|
40
|
-
where: { domain: { id: domain.id }, id }
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
return await repository.save({
|
|
44
|
-
...inventoryItem,
|
|
45
|
-
...patch,
|
|
46
|
-
updater: user
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
@Directive('@transaction')
|
|
51
|
-
@Mutation(returns => Boolean, { description: 'To modify InventoryItem serial number' })
|
|
52
|
-
async updateInventoryItemSerialNumber(
|
|
53
|
-
@Arg('id') id: string,
|
|
54
|
-
@Arg('serialNumber') serialNumber: string,
|
|
55
|
-
@Ctx() context: ResolverContext
|
|
56
|
-
): Promise<boolean> {
|
|
57
|
-
try {
|
|
58
|
-
const { domain, user, tx } = context.state
|
|
59
|
-
|
|
60
|
-
const repository = tx.getRepository(InventoryItem)
|
|
61
|
-
|
|
62
|
-
const inventoryItem = await repository.findOne({
|
|
63
|
-
where: { domain: { id: domain.id }, id },
|
|
64
|
-
relations: ['product']
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
const product: Product = inventoryItem.product
|
|
68
|
-
const duplicatedSerialNumberCnt: number = await repository.countBy({
|
|
69
|
-
domain: { id: domain.id },
|
|
70
|
-
product: { id: product.id },
|
|
71
|
-
serialNumber
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
if (duplicatedSerialNumberCnt) throw new Error(`Serial Number ${serialNumber} is duplicated`)
|
|
75
|
-
|
|
76
|
-
await repository.update({ id }, { serialNumber, updater: user })
|
|
77
|
-
|
|
78
|
-
return true
|
|
79
|
-
} catch (error) {
|
|
80
|
-
throw error
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
@Directive('@transaction')
|
|
85
|
-
@Mutation(returns => [InventoryItem], { description: "To modify multiple InventoryItems' information" })
|
|
86
|
-
async updateMultipleInventoryItem(
|
|
87
|
-
@Arg('patches', type => [InventoryItemPatch]) patches: InventoryItemPatch[],
|
|
88
|
-
@Ctx() context: ResolverContext
|
|
89
|
-
): Promise<InventoryItem[]> {
|
|
90
|
-
const { domain, user, tx } = context.state
|
|
91
|
-
|
|
92
|
-
let results = []
|
|
93
|
-
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
94
|
-
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
95
|
-
const inventoryItemRepo = tx.getRepository(InventoryItem)
|
|
96
|
-
|
|
97
|
-
if (_createRecords.length > 0) {
|
|
98
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
99
|
-
const newRecord = _createRecords[i]
|
|
100
|
-
|
|
101
|
-
const result = await inventoryItemRepo.save({
|
|
102
|
-
...newRecord,
|
|
103
|
-
domain,
|
|
104
|
-
creator: user,
|
|
105
|
-
updater: user
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
results.push({ ...result, cuFlag: '+' })
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (_updateRecords.length > 0) {
|
|
113
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
114
|
-
const newRecord = _updateRecords[i]
|
|
115
|
-
const inventoryItem = await inventoryItemRepo.findOneBy({ id: newRecord.id })
|
|
116
|
-
|
|
117
|
-
const result = await inventoryItemRepo.save({
|
|
118
|
-
...inventoryItem,
|
|
119
|
-
...newRecord,
|
|
120
|
-
updater: user
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
results.push({ ...result, cuFlag: 'M' })
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return results
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
@Directive('@transaction')
|
|
131
|
-
@Mutation(returns => Boolean, { description: 'To delete InventoryItem' })
|
|
132
|
-
async deleteInventoryItem(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
133
|
-
const { domain, tx } = context.state
|
|
134
|
-
|
|
135
|
-
await tx.getRepository(InventoryItem).delete({ domain: { id: domain.id }, id })
|
|
136
|
-
|
|
137
|
-
return true
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
@Directive('@transaction')
|
|
141
|
-
@Mutation(returns => Boolean, { description: 'To delete multiple inventoryItems' })
|
|
142
|
-
async deleteInventoryItems(
|
|
143
|
-
@Arg('ids', type => [String]) ids: string[],
|
|
144
|
-
@Ctx() context: ResolverContext
|
|
145
|
-
): Promise<boolean> {
|
|
146
|
-
const { domain, tx } = context.state
|
|
147
|
-
|
|
148
|
-
await tx.getRepository(InventoryItem).delete({
|
|
149
|
-
domain: { id: domain.id },
|
|
150
|
-
id: In(ids)
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
return true
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
@Directive('@transaction')
|
|
157
|
-
@Mutation(returns => InventoryItem, { description: 'To update picked InventoryItem with new IventoryItem' })
|
|
158
|
-
async replacePickedInventoryItem(
|
|
159
|
-
@Arg('selectedSerialNumber') selectedSerialNumber: InventoryItemPatch,
|
|
160
|
-
@Arg('newSerialNumber') newSerialNumber: string,
|
|
161
|
-
@Ctx() context: ResolverContext
|
|
162
|
-
): Promise<InventoryItem> {
|
|
163
|
-
const { domain, user, tx } = context.state
|
|
164
|
-
|
|
165
|
-
const repository = tx.getRepository(InventoryItem)
|
|
166
|
-
const foundSerialNumber = await repository.findOne({
|
|
167
|
-
where: { domain: { id: domain.id }, serialNumber: newSerialNumber }
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
if ((selectedSerialNumber.source = INVENTORY_ITEM_SOURCE.OUTBOUND)) {
|
|
171
|
-
await tx.getRepository(InventoryItem).delete(selectedSerialNumber.id)
|
|
172
|
-
} else {
|
|
173
|
-
await repository.update(
|
|
174
|
-
{
|
|
175
|
-
domain: { id: domain.id },
|
|
176
|
-
id: selectedSerialNumber.id
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
status: INVENTORY_STATUS.STORED,
|
|
180
|
-
outboundOrderId: null,
|
|
181
|
-
updater: user
|
|
182
|
-
}
|
|
183
|
-
)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (foundSerialNumber) {
|
|
187
|
-
if (foundSerialNumber.productId !== selectedSerialNumber.product?.id) {
|
|
188
|
-
throw new Error('Invalid Serial Number')
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (foundSerialNumber.inventoryId !== selectedSerialNumber.inventory?.id) {
|
|
192
|
-
throw new Error('Serial Number Registered Under Different Inventory')
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (foundSerialNumber.status !== INVENTORY_STATUS.STORED) {
|
|
196
|
-
throw new Error('Inventory Item is not available')
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
foundSerialNumber.status = INVENTORY_STATUS.PICKED
|
|
200
|
-
foundSerialNumber.updater = user
|
|
201
|
-
foundSerialNumber.outboundOrderId = selectedSerialNumber.outboundOrderId
|
|
202
|
-
|
|
203
|
-
return await repository.save(foundSerialNumber)
|
|
204
|
-
} else {
|
|
205
|
-
let inventoryItem: InventoryItem = new InventoryItem()
|
|
206
|
-
inventoryItem.name = InventoryNoGenerator.inventoryItemName()
|
|
207
|
-
inventoryItem.serialNumber = newSerialNumber
|
|
208
|
-
inventoryItem.status = INVENTORY_STATUS.PICKED
|
|
209
|
-
inventoryItem.outboundOrderId = selectedSerialNumber.outboundOrderId
|
|
210
|
-
inventoryItem.product = selectedSerialNumber.product as any
|
|
211
|
-
inventoryItem.inventory = selectedSerialNumber.inventory as any
|
|
212
|
-
inventoryItem.domain = domain
|
|
213
|
-
|
|
214
|
-
return await repository.save(inventoryItem)
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
-
import { Brackets, EntityManager, In, Not, OrderByCondition, SelectQueryBuilder } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { User } from '@things-factory/auth-base'
|
|
5
|
-
import { Product } from '@things-factory/product-base'
|
|
6
|
-
import { convertListParams, Domain, getRepository, ListParam } from '@things-factory/shell'
|
|
7
|
-
|
|
8
|
-
import { INVENTORY_STATUS } from '../../constants'
|
|
9
|
-
import { Inventory } from '../inventory/inventory'
|
|
10
|
-
import { InventoryItem } from './inventory-item'
|
|
11
|
-
import { InventoryItemList } from './inventory-item-type'
|
|
12
|
-
|
|
13
|
-
@Resolver(InventoryItem)
|
|
14
|
-
export class InventoryItemQuery {
|
|
15
|
-
@Query(returns => InventoryItem, { description: 'To fetch a InventoryItem' })
|
|
16
|
-
async inventoryItem(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<InventoryItem> {
|
|
17
|
-
const { domain } = context.state
|
|
18
|
-
|
|
19
|
-
return await getRepository(InventoryItem).findOne({
|
|
20
|
-
where: { domain: { id: domain.id }, id }
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
@Query(returns => InventoryItemList, { description: 'To fetch multiple InventoryItems' })
|
|
25
|
-
async inventoryItems(
|
|
26
|
-
@Args(type => ListParam) params: ListParam,
|
|
27
|
-
@Ctx() context: ResolverContext
|
|
28
|
-
): Promise<InventoryItemList> {
|
|
29
|
-
const { domain } = context.state
|
|
30
|
-
|
|
31
|
-
const convertedParams = convertListParams(params, { domain })
|
|
32
|
-
const [items, total] = await getRepository(InventoryItem).findAndCount({
|
|
33
|
-
...convertedParams,
|
|
34
|
-
relations: ['inventory', 'product']
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
return { items, total }
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@Directive('@transaction')
|
|
41
|
-
@Query(returns => InventoryItemList, { description: 'To fetch multiple InventoryItems with InventoryItemChanges' })
|
|
42
|
-
async inventoryItemsWithChanges(
|
|
43
|
-
@Args(type => ListParam) params: ListParam,
|
|
44
|
-
@Ctx() context: ResolverContext
|
|
45
|
-
): Promise<InventoryItemList> {
|
|
46
|
-
const { domain, tx } = context.state
|
|
47
|
-
|
|
48
|
-
const page = params?.pagination?.page
|
|
49
|
-
const limit = params?.pagination?.limit
|
|
50
|
-
|
|
51
|
-
let inventoryFilter = params.filters.find(filter => filter.name == 'inventoryId')
|
|
52
|
-
|
|
53
|
-
let items: any = []
|
|
54
|
-
let total: any = 0
|
|
55
|
-
if (inventoryFilter) {
|
|
56
|
-
await tx.query(
|
|
57
|
-
`
|
|
58
|
-
create temp table temp_inventory_items on commit drop as (
|
|
59
|
-
select * from (
|
|
60
|
-
select ii.id, ii.name, ii.serial_number, '' as "type", 'ORIGINAL' as "transaction_type", i2.id as inventory_id, i2.name as inventory_name, i2.pallet_id as pallet_id, i2.carton_id as carton_id, p2.id as product_id, p2.name as product_name, p2.sku as product_sku from inventory_items ii
|
|
61
|
-
inner join inventories i2 on i2.id = ii.inventory_id
|
|
62
|
-
inner join products p2 on p2.id = i2.product_id
|
|
63
|
-
where ii.domain_id = $1 and ii.inventory_id = $2 and ii.status = $3
|
|
64
|
-
) src
|
|
65
|
-
)
|
|
66
|
-
`,
|
|
67
|
-
[domain.id, inventoryFilter.value, INVENTORY_STATUS.STORED]
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
const offsetQuery: string = params?.pagination ? `OFFSET ${(page - 1) * limit} LIMIT ${limit}` : ''
|
|
71
|
-
|
|
72
|
-
items = await tx.query(`
|
|
73
|
-
select * from temp_inventory_items ${offsetQuery}
|
|
74
|
-
`)
|
|
75
|
-
|
|
76
|
-
total = await tx.query(`
|
|
77
|
-
select count(*) from temp_inventory_items
|
|
78
|
-
`)
|
|
79
|
-
|
|
80
|
-
items = items.map(item => {
|
|
81
|
-
return {
|
|
82
|
-
id: item.id,
|
|
83
|
-
name: item.name,
|
|
84
|
-
serialNumber: item.serial_number,
|
|
85
|
-
type: item.type,
|
|
86
|
-
transactionType: item.transaction_type,
|
|
87
|
-
inventory: {
|
|
88
|
-
id: item.inventory_id,
|
|
89
|
-
name: item.inventory_name,
|
|
90
|
-
palletId: item.pallet_id,
|
|
91
|
-
cartonId: item.carton_id
|
|
92
|
-
},
|
|
93
|
-
product: {
|
|
94
|
-
id: item.product_id,
|
|
95
|
-
name: item.product_name,
|
|
96
|
-
sku: item.product_sku
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
total = total[0].count
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
items,
|
|
106
|
-
total
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
@Query(returns => InventoryItemList, { description: 'To fetch multiple InventoryItems by inventory' })
|
|
111
|
-
async inventoryItemsByInventory(
|
|
112
|
-
@Args(type => ListParam) params: ListParam,
|
|
113
|
-
@Ctx() context: ResolverContext
|
|
114
|
-
): Promise<InventoryItemList> {
|
|
115
|
-
const { domain } = context.state
|
|
116
|
-
|
|
117
|
-
const page = params.pagination.page
|
|
118
|
-
const limit = params.pagination.limit
|
|
119
|
-
const sortings = params.sortings
|
|
120
|
-
|
|
121
|
-
let inventoryInfoFilter = params.filters.find(filter => filter.name == 'inventory_info')
|
|
122
|
-
let orderTypeFilter = params.filters.find(filter => filter.name == 'orderType')
|
|
123
|
-
let orderIdFilter = params.filters.find(filter => filter.name == 'orderId')
|
|
124
|
-
let productIdFilter = params.filters.find(filter => filter.name == 'productId')
|
|
125
|
-
|
|
126
|
-
let qb: SelectQueryBuilder<InventoryItem> = getRepository(InventoryItem).createQueryBuilder('ivi')
|
|
127
|
-
qb.leftJoinAndSelect('ivi.product', 'product').leftJoinAndSelect('ivi.inventory', 'inventory')
|
|
128
|
-
qb.where('ivi.product_id=:productId', { productId: productIdFilter.value })
|
|
129
|
-
qb.andWhere('inventory.status!=:inventoryStatus', { inventoryStatus: INVENTORY_STATUS.PARTIALLY_UNLOADED })
|
|
130
|
-
qb.andWhere('inventory.domain_id=:domainId', { domainId: domain.id })
|
|
131
|
-
|
|
132
|
-
if (orderTypeFilter.value == 'inbound') {
|
|
133
|
-
qb.andWhere('ivi.inbound_order_id=:orderId', { orderId: orderIdFilter.value })
|
|
134
|
-
} else {
|
|
135
|
-
qb.andWhere('ivi.outbound_order_id=:orderId', { orderId: orderIdFilter.value })
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (inventoryInfoFilter) {
|
|
139
|
-
qb.andWhere(qb => {
|
|
140
|
-
const subQuery = qb
|
|
141
|
-
.subQuery()
|
|
142
|
-
.select()
|
|
143
|
-
.from(Inventory, `inventories`)
|
|
144
|
-
.where(`inventories.id = ivi.inventory_id`)
|
|
145
|
-
.andWhere(
|
|
146
|
-
new Brackets(qb => {
|
|
147
|
-
qb.where('Lower(inventories.pallet_id) LIKE :inventoryInfo', {
|
|
148
|
-
inventoryInfo: '%' + inventoryInfoFilter.value.toLowerCase() + '%'
|
|
149
|
-
})
|
|
150
|
-
.orWhere('Lower(inventories.carton_id) LIKE :inventoryInfo', {
|
|
151
|
-
inventoryInfo: '%' + inventoryInfoFilter.value.toLowerCase() + '%'
|
|
152
|
-
})
|
|
153
|
-
.orWhere('Lower(ivi.serial_number) LIKE :inventoryInfo', {
|
|
154
|
-
inventoryInfo: '%' + inventoryInfoFilter.value.toLowerCase() + '%'
|
|
155
|
-
})
|
|
156
|
-
})
|
|
157
|
-
)
|
|
158
|
-
.getQuery()
|
|
159
|
-
return `EXISTS ${subQuery}`
|
|
160
|
-
})
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (sortings?.length !== 0) {
|
|
164
|
-
const arrChildSortData = ['serial_number']
|
|
165
|
-
const sort: OrderByCondition = (sortings || []).reduce(
|
|
166
|
-
(acc, sort) => ({
|
|
167
|
-
...acc,
|
|
168
|
-
[arrChildSortData.indexOf(sort.name) >= 0 ? sort.name + '.name' : 'ivi.' + sort.name]: sort.desc
|
|
169
|
-
? 'DESC'
|
|
170
|
-
: 'ASC'
|
|
171
|
-
}),
|
|
172
|
-
{}
|
|
173
|
-
)
|
|
174
|
-
qb.orderBy(sort)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
qb.limit(limit)
|
|
178
|
-
qb.offset(limit * (page - 1))
|
|
179
|
-
|
|
180
|
-
let [items, total] = await qb.getManyAndCount()
|
|
181
|
-
|
|
182
|
-
return { items, total }
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
@FieldResolver(type => Domain)
|
|
186
|
-
async domain(@Root() inventoryItem: InventoryItem): Promise<Domain> {
|
|
187
|
-
return await getRepository(Domain).findOneBy({ id: inventoryItem.domainId })
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
@FieldResolver(type => User)
|
|
191
|
-
async updater(@Root() inventoryItem: InventoryItem): Promise<User> {
|
|
192
|
-
return await getRepository(User).findOneBy({ id: inventoryItem.updaterId })
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
@FieldResolver(type => User)
|
|
196
|
-
async creator(@Root() inventoryItem: InventoryItem): Promise<User> {
|
|
197
|
-
return await getRepository(User).findOneBy({ id: inventoryItem.creatorId })
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export async function checkExistingSerialNumber(
|
|
202
|
-
serialNumber: string,
|
|
203
|
-
product: Product,
|
|
204
|
-
context: any,
|
|
205
|
-
inventory?: Inventory,
|
|
206
|
-
tx?: EntityManager
|
|
207
|
-
) {
|
|
208
|
-
const { domain } = context.state
|
|
209
|
-
|
|
210
|
-
let countCondition: any = {
|
|
211
|
-
domain: { id: domain.id },
|
|
212
|
-
product: { id: product.id },
|
|
213
|
-
serialNumber,
|
|
214
|
-
status: Not(In([INVENTORY_STATUS.DELETED, INVENTORY_STATUS.TERMINATED]))
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (inventory) {
|
|
218
|
-
countCondition = { ...countCondition, inventory: { id: inventory.id } }
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const duplicatedSerialNumberCnt: number = await tx.getRepository(InventoryItem).countBy(countCondition)
|
|
222
|
-
|
|
223
|
-
if (duplicatedSerialNumberCnt) {
|
|
224
|
-
return true
|
|
225
|
-
}
|
|
226
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
-
|
|
3
|
-
import { ObjectRef } from '@things-factory/shell'
|
|
4
|
-
|
|
5
|
-
import { InventoryItem } from './inventory-item'
|
|
6
|
-
|
|
7
|
-
@InputType()
|
|
8
|
-
export class NewInventoryItem {
|
|
9
|
-
@Field()
|
|
10
|
-
name: string
|
|
11
|
-
|
|
12
|
-
@Field({ nullable: true })
|
|
13
|
-
serialNumber?: string
|
|
14
|
-
|
|
15
|
-
@Field({ nullable: true })
|
|
16
|
-
status?: string
|
|
17
|
-
|
|
18
|
-
@Field({ nullable: true })
|
|
19
|
-
source?: string
|
|
20
|
-
|
|
21
|
-
@Field(type => ObjectRef, { nullable: true })
|
|
22
|
-
product?: ObjectRef
|
|
23
|
-
|
|
24
|
-
@Field(type => ObjectRef, { nullable: true })
|
|
25
|
-
inventory?: ObjectRef
|
|
26
|
-
|
|
27
|
-
@Field({ nullable: true })
|
|
28
|
-
inboundOrderId?: string
|
|
29
|
-
|
|
30
|
-
@Field({ nullable: true })
|
|
31
|
-
outboundOrderId?: string
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@InputType()
|
|
35
|
-
export class InventoryItemPatch {
|
|
36
|
-
@Field(type => ID, { nullable: true })
|
|
37
|
-
id?: string
|
|
38
|
-
|
|
39
|
-
@Field({ nullable: true })
|
|
40
|
-
name?: string
|
|
41
|
-
|
|
42
|
-
@Field({ nullable: true })
|
|
43
|
-
serialNumber?: string
|
|
44
|
-
|
|
45
|
-
@Field({ nullable: true })
|
|
46
|
-
status?: string
|
|
47
|
-
|
|
48
|
-
@Field({ nullable: true })
|
|
49
|
-
source?: string
|
|
50
|
-
|
|
51
|
-
@Field(type => ObjectRef, { nullable: true })
|
|
52
|
-
product?: ObjectRef
|
|
53
|
-
|
|
54
|
-
@Field(type => ObjectRef, { nullable: true })
|
|
55
|
-
inventory?: ObjectRef
|
|
56
|
-
|
|
57
|
-
@Field({ nullable: true })
|
|
58
|
-
inboundOrderId?: string
|
|
59
|
-
|
|
60
|
-
@Field({ nullable: true })
|
|
61
|
-
outboundOrderId?: string
|
|
62
|
-
|
|
63
|
-
@Field({ nullable: true })
|
|
64
|
-
cuFlag: string
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
@ObjectType()
|
|
68
|
-
export class InventoryItemList {
|
|
69
|
-
@Field(type => [InventoryItem])
|
|
70
|
-
items: InventoryItem[]
|
|
71
|
-
|
|
72
|
-
@Field(type => Int)
|
|
73
|
-
total: number
|
|
74
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { Field, ID, ObjectType } from 'type-graphql'
|
|
2
|
-
import {
|
|
3
|
-
Column,
|
|
4
|
-
CreateDateColumn,
|
|
5
|
-
Entity,
|
|
6
|
-
Index,
|
|
7
|
-
ManyToOne,
|
|
8
|
-
PrimaryGeneratedColumn,
|
|
9
|
-
RelationId,
|
|
10
|
-
UpdateDateColumn
|
|
11
|
-
} from 'typeorm'
|
|
12
|
-
|
|
13
|
-
import { User } from '@things-factory/auth-base'
|
|
14
|
-
import { Product } from '@things-factory/product-base'
|
|
15
|
-
import { Domain } from '@things-factory/shell'
|
|
16
|
-
|
|
17
|
-
import { Inventory } from '../inventory/inventory'
|
|
18
|
-
|
|
19
|
-
@Entity()
|
|
20
|
-
@Index('ix_inventory_item_0', (inventoryItem: InventoryItem) => [inventoryItem.domain, inventoryItem.name], {
|
|
21
|
-
unique: true
|
|
22
|
-
})
|
|
23
|
-
@ObjectType({ description: 'Entity for InventoryItem' })
|
|
24
|
-
export class InventoryItem {
|
|
25
|
-
@PrimaryGeneratedColumn('uuid')
|
|
26
|
-
@Field(type => ID)
|
|
27
|
-
readonly id: string
|
|
28
|
-
|
|
29
|
-
@ManyToOne(type => Domain)
|
|
30
|
-
@Field(type => Domain)
|
|
31
|
-
domain?: Domain
|
|
32
|
-
|
|
33
|
-
@RelationId((inventoryItem: InventoryItem) => inventoryItem.domain)
|
|
34
|
-
domainId?: string
|
|
35
|
-
|
|
36
|
-
@Column()
|
|
37
|
-
@Field()
|
|
38
|
-
name: string
|
|
39
|
-
|
|
40
|
-
@Column({ nullable: true })
|
|
41
|
-
@Field({ nullable: true })
|
|
42
|
-
serialNumber?: string
|
|
43
|
-
|
|
44
|
-
@Column({ nullable: true })
|
|
45
|
-
@Field({ nullable: true })
|
|
46
|
-
status?: string
|
|
47
|
-
|
|
48
|
-
@Column({ nullable: true })
|
|
49
|
-
@Field({ nullable: true })
|
|
50
|
-
source?: string
|
|
51
|
-
|
|
52
|
-
@Column({ nullable: true })
|
|
53
|
-
@Field({ nullable: true })
|
|
54
|
-
inboundOrderId: string
|
|
55
|
-
|
|
56
|
-
@Column({ nullable: true })
|
|
57
|
-
@Field({ nullable: true })
|
|
58
|
-
outboundOrderId: string
|
|
59
|
-
|
|
60
|
-
@ManyToOne(type => Product)
|
|
61
|
-
@Field(type => Product, { nullable: true })
|
|
62
|
-
product?: Product
|
|
63
|
-
|
|
64
|
-
@RelationId((inventoryItem: InventoryItem) => inventoryItem.product)
|
|
65
|
-
productId?: string
|
|
66
|
-
|
|
67
|
-
@ManyToOne(type => Inventory)
|
|
68
|
-
@Field(type => Inventory)
|
|
69
|
-
inventory?: Inventory
|
|
70
|
-
|
|
71
|
-
@RelationId((inventoryItem: InventoryItem) => inventoryItem.inventory)
|
|
72
|
-
inventoryId?: string
|
|
73
|
-
|
|
74
|
-
@CreateDateColumn()
|
|
75
|
-
@Field({ nullable: true })
|
|
76
|
-
createdAt?: Date
|
|
77
|
-
|
|
78
|
-
@UpdateDateColumn()
|
|
79
|
-
@Field({ nullable: true })
|
|
80
|
-
updatedAt?: Date
|
|
81
|
-
|
|
82
|
-
@ManyToOne(type => User, {
|
|
83
|
-
nullable: true
|
|
84
|
-
})
|
|
85
|
-
@Field(type => User, { nullable: true })
|
|
86
|
-
creator?: User
|
|
87
|
-
|
|
88
|
-
@RelationId((inventoryItem: InventoryItem) => inventoryItem.creator)
|
|
89
|
-
creatorId?: string
|
|
90
|
-
|
|
91
|
-
@ManyToOne(type => User, {
|
|
92
|
-
nullable: true
|
|
93
|
-
})
|
|
94
|
-
@Field(type => User, { nullable: true })
|
|
95
|
-
updater?: User
|
|
96
|
-
|
|
97
|
-
@RelationId((inventoryItem: InventoryItem) => inventoryItem.updater)
|
|
98
|
-
updaterId?: string
|
|
99
|
-
|
|
100
|
-
@Field({ nullable: true })
|
|
101
|
-
type?: string
|
|
102
|
-
|
|
103
|
-
@Field({ nullable: true })
|
|
104
|
-
transactionType?: string
|
|
105
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { InventoryItemChange } from './inventory-item-change'
|
|
2
|
-
import { InventoryItemChangeQuery } from './inventory-item-change-query'
|
|
3
|
-
import { InventoryItemChangeMutation } from './inventory-item-change-mutation'
|
|
4
|
-
|
|
5
|
-
export const entities = [InventoryItemChange]
|
|
6
|
-
export const resolvers = [InventoryItemChangeQuery, InventoryItemChangeMutation]
|