@things-factory/warehouse-base 8.0.3 → 8.0.6
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,201 +0,0 @@
|
|
|
1
|
-
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
-
import { In } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { Bizplace } from '@things-factory/biz-base'
|
|
5
|
-
|
|
6
|
-
import { Tote } from './tote'
|
|
7
|
-
import { NewTote, TotePatch } from './tote-types'
|
|
8
|
-
|
|
9
|
-
@Resolver(Tote)
|
|
10
|
-
export class ToteMutation {
|
|
11
|
-
@Directive('@transaction')
|
|
12
|
-
@Mutation(returns => Tote)
|
|
13
|
-
async createTote(@Arg('pallet') tote: NewTote, @Ctx() context: ResolverContext): Promise<Tote> {
|
|
14
|
-
const { domain, user, tx } = context.state
|
|
15
|
-
|
|
16
|
-
const existingTote: string[] = (await tx.getRepository(Tote).find({ relations: ['user'] })).map(tote => tote.name)
|
|
17
|
-
if (existingTote.includes(tote.name)) throw new Error('tote box already exists')
|
|
18
|
-
|
|
19
|
-
return await tx.getRepository(Tote).save({
|
|
20
|
-
...tote,
|
|
21
|
-
domain: domain,
|
|
22
|
-
creator: user,
|
|
23
|
-
updater: user
|
|
24
|
-
})
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@Directive('@transaction')
|
|
28
|
-
@Mutation(returns => Tote)
|
|
29
|
-
async updateTote(
|
|
30
|
-
@Arg('name') name: string,
|
|
31
|
-
@Arg('patch') patch: TotePatch,
|
|
32
|
-
@Ctx() context: ResolverContext
|
|
33
|
-
): Promise<Tote> {
|
|
34
|
-
const { domain, user, tx } = context.state
|
|
35
|
-
|
|
36
|
-
const repository = tx.getRepository(Tote)
|
|
37
|
-
const tote = await repository.findOne({
|
|
38
|
-
where: { domain: { id: domain.id }, name }
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
return await repository.save({
|
|
42
|
-
...tote,
|
|
43
|
-
...patch,
|
|
44
|
-
updater: user
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
@Directive('@transaction')
|
|
49
|
-
@Mutation(returns => [Tote])
|
|
50
|
-
async updateMultipleTote(
|
|
51
|
-
@Arg('patches', type => [TotePatch]) patches: TotePatch[],
|
|
52
|
-
@Ctx() context: ResolverContext
|
|
53
|
-
): Promise<Tote[]> {
|
|
54
|
-
const { domain, user, tx } = context.state
|
|
55
|
-
|
|
56
|
-
let results = []
|
|
57
|
-
const _createRecords = patches.filter((patch: any) => patch.cuFlag === '+')
|
|
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]
|
|
63
|
-
|
|
64
|
-
if (newRecord.bizplace && newRecord.bizplace.id) {
|
|
65
|
-
newRecord.bizplace = (await tx.getRepository(Bizplace).findOneBy({ id: newRecord.bizplace.id })) as any
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
let foundTote = await tx.getRepository(Tote).findOne({
|
|
69
|
-
where: { domain: { id: domain.id }, name: newRecord.name, bizplace: { id: newRecord.bizplace.id } }
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
if (foundTote) {
|
|
73
|
-
throw new Error('Duplicated tote found')
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const result: Tote = await tx.getRepository(Tote).save({
|
|
77
|
-
domain: domain,
|
|
78
|
-
creator: user,
|
|
79
|
-
updater: user,
|
|
80
|
-
...newRecord
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
results.push({ ...result, cuFlag: '+' })
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (_updateRecords.length > 0) {
|
|
88
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
89
|
-
const newRecord = _updateRecords[i]
|
|
90
|
-
const tote = await tx.getRepository(Tote).findOne({
|
|
91
|
-
where: { id: newRecord.id },
|
|
92
|
-
relations: ['bizplace']
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
if (newRecord.bizplace && newRecord.bizplace.id) {
|
|
96
|
-
newRecord.bizplace = (await tx.getRepository(Bizplace).findOneBy({ id: newRecord.bizplace.id })) as any
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
let foundTote = await tx.getRepository(Tote).findOne({
|
|
100
|
-
where: { domain: { id: domain.id }, name: newRecord.name, bizplace: { id: newRecord.bizplace.id } }
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
if (foundTote) {
|
|
104
|
-
throw new Error('Duplicated tote found')
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const result = await tx.getRepository(Tote).save({
|
|
108
|
-
...tote,
|
|
109
|
-
...newRecord,
|
|
110
|
-
updater: user
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
results.push({ ...result, cuFlag: 'M' })
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return results
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
@Directive('@transaction')
|
|
121
|
-
@Mutation(returns => Boolean)
|
|
122
|
-
async deleteTote(@Arg('name') id: string, @Ctx() context: ResolverContext): Promise<Boolean> {
|
|
123
|
-
const { domain, user, tx } = context.state
|
|
124
|
-
|
|
125
|
-
const foundTote = await tx.getRepository(Tote).find({ where: { id } })
|
|
126
|
-
|
|
127
|
-
await tx.getRepository(Tote).save({
|
|
128
|
-
...foundTote,
|
|
129
|
-
deletedAt: new Date(),
|
|
130
|
-
updater: user
|
|
131
|
-
})
|
|
132
|
-
return true
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
@Directive('@transaction')
|
|
136
|
-
@Mutation(returns => Boolean)
|
|
137
|
-
async deleteTotes(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<Boolean> {
|
|
138
|
-
const { domain, user, tx } = context.state
|
|
139
|
-
|
|
140
|
-
const totes = await tx.getRepository(Tote).find({
|
|
141
|
-
where: {
|
|
142
|
-
domain: { id: domain.id },
|
|
143
|
-
id: In(ids)
|
|
144
|
-
},
|
|
145
|
-
relations: ['bizplace']
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
await Promise.all(
|
|
149
|
-
totes.map(async (tote: Tote) => {
|
|
150
|
-
await tx.getRepository(Tote).save({
|
|
151
|
-
...tote,
|
|
152
|
-
deletedAt: new Date(),
|
|
153
|
-
updater: user
|
|
154
|
-
})
|
|
155
|
-
})
|
|
156
|
-
)
|
|
157
|
-
return true
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
@Directive('@transaction')
|
|
161
|
-
@Mutation(returns => Boolean)
|
|
162
|
-
async undeleteTotes(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<Boolean> {
|
|
163
|
-
const { tx, user } = context.state
|
|
164
|
-
const toteRepo = tx.getRepository(Tote)
|
|
165
|
-
|
|
166
|
-
await toteRepo.update(
|
|
167
|
-
{
|
|
168
|
-
id: In(ids)
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
deletedAt: null,
|
|
172
|
-
updater: user
|
|
173
|
-
}
|
|
174
|
-
)
|
|
175
|
-
|
|
176
|
-
return true
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
@Directive('@transaction')
|
|
180
|
-
@Mutation(returns => Boolean)
|
|
181
|
-
async bulkUpdateToteStatus(
|
|
182
|
-
@Arg('ids', type => [String]) ids: string[],
|
|
183
|
-
@Arg('status', type => String) status: string,
|
|
184
|
-
@Ctx() context: ResolverContext
|
|
185
|
-
): Promise<Boolean> {
|
|
186
|
-
const { tx, user } = context.state
|
|
187
|
-
const toteRepo = tx.getRepository(Tote)
|
|
188
|
-
|
|
189
|
-
await toteRepo.update(
|
|
190
|
-
{
|
|
191
|
-
id: In(ids)
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
status,
|
|
195
|
-
updater: user
|
|
196
|
-
}
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
return true
|
|
200
|
-
}
|
|
201
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { Arg, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
-
import { IsNull } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { User } from '@things-factory/auth-base'
|
|
5
|
-
import { Bizplace } from '@things-factory/biz-base'
|
|
6
|
-
import { buildQuery, Domain, Filter, getRepository, Pagination, Sorting } from '@things-factory/shell'
|
|
7
|
-
|
|
8
|
-
import { Tote } from './tote'
|
|
9
|
-
import { ToteList } from './tote-types'
|
|
10
|
-
|
|
11
|
-
@Resolver(Tote)
|
|
12
|
-
export class ToteQuery {
|
|
13
|
-
@Query(returns => ToteList)
|
|
14
|
-
async totes(
|
|
15
|
-
@Ctx() context: ResolverContext,
|
|
16
|
-
@Arg('filters', type => [Filter], { nullable: true }) filters?: Filter[],
|
|
17
|
-
@Arg('pagination', type => Pagination, { nullable: true }) pagination?: Pagination,
|
|
18
|
-
@Arg('sortings', type => [Sorting], { nullable: true }) sortings?: Sorting[]
|
|
19
|
-
): Promise<ToteList> {
|
|
20
|
-
const { domain } = context.state
|
|
21
|
-
|
|
22
|
-
const deletedFilter: any = filters.find((filter: any) => filter.name === 'deleted' && filter.value === true)
|
|
23
|
-
|
|
24
|
-
const queryBuilder = getRepository(Tote).createQueryBuilder()
|
|
25
|
-
buildQuery(queryBuilder, { filters, pagination, sortings }, context)
|
|
26
|
-
|
|
27
|
-
queryBuilder
|
|
28
|
-
.leftJoinAndSelect('Tote.domain', 'Domain')
|
|
29
|
-
.leftJoinAndSelect('Tote.bizplace', 'Bizplace')
|
|
30
|
-
.leftJoinAndSelect('Tote.creator', 'Creator')
|
|
31
|
-
.leftJoinAndSelect('Tote.updater', 'Updater')
|
|
32
|
-
.where('Domain.id = :domainId', { domainId: domain.id })
|
|
33
|
-
|
|
34
|
-
if (deletedFilter) {
|
|
35
|
-
queryBuilder.andWhere('Tote.deletedAt IS NOT NULL')
|
|
36
|
-
} else {
|
|
37
|
-
queryBuilder.andWhere('Tote.deletedAt IS NULL')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const [items, total] = await queryBuilder.getManyAndCount()
|
|
41
|
-
|
|
42
|
-
return { items, total }
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@Query(returns => Tote)
|
|
46
|
-
async tote(
|
|
47
|
-
@Arg('name') name: string,
|
|
48
|
-
@Arg('bizplace') bizplace: string,
|
|
49
|
-
@Ctx() context: ResolverContext
|
|
50
|
-
): Promise<Tote> {
|
|
51
|
-
const { domain } = context.state
|
|
52
|
-
let foundBizplace = (await getRepository(Bizplace).findOne({ where: { name: bizplace } })) as Bizplace
|
|
53
|
-
|
|
54
|
-
let foundTote = await getRepository(Tote).findOne({
|
|
55
|
-
where: { domain: { id: domain.id }, bizplace: { id: foundBizplace.id }, name, deletedAt: IsNull() },
|
|
56
|
-
relations: ['domain', 'bizplace', 'creator', 'updater']
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
if (!foundTote) {
|
|
60
|
-
throw new Error('Tote not found')
|
|
61
|
-
} else {
|
|
62
|
-
return foundTote
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
@Query(returns => String)
|
|
67
|
-
async checkToteStatus(
|
|
68
|
-
@Arg('name') name: string,
|
|
69
|
-
@Arg('bizplace') bizplace: string,
|
|
70
|
-
@Ctx() context: ResolverContext
|
|
71
|
-
): Promise<String> {
|
|
72
|
-
const { domain } = context.state
|
|
73
|
-
let foundBizplace = (await getRepository(Bizplace).findOne({ where: { name: bizplace } })) as Bizplace
|
|
74
|
-
|
|
75
|
-
let foundTote = await getRepository(Tote).findOne({
|
|
76
|
-
where: { domain: { id: domain.id }, bizplace: { id: foundBizplace.id }, name, deletedAt: IsNull() },
|
|
77
|
-
relations: ['domain', 'bizplace', 'creator', 'updater']
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
if (!foundTote) {
|
|
81
|
-
return ''
|
|
82
|
-
} else {
|
|
83
|
-
return foundTote.status
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
@FieldResolver()
|
|
88
|
-
async domain(@Root() tote: Tote) {
|
|
89
|
-
return await getRepository(Domain).findOneBy({ id: tote.domainId })
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
@FieldResolver()
|
|
93
|
-
async bizplace(@Root() tote: Tote) {
|
|
94
|
-
return await getRepository(Bizplace).findOneBy({ id: tote.bizplaceId })
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
@FieldResolver()
|
|
98
|
-
async updater(@Root() tote: Tote) {
|
|
99
|
-
return await getRepository(User).findOneBy({ id: tote.updaterId })
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
@FieldResolver()
|
|
103
|
-
async creator(@Root() tote: Tote) {
|
|
104
|
-
return await getRepository(User).findOneBy({ id: tote.creatorId })
|
|
105
|
-
}
|
|
106
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Field, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
-
|
|
3
|
-
import { ObjectRef } from '@things-factory/shell'
|
|
4
|
-
|
|
5
|
-
import { Tote } from './tote'
|
|
6
|
-
|
|
7
|
-
@InputType()
|
|
8
|
-
export class NewTote {
|
|
9
|
-
@Field()
|
|
10
|
-
name: string
|
|
11
|
-
|
|
12
|
-
@Field(type => ObjectRef, { nullable: true })
|
|
13
|
-
bizplace?: ObjectRef
|
|
14
|
-
|
|
15
|
-
@Field({ nullable: true })
|
|
16
|
-
status?: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@ObjectType()
|
|
20
|
-
export class ToteList {
|
|
21
|
-
@Field(type => [Tote], { nullable: true })
|
|
22
|
-
items?: Tote[]
|
|
23
|
-
|
|
24
|
-
@Field(type => Int, { nullable: true })
|
|
25
|
-
total?: number
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@InputType()
|
|
29
|
-
export class TotePatch {
|
|
30
|
-
@Field({ nullable: true })
|
|
31
|
-
id?: string
|
|
32
|
-
|
|
33
|
-
@Field({ nullable: true })
|
|
34
|
-
name?: string
|
|
35
|
-
|
|
36
|
-
@Field(type => ObjectRef, { nullable: true })
|
|
37
|
-
bizplace?: ObjectRef
|
|
38
|
-
|
|
39
|
-
@Field({ nullable: true })
|
|
40
|
-
status?: string
|
|
41
|
-
|
|
42
|
-
@Field({ nullable: true })
|
|
43
|
-
cuFlag?: string
|
|
44
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { Field, 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 { Bizplace } from '@things-factory/biz-base'
|
|
15
|
-
import { Domain } from '@things-factory/shell'
|
|
16
|
-
|
|
17
|
-
@Entity()
|
|
18
|
-
@Index('ix_tote_0', (tote: Tote) => [tote.bizplace, tote.name], { unique: true })
|
|
19
|
-
@ObjectType()
|
|
20
|
-
export class Tote {
|
|
21
|
-
@PrimaryGeneratedColumn('uuid')
|
|
22
|
-
@Field()
|
|
23
|
-
id: string
|
|
24
|
-
|
|
25
|
-
@ManyToOne(type => Domain)
|
|
26
|
-
@Field(type => Domain)
|
|
27
|
-
domain: Domain
|
|
28
|
-
|
|
29
|
-
@RelationId((tote: Tote) => tote.domain)
|
|
30
|
-
domainId: string
|
|
31
|
-
|
|
32
|
-
@Column()
|
|
33
|
-
@Field()
|
|
34
|
-
name: string
|
|
35
|
-
|
|
36
|
-
@ManyToOne(type => Bizplace)
|
|
37
|
-
@ManyToOne(type => Bizplace)
|
|
38
|
-
@Field(type => Bizplace)
|
|
39
|
-
bizplace: Bizplace
|
|
40
|
-
|
|
41
|
-
@RelationId((tote: Tote) => tote.bizplace)
|
|
42
|
-
bizplaceId: string
|
|
43
|
-
|
|
44
|
-
@Column()
|
|
45
|
-
@Field()
|
|
46
|
-
status: string
|
|
47
|
-
|
|
48
|
-
@CreateDateColumn()
|
|
49
|
-
@Field({ nullable: true })
|
|
50
|
-
createdAt: Date
|
|
51
|
-
|
|
52
|
-
@UpdateDateColumn()
|
|
53
|
-
@Field({ nullable: true })
|
|
54
|
-
updatedAt: Date
|
|
55
|
-
|
|
56
|
-
@ManyToOne(type => User, {
|
|
57
|
-
nullable: true
|
|
58
|
-
})
|
|
59
|
-
@Field({ nullable: true })
|
|
60
|
-
creator: User
|
|
61
|
-
|
|
62
|
-
@RelationId((tote: Tote) => tote.creator)
|
|
63
|
-
creatorId: string
|
|
64
|
-
|
|
65
|
-
@ManyToOne(type => User, {
|
|
66
|
-
nullable: true
|
|
67
|
-
})
|
|
68
|
-
@Field({ nullable: true })
|
|
69
|
-
updater: User
|
|
70
|
-
|
|
71
|
-
@RelationId((tote: Tote) => tote.updater)
|
|
72
|
-
updaterId: string
|
|
73
|
-
|
|
74
|
-
@Column({ nullable: true })
|
|
75
|
-
@Field({ nullable: true })
|
|
76
|
-
deletedAt: Date
|
|
77
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
-
import { Repository, In, Equal } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { Warehouse } from './warehouse'
|
|
5
|
-
import { NewWarehouse, WarehousePatch } from './warehouse-types'
|
|
6
|
-
import { Product } from '@things-factory/product-base'
|
|
7
|
-
|
|
8
|
-
@Resolver(Warehouse)
|
|
9
|
-
export class WarehouseMutation {
|
|
10
|
-
@Directive('@privilege(category: "warehouse", privilege: "mutation")')
|
|
11
|
-
@Directive('@transaction')
|
|
12
|
-
@Mutation(returns => Warehouse)
|
|
13
|
-
async createWarehouse(
|
|
14
|
-
@Arg('warehouse') warehouse: NewWarehouse,
|
|
15
|
-
@Ctx() context: ResolverContext
|
|
16
|
-
): Promise<Warehouse> {
|
|
17
|
-
return await createWarehouse(warehouse, context)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@Directive('@privilege(category: "warehouse", privilege: "mutation")')
|
|
21
|
-
@Directive('@transaction')
|
|
22
|
-
@Mutation(returns => Warehouse)
|
|
23
|
-
async updateWarehouse(
|
|
24
|
-
@Arg('id') id: string,
|
|
25
|
-
@Arg('patch') patch: WarehousePatch,
|
|
26
|
-
@Ctx() context: ResolverContext
|
|
27
|
-
): Promise<Warehouse> {
|
|
28
|
-
return await updateWarehouse(id, patch, context)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@Directive('@privilege(category: "warehouse", privilege: "mutation")')
|
|
32
|
-
@Directive('@transaction')
|
|
33
|
-
@Mutation(returns => [Warehouse])
|
|
34
|
-
async updateMultipleWarehouse(
|
|
35
|
-
@Arg('patches', type => [WarehousePatch]) patches: WarehousePatch[],
|
|
36
|
-
@Ctx() context: ResolverContext
|
|
37
|
-
): Promise<Warehouse[]> {
|
|
38
|
-
let results = []
|
|
39
|
-
const _createRecords = patches.filter((patch: any) => patch.cuFlag === '+')
|
|
40
|
-
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
41
|
-
|
|
42
|
-
if (_createRecords.length > 0) {
|
|
43
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
44
|
-
const patch = _createRecords[i]
|
|
45
|
-
const result = await createWarehouse(patch as NewWarehouse, context)
|
|
46
|
-
results.push({ ...result, cuFlag: '+' })
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (_updateRecords.length > 0) {
|
|
51
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
52
|
-
const patch: WarehousePatch = _updateRecords[i]
|
|
53
|
-
const result = await updateWarehouse(patch.id, patch, context)
|
|
54
|
-
results.push({ ...result, cuFlag: 'M' })
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return results
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
@Directive('@privilege(category: "warehouse", privilege: "mutation")')
|
|
62
|
-
@Directive('@transaction')
|
|
63
|
-
@Mutation(returns => Boolean)
|
|
64
|
-
async deleteWarehouse(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Boolean> {
|
|
65
|
-
const { domain, user, tx } = context.state
|
|
66
|
-
const product = await tx.getRepository(Product).findOne({
|
|
67
|
-
where: {
|
|
68
|
-
domain: { id: domain.id },
|
|
69
|
-
warehouseId: Equal(id)
|
|
70
|
-
}
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
if (product?.id) {
|
|
74
|
-
await tx.getRepository(Product).save({
|
|
75
|
-
...product,
|
|
76
|
-
warehouseId: null
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return await deleteWarehouse(id, context)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
@Directive('@privilege(category: "warehouse", privilege: "mutation")')
|
|
84
|
-
@Directive('@transaction')
|
|
85
|
-
@Mutation(returns => Boolean)
|
|
86
|
-
async deleteWarehouses(
|
|
87
|
-
@Arg('ids', type => [String]) ids: string[],
|
|
88
|
-
@Ctx() context: ResolverContext
|
|
89
|
-
): Promise<Boolean> {
|
|
90
|
-
const { domain, user, tx } = context.state
|
|
91
|
-
const products = await tx.getRepository(Product).find({
|
|
92
|
-
where: {
|
|
93
|
-
domain: { id: domain.id },
|
|
94
|
-
warehouseId: In(ids)
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
if (products?.length) {
|
|
99
|
-
await tx.getRepository(Product).save(
|
|
100
|
-
products.map(i => {
|
|
101
|
-
return {
|
|
102
|
-
...i,
|
|
103
|
-
warehouseId: null
|
|
104
|
-
}
|
|
105
|
-
})
|
|
106
|
-
)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return await deleteWarehouses(ids, context)
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export async function createWarehouse(warehouse: NewWarehouse, context: ResolverContext): Promise<Warehouse> {
|
|
114
|
-
const { domain, user, tx } = context.state
|
|
115
|
-
|
|
116
|
-
const repository: Repository<Warehouse> = tx.getRepository(Warehouse)
|
|
117
|
-
return await repository.save({
|
|
118
|
-
...warehouse,
|
|
119
|
-
domain,
|
|
120
|
-
creator: user,
|
|
121
|
-
updater: user
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export async function updateWarehouse(id: string, patch: WarehousePatch, context: ResolverContext): Promise<Warehouse> {
|
|
126
|
-
const { domain, user, tx } = context.state
|
|
127
|
-
|
|
128
|
-
const repository: Repository<Warehouse> = tx.getRepository(Warehouse)
|
|
129
|
-
const warehouse = await repository.findOneBy({ id })
|
|
130
|
-
|
|
131
|
-
return await repository.save({
|
|
132
|
-
...warehouse,
|
|
133
|
-
...patch,
|
|
134
|
-
updater: user
|
|
135
|
-
})
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export async function deleteWarehouse(id: string, context: ResolverContext) {
|
|
139
|
-
const { tx } = context.state
|
|
140
|
-
|
|
141
|
-
const repository: Repository<Warehouse> = tx.getRepository(Warehouse)
|
|
142
|
-
await repository.delete(id)
|
|
143
|
-
return true
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export async function deleteWarehouses(ids: string[], context: ResolverContext) {
|
|
147
|
-
const { tx } = context.state
|
|
148
|
-
|
|
149
|
-
const repository: Repository<Warehouse> = tx.getRepository(Warehouse)
|
|
150
|
-
await repository.delete(ids)
|
|
151
|
-
return true
|
|
152
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
-
|
|
3
|
-
import { User } from '@things-factory/auth-base'
|
|
4
|
-
import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
5
|
-
|
|
6
|
-
import { Warehouse } from './warehouse'
|
|
7
|
-
import { WarehouseList } from './warehouse-types'
|
|
8
|
-
|
|
9
|
-
@Resolver(Warehouse)
|
|
10
|
-
export class WarehouseQuery {
|
|
11
|
-
@Query(returns => Warehouse)
|
|
12
|
-
async warehouse(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Warehouse> {
|
|
13
|
-
const { domain } = context.state
|
|
14
|
-
|
|
15
|
-
return await getRepository(Warehouse).findOne({
|
|
16
|
-
where: {
|
|
17
|
-
domain: { id: domain.id },
|
|
18
|
-
id
|
|
19
|
-
/* name */
|
|
20
|
-
},
|
|
21
|
-
relations: ['domain', 'locations', 'creator', 'updater']
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@Query(returns => WarehouseList)
|
|
26
|
-
async warehouses(
|
|
27
|
-
@Args(type => ListParam) params: ListParam,
|
|
28
|
-
@Ctx() context: ResolverContext
|
|
29
|
-
): Promise<WarehouseList> {
|
|
30
|
-
const { domain } = context.state
|
|
31
|
-
|
|
32
|
-
const queryBuilder = getQueryBuilderFromListParams({
|
|
33
|
-
domain,
|
|
34
|
-
params,
|
|
35
|
-
repository: getRepository(Warehouse),
|
|
36
|
-
searchables: ['name', 'description']
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
const [items, total] = await queryBuilder.getManyAndCount()
|
|
40
|
-
|
|
41
|
-
return { items, total }
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
@FieldResolver(type => Domain)
|
|
45
|
-
async domain(@Root() warehouse: Warehouse) {
|
|
46
|
-
return await getRepository(Domain).findOneBy({ id: warehouse.domainId })
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@FieldResolver(type => User)
|
|
50
|
-
async updater(@Root() warehouse: Warehouse) {
|
|
51
|
-
return await getRepository(User).findOneBy({ id: warehouse.updaterId })
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
@FieldResolver(type => User)
|
|
55
|
-
async creator(@Root() warehouse: Warehouse) {
|
|
56
|
-
return await getRepository(User).findOneBy({ id: warehouse.creatorId })
|
|
57
|
-
}
|
|
58
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Field, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
-
|
|
3
|
-
import { ObjectRef } from '@things-factory/shell'
|
|
4
|
-
|
|
5
|
-
import { Warehouse } from './warehouse'
|
|
6
|
-
|
|
7
|
-
@InputType()
|
|
8
|
-
export class NewWarehouse {
|
|
9
|
-
@Field({ nullable: true })
|
|
10
|
-
id?: string
|
|
11
|
-
|
|
12
|
-
@Field()
|
|
13
|
-
name: string
|
|
14
|
-
|
|
15
|
-
@Field(type => [ObjectRef], { nullable: true })
|
|
16
|
-
locations?: ObjectRef[]
|
|
17
|
-
|
|
18
|
-
@Field({ nullable: true })
|
|
19
|
-
description?: string
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@ObjectType()
|
|
23
|
-
export class WarehouseList {
|
|
24
|
-
@Field(type => [Warehouse], { nullable: true })
|
|
25
|
-
items?: Warehouse[]
|
|
26
|
-
|
|
27
|
-
@Field(type => Int, { nullable: true })
|
|
28
|
-
total?: number
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@InputType()
|
|
32
|
-
export class WarehousePatch {
|
|
33
|
-
@Field({ nullable: true })
|
|
34
|
-
id?: string
|
|
35
|
-
|
|
36
|
-
@Field({ nullable: true })
|
|
37
|
-
name?: string
|
|
38
|
-
|
|
39
|
-
@Field({ nullable: true })
|
|
40
|
-
type?: string
|
|
41
|
-
|
|
42
|
-
@Field(type => [ObjectRef], { nullable: true })
|
|
43
|
-
locations?: ObjectRef[]
|
|
44
|
-
|
|
45
|
-
@Field({ nullable: true })
|
|
46
|
-
description?: string
|
|
47
|
-
|
|
48
|
-
@Field({ nullable: true })
|
|
49
|
-
cuFlag?: string
|
|
50
|
-
}
|