@things-factory/routing-base 8.0.5 → 9.0.0-beta.12

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.
@@ -1,213 +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 { Operation } from '../operation/operation'
7
- import { Routing } from './routing'
8
- import { RoutingList } from './routing-type'
9
-
10
- @Resolver(Routing)
11
- export class RoutingQuery {
12
- @Query(returns => Routing, { description: 'To fetch a Routing' })
13
- async routing(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Routing> {
14
- const { domain } = context.state
15
-
16
- return await getRepository(Routing).findOne({
17
- where: { domain: { id: domain.id }, id }
18
- })
19
- }
20
-
21
- @Query(returns => RoutingList, { description: 'To fetch multiple Routings' })
22
- async routings(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<RoutingList> {
23
- const { domain } = context.state
24
-
25
- const queryBuilder = getQueryBuilderFromListParams({
26
- repository: getRepository(Routing),
27
- params,
28
- domain,
29
- searchables: ['name']
30
- })
31
-
32
- const [items, total] = await queryBuilder.getManyAndCount()
33
-
34
- return { items, total }
35
- }
36
-
37
- @FieldResolver(type => Domain)
38
- async domain(@Root() routing: Routing): Promise<Domain> {
39
- return await getRepository(Domain).findOneBy({ id: routing.domainId })
40
- }
41
-
42
- @FieldResolver(type => User)
43
- async updater(@Root() routing: Routing): Promise<User> {
44
- return await getRepository(User).findOneBy({ id: routing.updaterId })
45
- }
46
-
47
- @FieldResolver(type => User)
48
- async creator(@Root() routing: Routing): Promise<User> {
49
- return await getRepository(User).findOneBy({ id: routing.creatorId })
50
- }
51
- }
52
-
53
- export async function firstOperation(routingId: string, context: ResolverContext): Promise<Operation> {
54
- const { domain, user, tx } = context.state
55
- const operation: Operation = await tx.getRepository(Operation).query(
56
- `
57
- select
58
- *
59
- from
60
- operations
61
- where
62
- id =
63
- (
64
- select
65
- operation_id
66
- from
67
- routing_items
68
- where
69
- routing_id = '${routingId}'
70
- and
71
- rank =
72
- (
73
- select
74
- min(rank)
75
- from
76
- routing_items
77
- where
78
- routing_id = '${routingId}'
79
- )
80
- )
81
- `
82
- )
83
- return operation
84
- }
85
-
86
- export async function nextOperation(
87
- operationId: string,
88
- routingId: string,
89
- context: ResolverContext
90
- ): Promise<Operation> {
91
- const operation = await getRepository(Operation).query(
92
- `
93
- select
94
- *
95
- from
96
- operations
97
- where
98
- id =
99
- (
100
- select
101
- operation_id
102
- from
103
- routing_items
104
- where
105
- routing_id = '${routingId}'
106
- and
107
- rank =
108
- (
109
- select
110
- min(rank)
111
- from
112
- routing_items
113
- where
114
- routing_id = '${routingId}'
115
- and
116
- rank >
117
- (
118
- select
119
- rank
120
- from
121
- routing_items
122
- where
123
- routing_id = '${routingId}'
124
- and
125
- operation_id = '${operationId}'
126
- )
127
- )
128
- )
129
- `
130
- )
131
- return operation
132
- }
133
-
134
- export async function prevOperation(
135
- operationId: string,
136
- routingId: string,
137
- context: ResolverContext
138
- ): Promise<Operation> {
139
- const operation = await getRepository(Operation).query(
140
- `
141
- select
142
- *
143
- from
144
- operations
145
- where
146
- id =
147
- (
148
- select
149
- operation_id
150
- from
151
- routing_items
152
- where
153
- routing_id = '${routingId}'
154
- and
155
- rank =
156
- (
157
- select
158
- max(rank)
159
- from
160
- routing_items
161
- where
162
- routing_id = '${routingId}'
163
- and
164
- rank <
165
- (
166
- select
167
- rank
168
- from
169
- routing_items
170
- where
171
- routing_id = '${routingId}'
172
- and
173
- operation_id = '${operationId}'
174
- )
175
- )
176
- )
177
- `
178
- )
179
-
180
- return operation
181
- }
182
-
183
- export async function lastOperation(routingId: string, context: ResolverContext): Promise<Operation> {
184
- const operation = await getRepository(Operation).query(
185
- `
186
- select
187
- *
188
- from
189
- operations
190
- where
191
- id =
192
- (
193
- select
194
- operation_id
195
- from
196
- routing_items
197
- where
198
- routing_id = '${routingId}'
199
- and
200
- rank =
201
- (
202
- select
203
- max(rank)
204
- from
205
- routing_items
206
- where
207
- routing_id = '${routingId}'
208
- )
209
- )
210
- `
211
- )
212
- return operation
213
- }
@@ -1,48 +0,0 @@
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
- }
@@ -1,88 +0,0 @@
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(type => User, { 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(type => User, { nullable: true })
84
- updater?: User
85
-
86
- @RelationId((routing: Routing) => routing.updater)
87
- updaterId?: string
88
- }
@@ -1,9 +0,0 @@
1
- import { RoutingItem } from './routing-item'
2
- import { RoutingItemMutation } from './routing-item-mutation'
3
- import { RoutingItemQuery } from './routing-item-query'
4
-
5
- export const entities = [RoutingItem]
6
- export const resolvers = [RoutingItemQuery, RoutingItemMutation]
7
-
8
- export * from './routing-item-query'
9
- export * from './routing-item-mutation'
@@ -1,126 +0,0 @@
1
- import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
- import { In } from 'typeorm'
3
- import { Routing } from '../routing/routing'
4
-
5
- import { RoutingItem } from './routing-item'
6
- import { NewRoutingItem, RoutingItemPatch } from './routing-item-type'
7
-
8
- @Resolver(RoutingItem)
9
- export class RoutingItemMutation {
10
- @Directive('@transaction')
11
- @Mutation(returns => RoutingItem, { description: 'To create new RoutingItem' })
12
- async createRoutingItem(
13
- @Arg('routingItem') routingItem: NewRoutingItem,
14
- @Ctx() context: ResolverContext
15
- ): Promise<RoutingItem> {
16
- const { domain, user, tx } = context.state
17
- const routing = await tx
18
- .getRepository(Routing)
19
- .findOne({ where: { domain: { id: domain.id }, id: routingItem.routingId } })
20
-
21
- return await tx.getRepository(RoutingItem).save({
22
- ...routingItem,
23
- routing,
24
- domain,
25
- creator: user,
26
- updater: user
27
- })
28
- }
29
-
30
- @Directive('@transaction')
31
- @Mutation(returns => RoutingItem, { description: 'To modify RoutingItem information' })
32
- async updateRoutingItem(
33
- @Arg('id') id: string,
34
- @Arg('patch') patch: RoutingItemPatch,
35
- @Ctx() context: ResolverContext
36
- ): Promise<RoutingItem> {
37
- const { domain, user, tx } = context.state
38
-
39
- const repository = tx.getRepository(RoutingItem)
40
- const routingItem = await repository.findOne({
41
- where: { domain: { id: domain.id }, id },
42
- relations: ['routing']
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: ResolverContext
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
- const routing = await tx
69
- .getRepository(Routing)
70
- .findOne({ where: { domain: { id: domain.id }, id: _createRecords[i].routingId } })
71
-
72
- const result = await routingItemRepo.save({
73
- ...newRecord,
74
- routing,
75
- domain,
76
- creator: user,
77
- updater: user
78
- })
79
-
80
- results.push({ ...result, cuFlag: '+' })
81
- }
82
- }
83
-
84
- if (_updateRecords.length > 0) {
85
- for (let i = 0; i < _updateRecords.length; i++) {
86
- const newRecord = _updateRecords[i]
87
- const routingItem = await routingItemRepo.findOneBy({ id: newRecord.id })
88
-
89
- const result = await routingItemRepo.save({
90
- ...routingItem,
91
- ...newRecord,
92
- updater: user
93
- })
94
-
95
- results.push({ ...result, cuFlag: 'M' })
96
- }
97
- }
98
-
99
- return results
100
- }
101
-
102
- @Directive('@transaction')
103
- @Mutation(returns => Boolean, { description: 'To delete RoutingItem' })
104
- async deleteRoutingItem(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
105
- const { domain, tx } = context.state
106
-
107
- await tx.getRepository(RoutingItem).delete({ domain: { id: domain.id }, id })
108
- return true
109
- }
110
-
111
- @Directive('@transaction')
112
- @Mutation(returns => Boolean, { description: 'To delete multiple routingItems' })
113
- async deleteRoutingItems(
114
- @Arg('ids', type => [String]) ids: string[],
115
- @Ctx() context: ResolverContext
116
- ): Promise<boolean> {
117
- const { domain, tx } = context.state
118
-
119
- await tx.getRepository(RoutingItem).delete({
120
- domain: { id: domain.id },
121
- id: In(ids)
122
- })
123
-
124
- return true
125
- }
126
- }
@@ -1,60 +0,0 @@
1
- import { 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 { Operation } from '../operation/operation'
7
- import { Routing } from '../routing/routing'
8
- import { RoutingItem } from './routing-item'
9
- import { RoutingItemList } from './routing-item-type'
10
-
11
- @Resolver(RoutingItem)
12
- export class RoutingItemQuery {
13
- @Query(returns => RoutingItemList, { description: 'To fetch multiple RoutingItems' })
14
- async routingItems(
15
- @Args(type => ListParam) params: ListParam,
16
- @Ctx() context: ResolverContext
17
- ): Promise<RoutingItemList> {
18
- const { domain } = context.state
19
-
20
- const queryBuilder = getQueryBuilderFromListParams({
21
- repository: getRepository(RoutingItem),
22
- params,
23
- domain,
24
- alias: 'ri',
25
- searchables: ['name', 'description']
26
- })
27
-
28
- const [items, total] = await queryBuilder
29
- .leftJoinAndSelect('ri.routing', 'routing')
30
- .leftJoinAndSelect('ri.operation', 'operation')
31
- .getManyAndCount()
32
-
33
- return { items, total }
34
- }
35
-
36
- @FieldResolver(type => Routing)
37
- async routing(@Root() routingItem: RoutingItem): Promise<Routing> {
38
- return routingItem.routing || (await getRepository(Routing).findOneBy({ id: routingItem.routingId }))
39
- }
40
-
41
- @FieldResolver(type => Operation)
42
- async operation(@Root() routingItem: RoutingItem): Promise<Operation> {
43
- return routingItem.operation || (await getRepository(Operation).findOneBy({ id: routingItem.operationId }))
44
- }
45
-
46
- @FieldResolver(type => Domain)
47
- async domain(@Root() routingItem: RoutingItem): Promise<Domain> {
48
- return await getRepository(Domain).findOneBy({ id: routingItem.domainId })
49
- }
50
-
51
- @FieldResolver(type => User)
52
- async updater(@Root() routingItem: RoutingItem): Promise<User> {
53
- return await getRepository(User).findOneBy({ id: routingItem.updaterId })
54
- }
55
-
56
- @FieldResolver(type => User)
57
- async creator(@Root() routingItem: RoutingItem): Promise<User> {
58
- return await getRepository(User).findOneBy({ id: routingItem.creatorId })
59
- }
60
- }
@@ -1,67 +0,0 @@
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({ nullable: true })
9
- routingId?: string
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({ nullable: true })
36
- routingId?: string
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
- }