@things-factory/routing-base 4.0.22

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.
Files changed (79) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE.md +21 -0
  3. package/client/actions/main.js +1 -0
  4. package/client/bootstrap.js +8 -0
  5. package/client/index.js +1 -0
  6. package/client/reducers/main.js +17 -0
  7. package/client/themes/app-theme.css +59 -0
  8. package/config/config.development.js +1 -0
  9. package/config/config.production.js +1 -0
  10. package/dist-server/controllers/index.js +1 -0
  11. package/dist-server/controllers/index.js.map +1 -0
  12. package/dist-server/index.js +17 -0
  13. package/dist-server/index.js.map +1 -0
  14. package/dist-server/middlewares/index.js +8 -0
  15. package/dist-server/middlewares/index.js.map +1 -0
  16. package/dist-server/migrations/index.js +12 -0
  17. package/dist-server/migrations/index.js.map +1 -0
  18. package/dist-server/routes.js +25 -0
  19. package/dist-server/routes.js.map +1 -0
  20. package/dist-server/service/index.js +30 -0
  21. package/dist-server/service/index.js.map +1 -0
  22. package/dist-server/service/operation/index.js +9 -0
  23. package/dist-server/service/operation/index.js.map +1 -0
  24. package/dist-server/service/operation/operation-mutation.js +120 -0
  25. package/dist-server/service/operation/operation-mutation.js.map +1 -0
  26. package/dist-server/service/operation/operation-query.js +87 -0
  27. package/dist-server/service/operation/operation-query.js.map +1 -0
  28. package/dist-server/service/operation/operation-type.js +97 -0
  29. package/dist-server/service/operation/operation-type.js.map +1 -0
  30. package/dist-server/service/operation/operation.js +127 -0
  31. package/dist-server/service/operation/operation.js.map +1 -0
  32. package/dist-server/service/routing/index.js +9 -0
  33. package/dist-server/service/routing/index.js.map +1 -0
  34. package/dist-server/service/routing/routing-mutation.js +120 -0
  35. package/dist-server/service/routing/routing-mutation.js.map +1 -0
  36. package/dist-server/service/routing/routing-query.js +232 -0
  37. package/dist-server/service/routing/routing-query.js.map +1 -0
  38. package/dist-server/service/routing/routing-type.js +81 -0
  39. package/dist-server/service/routing/routing-type.js.map +1 -0
  40. package/dist-server/service/routing/routing.js +107 -0
  41. package/dist-server/service/routing/routing.js.map +1 -0
  42. package/dist-server/service/routing-item/index.js +9 -0
  43. package/dist-server/service/routing-item/index.js.map +1 -0
  44. package/dist-server/service/routing-item/routing-item-mutation.js +120 -0
  45. package/dist-server/service/routing-item/routing-item-mutation.js.map +1 -0
  46. package/dist-server/service/routing-item/routing-item-query.js +88 -0
  47. package/dist-server/service/routing-item/routing-item-query.js.map +1 -0
  48. package/dist-server/service/routing-item/routing-item-type.js +107 -0
  49. package/dist-server/service/routing-item/routing-item-type.js.map +1 -0
  50. package/dist-server/service/routing-item/routing-item.js +136 -0
  51. package/dist-server/service/routing-item/routing-item.js.map +1 -0
  52. package/package.json +30 -0
  53. package/server/controllers/index.ts +0 -0
  54. package/server/index.ts +5 -0
  55. package/server/middlewares/index.ts +3 -0
  56. package/server/migrations/index.ts +9 -0
  57. package/server/routes.ts +28 -0
  58. package/server/service/index.ts +28 -0
  59. package/server/service/operation/index.ts +6 -0
  60. package/server/service/operation/operation-mutation.ts +109 -0
  61. package/server/service/operation/operation-query.ts +43 -0
  62. package/server/service/operation/operation-type.ts +66 -0
  63. package/server/service/operation/operation.ts +111 -0
  64. package/server/service/routing/index.ts +6 -0
  65. package/server/service/routing/routing-mutation.ts +112 -0
  66. package/server/service/routing/routing-query.ts +211 -0
  67. package/server/service/routing/routing-type.ts +48 -0
  68. package/server/service/routing/routing.ts +88 -0
  69. package/server/service/routing-item/index.ts +6 -0
  70. package/server/service/routing-item/routing-item-mutation.ts +119 -0
  71. package/server/service/routing-item/routing-item-query.ts +61 -0
  72. package/server/service/routing-item/routing-item-type.ts +67 -0
  73. package/server/service/routing-item/routing-item.ts +118 -0
  74. package/things-factory.config.js +5 -0
  75. package/translations/en.json +1 -0
  76. package/translations/ko.json +1 -0
  77. package/translations/ms.json +1 -0
  78. package/translations/zh.json +1 -0
  79. package/tsconfig.json +9 -0
@@ -0,0 +1,211 @@
1
+ import {
2
+ Arg,
3
+ Args,
4
+ Ctx,
5
+ FieldResolver,
6
+ Query,
7
+ Resolver,
8
+ Root
9
+ } from 'type-graphql'
10
+ import { getRepository } from 'typeorm'
11
+
12
+ import { User } from '@things-factory/auth-base'
13
+ import {
14
+ convertListParams,
15
+ Domain,
16
+ ListParam
17
+ } from '@things-factory/shell'
18
+
19
+ import { Operation } from '../operation/operation'
20
+ import { Routing } from './routing'
21
+ import { RoutingList } from './routing-type'
22
+
23
+ @Resolver(Routing)
24
+ export class RoutingQuery {
25
+ @Query(returns => Routing, { description: 'To fetch a Routing' })
26
+ async routing(@Arg('id') id: string, @Ctx() context: any): Promise<Routing> {
27
+ const { domain } = context.state
28
+
29
+ return await getRepository(Routing).findOne({
30
+ where: { domain, name }
31
+ })
32
+ }
33
+
34
+ @Query(returns => RoutingList, { description: 'To fetch multiple Routings' })
35
+ async routings(@Args() params: ListParam, @Ctx() context: any): Promise<RoutingList> {
36
+ const { domain } = context.state
37
+
38
+ const convertedParams = convertListParams(params, domain.id)
39
+ const [items, total] = await getRepository(Routing).findAndCount(convertedParams)
40
+
41
+ return { items, total }
42
+ }
43
+
44
+ @FieldResolver(type => Domain)
45
+ async domain(@Root() routing: Routing): Promise<Domain> {
46
+ return await getRepository(Domain).findOne(routing.domainId)
47
+ }
48
+
49
+ @FieldResolver(type => User)
50
+ async updater(@Root() routing: Routing): Promise<User> {
51
+ return await getRepository(User).findOne(routing.updaterId)
52
+ }
53
+
54
+ @FieldResolver(type => User)
55
+ async creator(@Root() routing: Routing): Promise<User> {
56
+ return await getRepository(User).findOne(routing.creatorId)
57
+ }
58
+ }
59
+
60
+ export async function firstOperation(routingId: string, context: any): Promise<Operation> {
61
+ const operation = await getRepository(Operation).query(
62
+ `
63
+ select
64
+ *
65
+ from
66
+ operations
67
+ where
68
+ id =
69
+ (
70
+ select
71
+ operation_id
72
+ from
73
+ routing_items
74
+ where
75
+ routing_id = '${routingId}'
76
+ and
77
+ rank =
78
+ (
79
+ select
80
+ min(rank)
81
+ from
82
+ routing_items
83
+ where
84
+ routing_id = '${routingId}'
85
+ )
86
+ )
87
+ `
88
+ )
89
+ return operation
90
+ }
91
+
92
+ export async function nextOperation(operationId: string, routingId: string, context: any): Promise<Operation> {
93
+ const operation = await getRepository(Operation).query(
94
+ `
95
+ select
96
+ *
97
+ from
98
+ operations
99
+ where
100
+ id =
101
+ (
102
+ select
103
+ operation_id
104
+ from
105
+ routing_items
106
+ where
107
+ routing_id = '${routingId}'
108
+ and
109
+ rank =
110
+ (
111
+ select
112
+ min(rank)
113
+ from
114
+ routing_items
115
+ where
116
+ routing_id = '${routingId}'
117
+ and
118
+ rank >
119
+ (
120
+ select
121
+ rank
122
+ from
123
+ routing_items
124
+ where
125
+ routing_id = '${routingId}'
126
+ and
127
+ operation_id = '${operationId}'
128
+ )
129
+ )
130
+ )
131
+ `
132
+ )
133
+ return operation
134
+ }
135
+
136
+ export async function prevOperation(operationId: string, routingId: string, context: any): Promise<Operation> {
137
+ const operation = await getRepository(Operation).query(
138
+ `
139
+ select
140
+ *
141
+ from
142
+ operations
143
+ where
144
+ id =
145
+ (
146
+ select
147
+ operation_id
148
+ from
149
+ routing_items
150
+ where
151
+ routing_id = '${routingId}'
152
+ and
153
+ rank =
154
+ (
155
+ select
156
+ max(rank)
157
+ from
158
+ routing_items
159
+ where
160
+ routing_id = '${routingId}'
161
+ and
162
+ rank <
163
+ (
164
+ select
165
+ rank
166
+ from
167
+ routing_items
168
+ where
169
+ routing_id = '${routingId}'
170
+ and
171
+ operation_id = '${operationId}'
172
+ )
173
+ )
174
+ )
175
+ `
176
+ )
177
+
178
+ return operation
179
+ }
180
+
181
+ export async function lastOperation(routingId: string, context: any): Promise<Operation> {
182
+ const operation = await getRepository(Operation).query(
183
+ `
184
+ select
185
+ *
186
+ from
187
+ operations
188
+ where
189
+ id =
190
+ (
191
+ select
192
+ operation_id
193
+ from
194
+ routing_items
195
+ where
196
+ routing_id = '${routingId}'
197
+ and
198
+ rank =
199
+ (
200
+ select
201
+ max(rank)
202
+ from
203
+ routing_items
204
+ where
205
+ routing_id = '${routingId}'
206
+ )
207
+ )
208
+ `
209
+ )
210
+ return operation
211
+ }
@@ -0,0 +1,48 @@
1
+ import { ObjectType, Field, InputType, Int, ID, registerEnumType } from 'type-graphql'
2
+
3
+ import { Routing } from './routing'
4
+
5
+ @InputType()
6
+ export class NewRouting {
7
+ @Field({ nullable: false })
8
+ name: string
9
+
10
+ @Field({ nullable: true })
11
+ description?: string
12
+
13
+ @Field({ nullable: true })
14
+ createdLot?: boolean
15
+
16
+ @Field({ nullable: true })
17
+ active?: boolean
18
+ }
19
+
20
+ @InputType()
21
+ export class RoutingPatch {
22
+ @Field(type => ID, { nullable: true })
23
+ id: string
24
+
25
+ @Field({ nullable: true })
26
+ name: string
27
+
28
+ @Field({ nullable: true })
29
+ description?: string
30
+
31
+ @Field({ nullable: true })
32
+ createdLot?: boolean
33
+
34
+ @Field({ nullable: true })
35
+ active?: boolean
36
+
37
+ @Field()
38
+ cuFlag: string
39
+ }
40
+
41
+ @ObjectType()
42
+ export class RoutingList {
43
+ @Field(type => [Routing])
44
+ items: Routing[]
45
+
46
+ @Field(type => Int)
47
+ total: number
48
+ }
@@ -0,0 +1,88 @@
1
+ import {
2
+ CreateDateColumn,
3
+ UpdateDateColumn,
4
+ Entity,
5
+ Index,
6
+ Column,
7
+ RelationId,
8
+ ManyToOne,
9
+ PrimaryGeneratedColumn
10
+ } from 'typeorm'
11
+ import { ObjectType, Field, Int, ID, registerEnumType } from 'type-graphql'
12
+
13
+ import { Domain } from '@things-factory/shell'
14
+ import { User } from '@things-factory/auth-base'
15
+
16
+ export enum RoutingStatus {
17
+ STATUS_A = 'STATUS_A',
18
+ STATUS_B = 'STATUS_B'
19
+ }
20
+
21
+ registerEnumType(RoutingStatus, {
22
+ name: 'RoutingStatus',
23
+ description: 'state enumeration of a routing'
24
+ })
25
+
26
+ @Entity()
27
+ @Index('ix_routing_0', (routing: Routing) => [routing.domain, routing.name], { unique: true })
28
+ @ObjectType({ description: 'Entity for Routing' })
29
+ export class Routing {
30
+ @PrimaryGeneratedColumn('uuid')
31
+ @Field(type => ID, { nullable: false })
32
+ readonly id: string
33
+
34
+ @ManyToOne(type => Domain, { nullable: false })
35
+ @Field({ nullable: false })
36
+ domain?: Domain
37
+
38
+ @RelationId((routing: Routing) => routing.domain)
39
+ domainId?: string
40
+
41
+ @Column({ nullable: false })
42
+ @Field({ nullable: false })
43
+ name: string
44
+
45
+ @Column({
46
+ nullable: true
47
+ })
48
+ @Field({ nullable: true })
49
+ description?: string
50
+
51
+ @Column({
52
+ nullable: true
53
+ })
54
+ @Field({ nullable: true })
55
+ createdLot?: boolean
56
+
57
+ @Column({
58
+ nullable: true
59
+ })
60
+ @Field({ nullable: true })
61
+ active?: boolean
62
+
63
+ @CreateDateColumn()
64
+ @Field({ nullable: true })
65
+ createdAt?: Date
66
+
67
+ @UpdateDateColumn()
68
+ @Field({ nullable: true })
69
+ updatedAt?: Date
70
+
71
+ @ManyToOne(type => User, {
72
+ nullable: true
73
+ })
74
+ @Field({ nullable: true })
75
+ creator?: User
76
+
77
+ @RelationId((routing: Routing) => routing.creator)
78
+ creatorId?: string
79
+
80
+ @ManyToOne(type => User, {
81
+ nullable: true
82
+ })
83
+ @Field({ nullable: true })
84
+ updater?: User
85
+
86
+ @RelationId((routing: Routing) => routing.creator)
87
+ updaterId?: string
88
+ }
@@ -0,0 +1,6 @@
1
+ import { RoutingItem } from './routing-item'
2
+ import { RoutingItemQuery } from './routing-item-query'
3
+ import { RoutingItemMutation } from './routing-item-mutation'
4
+
5
+ export const entities = [RoutingItem]
6
+ export const resolvers = [RoutingItemQuery, RoutingItemMutation]
@@ -0,0 +1,119 @@
1
+ import {
2
+ Arg,
3
+ Ctx,
4
+ Directive,
5
+ Mutation,
6
+ Resolver
7
+ } from 'type-graphql'
8
+ import { In } from 'typeorm'
9
+
10
+ import { RoutingItem } from './routing-item'
11
+ import {
12
+ NewRoutingItem,
13
+ RoutingItemPatch
14
+ } from './routing-item-type'
15
+
16
+ @Resolver(RoutingItem)
17
+ export class RoutingItemMutation {
18
+ @Directive('@transaction')
19
+ @Mutation(returns => RoutingItem, { description: 'To create new RoutingItem' })
20
+ async createRoutingItem(@Arg('routingItem') routingItem: NewRoutingItem, @Ctx() context: any): Promise<RoutingItem> {
21
+ const { domain, user, tx } = context.state
22
+
23
+ return await tx.getRepository(RoutingItem).save({
24
+ ...routingItem,
25
+ domain,
26
+ creator: user,
27
+ updater: user
28
+ })
29
+ }
30
+
31
+ @Directive('@transaction')
32
+ @Mutation(returns => RoutingItem, { description: 'To modify RoutingItem information' })
33
+ async updateRoutingItem(
34
+ @Arg('id') id: string,
35
+ @Arg('patch') patch: RoutingItemPatch,
36
+ @Ctx() context: any
37
+ ): Promise<RoutingItem> {
38
+ const { domain, user, tx } = context.state
39
+
40
+ const repository = tx.getRepository(RoutingItem)
41
+ const routingItem = await repository.findOne({
42
+ where: { domain, id }
43
+ })
44
+
45
+ return await repository.save({
46
+ ...routingItem,
47
+ ...patch,
48
+ updater: user
49
+ })
50
+ }
51
+
52
+ @Directive('@transaction')
53
+ @Mutation(returns => [RoutingItem], { description: "To modify multiple RoutingItems' information" })
54
+ async updateMultipleRoutingItem(
55
+ @Arg('patches', type => [RoutingItemPatch]) patches: RoutingItemPatch[],
56
+ @Ctx() context: any
57
+ ): Promise<RoutingItem[]> {
58
+ const { domain, user, tx } = context.state
59
+
60
+ let results = []
61
+ const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
62
+ const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
63
+ const routingItemRepo = tx.getRepository(RoutingItem)
64
+
65
+ if (_createRecords.length > 0) {
66
+ for (let i = 0; i < _createRecords.length; i++) {
67
+ const newRecord = _createRecords[i]
68
+
69
+ const result = await routingItemRepo.save({
70
+ ...newRecord,
71
+ domain,
72
+ creator: user,
73
+ updater: user
74
+ })
75
+
76
+ results.push({ ...result, cuFlag: '+' })
77
+ }
78
+ }
79
+
80
+ if (_updateRecords.length > 0) {
81
+ for (let i = 0; i < _updateRecords.length; i++) {
82
+ const newRecord = _updateRecords[i]
83
+ const routingItem = await routingItemRepo.findOne(newRecord.id)
84
+
85
+ const result = await routingItemRepo.save({
86
+ ...routingItem,
87
+ ...newRecord,
88
+ updater: user
89
+ })
90
+
91
+ results.push({ ...result, cuFlag: 'M' })
92
+ }
93
+ }
94
+
95
+ return results
96
+ }
97
+
98
+ @Directive('@transaction')
99
+ @Mutation(returns => Boolean, { description: 'To delete RoutingItem' })
100
+ async deleteRoutingItem(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
101
+ const { domain, tx } = context.state
102
+
103
+ await tx.getRepository(RoutingItem).delete({ domain, id })
104
+ return true
105
+ }
106
+
107
+ @Directive('@transaction')
108
+ @Mutation(returns => Boolean, { description: 'To delete multiple routingItems' })
109
+ async deleteRoutingItems(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<boolean> {
110
+ const { domain, tx } = context.state
111
+
112
+ await tx.getRepository(RoutingItem).delete({
113
+ domain,
114
+ id: In(ids)
115
+ })
116
+
117
+ return true
118
+ }
119
+ }
@@ -0,0 +1,61 @@
1
+ import {
2
+ Arg,
3
+ Args,
4
+ Ctx,
5
+ FieldResolver,
6
+ Query,
7
+ Resolver,
8
+ Root
9
+ } from 'type-graphql'
10
+ import { getRepository } from 'typeorm'
11
+
12
+ import { User } from '@things-factory/auth-base'
13
+ import {
14
+ convertListParams,
15
+ Domain,
16
+ ListParam
17
+ } from '@things-factory/shell'
18
+
19
+ import { RoutingItem } from './routing-item'
20
+ import { RoutingItemList } from './routing-item-type'
21
+
22
+ @Resolver(RoutingItem)
23
+ export class RoutingItemQuery {
24
+ @Query(returns => RoutingItem, { description: 'To fetch a RoutingItem' })
25
+ async routingItem(@Arg('routing') routing: string, @Ctx() context: any): Promise<RoutingItem> {
26
+ const { domain } = context.state
27
+
28
+ return await getRepository(RoutingItem).findOne({
29
+ relations: ['routing'],
30
+ where: { domain, routing }
31
+ })
32
+ }
33
+
34
+ @Query(returns => RoutingItemList, { description: 'To fetch multiple RoutingItems' })
35
+ async routingItems(@Args() params: ListParam, @Ctx() context: any): Promise<RoutingItemList> {
36
+ const { domain } = context.state
37
+
38
+ const convertedParams = convertListParams(params, domain.id)
39
+ const [items, total] = await getRepository(RoutingItem).findAndCount({
40
+ ...convertedParams,
41
+ relations: ['routing', 'operation']
42
+ })
43
+
44
+ return { items, total }
45
+ }
46
+
47
+ @FieldResolver(type => Domain)
48
+ async domain(@Root() routingItem: RoutingItem): Promise<Domain> {
49
+ return await getRepository(Domain).findOne(routingItem.domainId)
50
+ }
51
+
52
+ @FieldResolver(type => User)
53
+ async updater(@Root() routingItem: RoutingItem): Promise<User> {
54
+ return await getRepository(User).findOne(routingItem.updaterId)
55
+ }
56
+
57
+ @FieldResolver(type => User)
58
+ async creator(@Root() routingItem: RoutingItem): Promise<User> {
59
+ return await getRepository(User).findOne(routingItem.creatorId)
60
+ }
61
+ }
@@ -0,0 +1,67 @@
1
+ import { ObjectType, Field, InputType, Int, ID, registerEnumType } from 'type-graphql'
2
+ import { ObjectRef } from '@things-factory/shell'
3
+
4
+ import { RoutingItem } from './routing-item'
5
+
6
+ @InputType()
7
+ export class NewRoutingItem {
8
+ @Field(type => ObjectRef, { nullable: true })
9
+ routing: ObjectRef
10
+
11
+ @Field({ nullable: true })
12
+ rank: string
13
+
14
+ @Field(type => ObjectRef, { nullable: true })
15
+ operation: ObjectRef
16
+
17
+ @Field({ nullable: true })
18
+ startedTransaction?: string
19
+
20
+ @Field({ nullable: true })
21
+ isStock?: boolean
22
+
23
+ @Field({ nullable: true })
24
+ operatorViewId?: string
25
+
26
+ @Field({ nullable: true })
27
+ active?: boolean
28
+ }
29
+
30
+ @InputType()
31
+ export class RoutingItemPatch {
32
+ @Field(type => ID, { nullable: true })
33
+ id: string
34
+
35
+ @Field(type => ObjectRef, { nullable: true })
36
+ routing: ObjectRef
37
+
38
+ @Field({ nullable: true })
39
+ rank: string
40
+
41
+ @Field(type => ObjectRef, { nullable: true })
42
+ operation?: ObjectRef
43
+
44
+ @Field({ nullable: true })
45
+ startedTransaction?: string
46
+
47
+ @Field({ nullable: true })
48
+ isStock?: boolean
49
+
50
+ @Field({ nullable: true })
51
+ operatorViewId?: string
52
+
53
+ @Field({ nullable: true })
54
+ active?: boolean
55
+
56
+ @Field()
57
+ cuFlag: string
58
+ }
59
+
60
+ @ObjectType()
61
+ export class RoutingItemList {
62
+ @Field(type => [RoutingItem])
63
+ items: RoutingItem[]
64
+
65
+ @Field(type => Int)
66
+ total: number
67
+ }