@things-factory/routing-base 8.0.0-beta.1 → 8.0.0-beta.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/routing-base",
3
- "version": "8.0.0-beta.1",
3
+ "version": "8.0.0-beta.2",
4
4
  "main": "dist-server/index.js",
5
5
  "things-factory": true,
6
6
  "author": "",
@@ -23,9 +23,9 @@
23
23
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create ./server/migrations/migration"
24
24
  },
25
25
  "dependencies": {
26
- "@things-factory/attachment-base": "^8.0.0-beta.1",
27
- "@things-factory/auth-base": "^8.0.0-beta.1",
28
- "@things-factory/shell": "^8.0.0-beta.1"
26
+ "@things-factory/attachment-base": "^8.0.0-beta.2",
27
+ "@things-factory/auth-base": "^8.0.0-beta.2",
28
+ "@things-factory/shell": "^8.0.0-beta.2"
29
29
  },
30
- "gitHead": "36c494e587640c1490318ef7b95adab02606e0c2"
30
+ "gitHead": "f03431a09435511b2595515658f9cb8f78ba4ebb"
31
31
  }
package/server/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './service'
@@ -1,43 +0,0 @@
1
- import {
2
- entities as OperationEntities,
3
- resolvers as OperationResolvers
4
- } from './operation'
5
- import {
6
- entities as RoutingEntities,
7
- resolvers as RoutingResolvers
8
- } from './routing'
9
- import {
10
- entities as RoutingItemEntities,
11
- resolvers as RoutingItemResolvers
12
- } from './routing-item'
13
-
14
- /* EXPORT ENTITY TYPES */
15
- export * from './routing/routing'
16
- export * from './routing-item/routing-item'
17
- export * from './operation/operation'
18
-
19
- /* EXPORT TYPES */
20
- export * from './routing/routing-type'
21
- export * from './operation/operation-type'
22
- export * from './routing-item/routing-item-type'
23
-
24
- /* EXPORT MUTAIONS */
25
- export * from './routing/routing-mutation'
26
- export * from './operation/operation-mutation'
27
- export * from './routing-item/routing-item-mutation'
28
-
29
- /* EXPORT QUERIES */
30
- export * from './routing/routing-query'
31
- export * from './operation/operation-query'
32
- export * from './routing-item/routing-item-query'
33
-
34
- export const entities = [
35
- /* ENTITIES */
36
- ...RoutingEntities,
37
- ...RoutingItemEntities,
38
- ...OperationEntities
39
- ]
40
-
41
- export const schema = {
42
- resolverClasses: [...RoutingResolvers, ...RoutingItemResolvers, ...OperationResolvers]
43
- }
@@ -1,9 +0,0 @@
1
- import { Operation } from './operation'
2
- import { OperationMutation } from './operation-mutation'
3
- import { OperationQuery } from './operation-query'
4
-
5
- export const entities = [Operation]
6
- export const resolvers = [OperationQuery, OperationMutation]
7
-
8
- export * from './operation-query'
9
- export * from './operation-mutation'
@@ -1,185 +0,0 @@
1
- import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
- import { In } from 'typeorm'
3
-
4
- import { createAttachment, deleteAttachmentsByRef } from '@things-factory/attachment-base'
5
-
6
- import { Operation } from './operation'
7
- import { NewOperation, OperationPatch } from './operation-type'
8
-
9
- @Resolver(Operation)
10
- export class OperationMutation {
11
- @Directive('@transaction')
12
- @Mutation(returns => Operation, { description: 'To create new Operation' })
13
- async createOperation(
14
- @Arg('operation') operation: NewOperation,
15
- @Ctx() context: ResolverContext
16
- ): Promise<Operation> {
17
- const { domain, user, tx } = context.state
18
-
19
- const result = await tx.getRepository(Operation).save({
20
- ...operation,
21
- domain,
22
- creator: user,
23
- updater: user
24
- })
25
-
26
- if (operation.thumbnail) {
27
- await createAttachment(
28
- null,
29
- {
30
- attachment: {
31
- file: operation.thumbnail,
32
- refType: Operation.name,
33
- refBy: result.id
34
- }
35
- },
36
- context
37
- )
38
- }
39
-
40
- return result
41
- }
42
-
43
- @Directive('@transaction')
44
- @Mutation(returns => Operation, { description: 'To modify Operation information' })
45
- async updateOperation(
46
- @Arg('id') id: string,
47
- @Arg('patch') patch: OperationPatch,
48
- @Ctx() context: ResolverContext
49
- ): Promise<Operation> {
50
- const { domain, user, tx } = context.state
51
-
52
- const repository = tx.getRepository(Operation)
53
- const operation = await repository.findOne({
54
- where: { domain: { id: domain.id }, id }
55
- })
56
-
57
- const result = await repository.save({
58
- ...operation,
59
- ...patch,
60
- updater: user
61
- })
62
-
63
- if (patch.thumbnail) {
64
- // ?? { refBys: [operation.id] }
65
- await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)
66
- await createAttachment(
67
- null,
68
- {
69
- attachment: {
70
- file: patch.thumbnail,
71
- refType: Operation.name,
72
- refBy: result.id
73
- }
74
- },
75
- context
76
- )
77
- }
78
-
79
- return result
80
- }
81
-
82
- @Directive('@transaction')
83
- @Mutation(returns => [Operation], { description: "To modify multiple Operations' information" })
84
- async updateMultipleOperation(
85
- @Arg('patches', type => [OperationPatch]) patches: OperationPatch[],
86
- @Ctx() context: ResolverContext
87
- ): Promise<Operation[]> {
88
- const { domain, user, tx } = context.state
89
-
90
- let results = []
91
- const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
92
- const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
93
- const operationRepo = tx.getRepository(Operation)
94
-
95
- if (_createRecords.length > 0) {
96
- for (let i = 0; i < _createRecords.length; i++) {
97
- const newRecord = _createRecords[i]
98
-
99
- const result = await operationRepo.save({
100
- ...newRecord,
101
- domain,
102
- creator: user,
103
- updater: user
104
- })
105
-
106
- if (newRecord.thumbnail) {
107
- await createAttachment(
108
- null,
109
- {
110
- attachment: {
111
- file: newRecord.thumbnail,
112
- refType: Operation.name,
113
- refBy: result.id
114
- }
115
- },
116
- context
117
- )
118
- }
119
-
120
- results.push({ ...result, cuFlag: '+' })
121
- }
122
- }
123
-
124
- if (_updateRecords.length > 0) {
125
- for (let i = 0; i < _updateRecords.length; i++) {
126
- const newRecord = _updateRecords[i]
127
- const operation = await operationRepo.findOneBy({ id: newRecord.id })
128
-
129
- const result = await operationRepo.save({
130
- ...operation,
131
- ...newRecord,
132
- updater: user
133
- })
134
-
135
- if (newRecord.thumbnail) {
136
- await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)
137
- await createAttachment(
138
- null,
139
- {
140
- attachment: {
141
- file: newRecord.thumbnail,
142
- refType: Operation.name,
143
- refBy: result.id
144
- }
145
- },
146
- context
147
- )
148
- }
149
-
150
- results.push({ ...result, cuFlag: 'M' })
151
- }
152
- }
153
-
154
- return results
155
- }
156
-
157
- @Directive('@transaction')
158
- @Mutation(returns => Boolean, { description: 'To delete Operation' })
159
- async deleteOperation(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
160
- const { domain, tx } = context.state
161
-
162
- await tx.getRepository(Operation).delete({ domain: { id: domain.id }, id })
163
- await deleteAttachmentsByRef(null, { refBys: [id] }, context)
164
-
165
- return true
166
- }
167
-
168
- @Directive('@transaction')
169
- @Mutation(returns => Boolean, { description: 'To delete multiple operations' })
170
- async deleteOperations(
171
- @Arg('ids', type => [String]) ids: string[],
172
- @Ctx() context: ResolverContext
173
- ): Promise<boolean> {
174
- const { domain, tx } = context.state
175
-
176
- await tx.getRepository(Operation).delete({
177
- domain: { id: domain.id },
178
- id: In(ids)
179
- })
180
-
181
- await deleteAttachmentsByRef(null, { refBys: ids }, context)
182
-
183
- return true
184
- }
185
- }
@@ -1,66 +0,0 @@
1
- import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
2
-
3
- import { Attachment } from '@things-factory/attachment-base'
4
- import { User } from '@things-factory/auth-base'
5
- import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
6
-
7
- import { Operation } from './operation'
8
- import { OperationList } from './operation-type'
9
-
10
- @Resolver(Operation)
11
- export class OperationQuery {
12
- @Query(returns => Operation, { description: 'To fetch a Operation' })
13
- async operation(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Operation> {
14
- const { domain } = context.state
15
-
16
- return await getRepository(Operation).findOne({
17
- where: { domain: { id: domain.id }, id }
18
- })
19
- }
20
-
21
- @Query(returns => OperationList, { description: 'To fetch multiple Operations' })
22
- async operations(
23
- @Args(type => ListParam) params: ListParam,
24
- @Ctx() context: ResolverContext
25
- ): Promise<OperationList> {
26
- const { domain } = context.state
27
-
28
- const queryBuilder = getQueryBuilderFromListParams({
29
- repository: getRepository(Operation),
30
- params,
31
- domain,
32
- searchables: ['name', 'description']
33
- })
34
-
35
- const [items, total] = await queryBuilder.getManyAndCount()
36
-
37
- return { items, total }
38
- }
39
-
40
- @FieldResolver(type => Domain)
41
- async domain(@Root() operation: Operation): Promise<Domain> {
42
- return await getRepository(Domain).findOneBy({ id: operation.domainId })
43
- }
44
-
45
- @FieldResolver(type => User)
46
- async updater(@Root() operation: Operation): Promise<User> {
47
- return await getRepository(User).findOneBy({ id: operation.updaterId })
48
- }
49
-
50
- @FieldResolver(type => User)
51
- async creator(@Root() operation: Operation): Promise<User> {
52
- return await getRepository(User).findOneBy({ id: operation.creatorId })
53
- }
54
-
55
- @FieldResolver(type => String)
56
- async thumbnail(@Root() operation: Operation): Promise<string | undefined> {
57
- const attachment: Attachment = await getRepository(Attachment).findOne({
58
- where: {
59
- domain: { id: operation.domainId },
60
- refBy: operation.id
61
- }
62
- })
63
-
64
- return attachment?.fullpath
65
- }
66
- }
@@ -1,68 +0,0 @@
1
- import type { FileUpload } from 'graphql-upload/GraphQLUpload.js'
2
- import GraphQLUpload from 'graphql-upload/GraphQLUpload.js'
3
- import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
4
-
5
- import { Operation } from './operation'
6
-
7
- @InputType()
8
- export class NewOperation {
9
- @Field({ nullable: false })
10
- name: string
11
-
12
- @Field({ nullable: true })
13
- description?: string
14
-
15
- @Field({ nullable: true })
16
- type?: string
17
-
18
- @Field({ nullable: true })
19
- operationStdChart?: string
20
-
21
- @Field({ nullable: true })
22
- operationStdTime?: string
23
-
24
- @Field({ nullable: true })
25
- active?: boolean
26
-
27
- @Field(type => GraphQLUpload, { nullable: true })
28
- thumbnail?: FileUpload
29
- }
30
-
31
- @InputType()
32
- export class OperationPatch {
33
- @Field(type => ID, { nullable: true })
34
- id!: string
35
-
36
- @Field({ nullable: true })
37
- name: string
38
-
39
- @Field({ nullable: true })
40
- description?: string
41
-
42
- @Field({ nullable: true })
43
- type?: string
44
-
45
- @Field({ nullable: true })
46
- operationStdChart?: string
47
-
48
- @Field({ nullable: true })
49
- operationStdTime?: string
50
-
51
- @Field({ nullable: true })
52
- active?: boolean
53
-
54
- @Field(type => GraphQLUpload, { nullable: true })
55
- thumbnail?: FileUpload
56
-
57
- @Field()
58
- cuFlag: string
59
- }
60
-
61
- @ObjectType()
62
- export class OperationList {
63
- @Field(type => [Operation])
64
- items: Operation[]
65
-
66
- @Field(type => Int)
67
- total: number
68
- }
@@ -1,109 +0,0 @@
1
- import { Field, ID, ObjectType, registerEnumType } 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 { Domain } from '@things-factory/shell'
15
-
16
- export enum OperationStatus {
17
- STATUS_A = 'STATUS_A',
18
- STATUS_B = 'STATUS_B',
19
- ASSY = 'Assembly',
20
- INV = 'Inventory',
21
- PACK = 'Packing',
22
- SMT = 'SMT',
23
- STD = 'Standard',
24
- TEST = 'Test'
25
- }
26
-
27
- registerEnumType(OperationStatus, {
28
- name: 'OperationStatus',
29
- description: 'state enumeration of a operation'
30
- })
31
-
32
- @Entity()
33
- @Index('ix_operation_0', (operation: Operation) => [operation.domain, operation.name], { unique: true })
34
- @ObjectType({ description: 'Entity for Operation' })
35
- export class Operation {
36
- @PrimaryGeneratedColumn('uuid')
37
- @Field(type => ID, { nullable: false })
38
- readonly id: string
39
-
40
- @ManyToOne(type => Domain)
41
- @Field(type => Domain, { nullable: false })
42
- domain: Domain
43
-
44
- @RelationId((operation: Operation) => operation.domain)
45
- domainId: string
46
-
47
- @Column()
48
- @Field({ nullable: false })
49
- name: string
50
-
51
- @Column({
52
- nullable: true
53
- })
54
- @Field({ nullable: true })
55
- description?: string
56
-
57
- @Column({
58
- nullable: true
59
- })
60
- @Field({ nullable: true })
61
- type?: string
62
-
63
- @Column({
64
- nullable: true
65
- })
66
- @Field({ nullable: true })
67
- operationStdChart?: string
68
-
69
- @Column({
70
- nullable: true
71
- })
72
- @Field({ nullable: true })
73
- operationStdTime?: string
74
-
75
- @Column({
76
- nullable: true
77
- })
78
- @Field({ nullable: true })
79
- active?: boolean
80
-
81
- @Field(type => String, { nullable: true })
82
- thumbnail?: string
83
-
84
- @ManyToOne(type => User, {
85
- nullable: true
86
- })
87
- @Field(type => User, { nullable: true })
88
- creator?: User
89
-
90
- @RelationId((operation: Operation) => operation.creator)
91
- creatorId?: string
92
-
93
- @ManyToOne(type => User, {
94
- nullable: true
95
- })
96
- @Field(type => User, { nullable: true })
97
- updater?: User
98
-
99
- @RelationId((operation: Operation) => operation.updater)
100
- updaterId?: string
101
-
102
- @CreateDateColumn()
103
- @Field({ nullable: true })
104
- createdAt?: Date
105
-
106
- @UpdateDateColumn()
107
- @Field({ nullable: true })
108
- updatedAt?: Date
109
- }
@@ -1,9 +0,0 @@
1
- import { Routing } from './routing'
2
- import { RoutingMutation } from './routing-mutation'
3
- import { RoutingQuery } from './routing-query'
4
-
5
- export const entities = [Routing]
6
- export const resolvers = [RoutingQuery, RoutingMutation]
7
-
8
- export * from './routing-query'
9
- export * from './routing-mutation'
@@ -1,110 +0,0 @@
1
- import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
- import { In } from 'typeorm'
3
-
4
- import { Routing } from './routing'
5
- import { NewRouting, RoutingPatch } from './routing-type'
6
-
7
- @Resolver(Routing)
8
- export class RoutingMutation {
9
- @Directive('@transaction')
10
- @Mutation(returns => Routing, { description: 'To create new Routing' })
11
- async createRouting(@Arg('routing') routing: NewRouting, @Ctx() context: ResolverContext): Promise<Routing> {
12
- const { domain, user, tx } = context.state
13
-
14
- return await tx.getRepository(Routing).save({
15
- ...routing,
16
- domain,
17
- creator: user,
18
- updater: user
19
- })
20
- }
21
-
22
- @Directive('@transaction')
23
- @Mutation(returns => Routing, { description: 'To modify Routing information' })
24
- async updateRouting(
25
- @Arg('id') id: string,
26
- @Arg('patch') patch: RoutingPatch,
27
- @Ctx() context: ResolverContext
28
- ): Promise<Routing> {
29
- const { domain, user, tx } = context.state
30
-
31
- const repository = tx.getRepository(Routing)
32
- const routing = await repository.findOne({
33
- where: { domain: { id: domain.id }, id }
34
- })
35
-
36
- return await repository.save({
37
- ...routing,
38
- ...patch,
39
- updater: user
40
- })
41
- }
42
-
43
- @Directive('@transaction')
44
- @Mutation(returns => [Routing], { description: "To modify multiple Routings' information" })
45
- async updateMultipleRouting(
46
- @Arg('patches', type => [RoutingPatch]) patches: RoutingPatch[],
47
- @Ctx() context: ResolverContext
48
- ): Promise<Routing[]> {
49
- const { domain, user, tx } = context.state
50
-
51
- let results = []
52
- const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
53
- const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
54
- const routingRepo = tx.getRepository(Routing)
55
-
56
- if (_createRecords.length > 0) {
57
- for (let i = 0; i < _createRecords.length; i++) {
58
- const newRecord = _createRecords[i]
59
-
60
- const result = await routingRepo.save({
61
- ...newRecord,
62
- domain,
63
- creator: user,
64
- updater: user
65
- })
66
-
67
- results.push({ ...result, cuFlag: '+' })
68
- }
69
- }
70
-
71
- if (_updateRecords.length > 0) {
72
- for (let i = 0; i < _updateRecords.length; i++) {
73
- const newRecord = _updateRecords[i]
74
- const routing = await routingRepo.findOneBy({ id: newRecord.id })
75
-
76
- const result = await routingRepo.save({
77
- ...routing,
78
- ...newRecord,
79
- updater: user
80
- })
81
-
82
- results.push({ ...result, cuFlag: 'M' })
83
- }
84
- }
85
-
86
- return results
87
- }
88
-
89
- @Directive('@transaction')
90
- @Mutation(returns => Boolean, { description: 'To delete Routing' })
91
- async deleteRouting(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
92
- const { domain, tx } = context.state
93
-
94
- await tx.getRepository(Routing).delete({ domain: { id: domain.id }, id })
95
- return true
96
- }
97
-
98
- @Directive('@transaction')
99
- @Mutation(returns => Boolean, { description: 'To delete multiple routings' })
100
- async deleteRoutings(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<boolean> {
101
- const { domain, tx } = context.state
102
-
103
- await tx.getRepository(Routing).delete({
104
- domain: { id: domain.id },
105
- id: In(ids)
106
- })
107
-
108
- return true
109
- }
110
- }
@@ -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
- }
@@ -1,117 +0,0 @@
1
- import { Field, ID, ObjectType, registerEnumType } 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 { Domain } from '@things-factory/shell'
15
-
16
- import { Operation } from '../operation/operation'
17
- import { Routing } from '../routing/routing'
18
-
19
- export enum RoutingItemStatus {
20
- STATUS_A = 'STATUS_A',
21
- STATUS_B = 'STATUS_B'
22
- }
23
-
24
- registerEnumType(RoutingItemStatus, {
25
- name: 'RoutingItemStatus',
26
- description: 'state enumeration of a routingItem'
27
- })
28
-
29
- @Entity()
30
- @Index(
31
- 'ix_routing_item_0',
32
- (routingItem: RoutingItem) => [routingItem.rank, routingItem.domain, routingItem.routing, routingItem.operation],
33
- { unique: true }
34
- )
35
- @ObjectType({ description: 'Entity for RoutingItem' })
36
- export class RoutingItem {
37
- @PrimaryGeneratedColumn('uuid')
38
- @Field(type => ID, { nullable: false })
39
- readonly id: string
40
-
41
- @ManyToOne(type => Domain, { nullable: false })
42
- @Field({ nullable: false })
43
- domain: Domain
44
-
45
- @RelationId((routingItem: RoutingItem) => routingItem.domain)
46
- domainId: string
47
-
48
- @ManyToOne(type => Routing, { nullable: true })
49
- @Field({ nullable: true })
50
- routing: Routing
51
-
52
- @RelationId((routingItem: RoutingItem) => routingItem.routing)
53
- routingId: string
54
-
55
- @Column({
56
- nullable: false
57
- })
58
- @Field({ nullable: false })
59
- rank: string
60
-
61
- @ManyToOne(type => Operation, { nullable: true })
62
- @Field({ nullable: true })
63
- operation: Operation
64
-
65
- @RelationId((routingItem: RoutingItem) => routingItem.operation)
66
- operationId: string
67
-
68
- @Column({
69
- nullable: true
70
- })
71
- @Field({ nullable: true })
72
- startedTransaction?: string
73
-
74
- @Column({
75
- nullable: true
76
- })
77
- @Field({ nullable: true })
78
- isStock?: boolean
79
-
80
- @Column({
81
- nullable: true
82
- })
83
- @Field({ nullable: true })
84
- operatorViewId?: string
85
-
86
- @Column({
87
- nullable: true
88
- })
89
- @Field({ nullable: true })
90
- active?: boolean
91
-
92
- @CreateDateColumn()
93
- @Field({ nullable: true })
94
- createdAt?: Date
95
-
96
- @UpdateDateColumn()
97
- @Field({ nullable: true })
98
- updatedAt?: Date
99
-
100
- @ManyToOne(type => User, {
101
- nullable: true
102
- })
103
- @Field(type => User, { nullable: true })
104
- creator?: User
105
-
106
- @RelationId((routingItem: RoutingItem) => routingItem.creator)
107
- creatorId?: string
108
-
109
- @ManyToOne(type => User, {
110
- nullable: true
111
- })
112
- @Field(type => User, { nullable: true })
113
- updater?: User
114
-
115
- @RelationId((routingItem: RoutingItem) => routingItem.updater)
116
- updaterId?: string
117
- }
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../tsconfig-base.json",
3
- "compilerOptions": {
4
- "outDir": "./dist-server",
5
- "baseUrl": "./"
6
- },
7
- "include": ["./server/**/*"],
8
- "exclude": ["**/*.spec.ts"]
9
- }