@things-factory/routing-base 8.0.0-beta.9 → 8.0.0

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.9",
3
+ "version": "8.0.0",
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.9",
27
- "@things-factory/auth-base": "^8.0.0-beta.9",
28
- "@things-factory/shell": "^8.0.0-beta.9"
26
+ "@things-factory/attachment-base": "^8.0.0",
27
+ "@things-factory/auth-base": "^8.0.0",
28
+ "@things-factory/shell": "^8.0.0"
29
29
  },
30
- "gitHead": "86b1dfa26292926a2d5447fdc23bfa5a9e983245"
30
+ "gitHead": "07ef27d272dd9a067a9648ac7013748510556a18"
31
31
  }
@@ -0,0 +1 @@
1
+ export * from './service'
@@ -0,0 +1,43 @@
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
+ }
@@ -0,0 +1,9 @@
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'
@@ -0,0 +1,185 @@
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
+ }
@@ -0,0 +1,66 @@
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
+ }
@@ -0,0 +1,68 @@
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
+ }
@@ -0,0 +1,109 @@
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
+ }
@@ -0,0 +1,9 @@
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'
@@ -0,0 +1,110 @@
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
+ }