@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.
- package/CHANGELOG.md +8 -0
- package/LICENSE.md +21 -0
- package/client/actions/main.js +1 -0
- package/client/bootstrap.js +8 -0
- package/client/index.js +1 -0
- package/client/reducers/main.js +17 -0
- package/client/themes/app-theme.css +59 -0
- package/config/config.development.js +1 -0
- package/config/config.production.js +1 -0
- package/dist-server/controllers/index.js +1 -0
- package/dist-server/controllers/index.js.map +1 -0
- package/dist-server/index.js +17 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/middlewares/index.js +8 -0
- package/dist-server/middlewares/index.js.map +1 -0
- package/dist-server/migrations/index.js +12 -0
- package/dist-server/migrations/index.js.map +1 -0
- package/dist-server/routes.js +25 -0
- package/dist-server/routes.js.map +1 -0
- package/dist-server/service/index.js +30 -0
- package/dist-server/service/index.js.map +1 -0
- package/dist-server/service/operation/index.js +9 -0
- package/dist-server/service/operation/index.js.map +1 -0
- package/dist-server/service/operation/operation-mutation.js +120 -0
- package/dist-server/service/operation/operation-mutation.js.map +1 -0
- package/dist-server/service/operation/operation-query.js +87 -0
- package/dist-server/service/operation/operation-query.js.map +1 -0
- package/dist-server/service/operation/operation-type.js +97 -0
- package/dist-server/service/operation/operation-type.js.map +1 -0
- package/dist-server/service/operation/operation.js +127 -0
- package/dist-server/service/operation/operation.js.map +1 -0
- package/dist-server/service/routing/index.js +9 -0
- package/dist-server/service/routing/index.js.map +1 -0
- package/dist-server/service/routing/routing-mutation.js +120 -0
- package/dist-server/service/routing/routing-mutation.js.map +1 -0
- package/dist-server/service/routing/routing-query.js +232 -0
- package/dist-server/service/routing/routing-query.js.map +1 -0
- package/dist-server/service/routing/routing-type.js +81 -0
- package/dist-server/service/routing/routing-type.js.map +1 -0
- package/dist-server/service/routing/routing.js +107 -0
- package/dist-server/service/routing/routing.js.map +1 -0
- package/dist-server/service/routing-item/index.js +9 -0
- package/dist-server/service/routing-item/index.js.map +1 -0
- package/dist-server/service/routing-item/routing-item-mutation.js +120 -0
- package/dist-server/service/routing-item/routing-item-mutation.js.map +1 -0
- package/dist-server/service/routing-item/routing-item-query.js +88 -0
- package/dist-server/service/routing-item/routing-item-query.js.map +1 -0
- package/dist-server/service/routing-item/routing-item-type.js +107 -0
- package/dist-server/service/routing-item/routing-item-type.js.map +1 -0
- package/dist-server/service/routing-item/routing-item.js +136 -0
- package/dist-server/service/routing-item/routing-item.js.map +1 -0
- package/package.json +30 -0
- package/server/controllers/index.ts +0 -0
- package/server/index.ts +5 -0
- package/server/middlewares/index.ts +3 -0
- package/server/migrations/index.ts +9 -0
- package/server/routes.ts +28 -0
- package/server/service/index.ts +28 -0
- package/server/service/operation/index.ts +6 -0
- package/server/service/operation/operation-mutation.ts +109 -0
- package/server/service/operation/operation-query.ts +43 -0
- package/server/service/operation/operation-type.ts +66 -0
- package/server/service/operation/operation.ts +111 -0
- package/server/service/routing/index.ts +6 -0
- package/server/service/routing/routing-mutation.ts +112 -0
- package/server/service/routing/routing-query.ts +211 -0
- package/server/service/routing/routing-type.ts +48 -0
- package/server/service/routing/routing.ts +88 -0
- package/server/service/routing-item/index.ts +6 -0
- package/server/service/routing-item/routing-item-mutation.ts +119 -0
- package/server/service/routing-item/routing-item-query.ts +61 -0
- package/server/service/routing-item/routing-item-type.ts +67 -0
- package/server/service/routing-item/routing-item.ts +118 -0
- package/things-factory.config.js +5 -0
- package/translations/en.json +1 -0
- package/translations/ko.json +1 -0
- package/translations/ms.json +1 -0
- package/translations/zh.json +1 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const glob = require('glob')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
|
|
4
|
+
export var migrations = []
|
|
5
|
+
|
|
6
|
+
glob.sync(path.resolve(__dirname, '.', '**', '*.js')).forEach(function(file) {
|
|
7
|
+
if (file.indexOf('index.js') !== -1) return
|
|
8
|
+
migrations = migrations.concat(Object.values(require(path.resolve(file))) || [])
|
|
9
|
+
})
|
package/server/routes.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const debug = require('debug')('operato:routing-base:routes')
|
|
2
|
+
|
|
3
|
+
process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
|
|
4
|
+
/*
|
|
5
|
+
* can add global public routes to application (auth not required, tenancy not required)
|
|
6
|
+
*
|
|
7
|
+
* ex) routes.get('/path', async(context, next) => {})
|
|
8
|
+
* ex) routes.post('/path', async(context, next) => {})
|
|
9
|
+
*/
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
process.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRouter) => {
|
|
13
|
+
/*
|
|
14
|
+
* can add global private routes to application (auth required, tenancy not required)
|
|
15
|
+
*/
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
process.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {
|
|
19
|
+
/*
|
|
20
|
+
* can add domain public routes to application (auth not required, tenancy required)
|
|
21
|
+
*/
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
process.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {
|
|
25
|
+
/*
|
|
26
|
+
* can add domain private routes to application (auth required, tenancy required)
|
|
27
|
+
*/
|
|
28
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
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 const entities = [
|
|
20
|
+
/* ENTITIES */
|
|
21
|
+
...RoutingEntities,
|
|
22
|
+
...RoutingItemEntities,
|
|
23
|
+
...OperationEntities
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
export const schema = {
|
|
27
|
+
resolverClasses: [...RoutingResolvers, ...RoutingItemResolvers, ...OperationResolvers]
|
|
28
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
|
|
2
|
+
import { getRepository, In } from 'typeorm'
|
|
3
|
+
import { Operation } from './operation'
|
|
4
|
+
import { NewOperation, OperationPatch } from './operation-type'
|
|
5
|
+
|
|
6
|
+
@Resolver(Operation)
|
|
7
|
+
export class OperationMutation {
|
|
8
|
+
@Directive('@transaction')
|
|
9
|
+
@Mutation(returns => Operation, { description: 'To create new Operation' })
|
|
10
|
+
async createOperation(@Arg('operation') operation: NewOperation, @Ctx() context: any): Promise<Operation> {
|
|
11
|
+
const { domain, user, tx } = context.state
|
|
12
|
+
|
|
13
|
+
return await tx.getRepository(Operation).save({
|
|
14
|
+
...operation,
|
|
15
|
+
domain,
|
|
16
|
+
creator: user,
|
|
17
|
+
updater: user
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Directive('@transaction')
|
|
22
|
+
@Mutation(returns => Operation, { description: 'To modify Operation information' })
|
|
23
|
+
async updateOperation(
|
|
24
|
+
@Arg('id') id: string,
|
|
25
|
+
@Arg('patch') patch: OperationPatch,
|
|
26
|
+
@Ctx() context: any
|
|
27
|
+
): Promise<Operation> {
|
|
28
|
+
const { domain, user, tx } = context.state
|
|
29
|
+
|
|
30
|
+
const repository = tx.getRepository(Operation)
|
|
31
|
+
const operation = await repository.findOne({
|
|
32
|
+
where: { domain, id }
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return await repository.save({
|
|
36
|
+
...operation,
|
|
37
|
+
...patch,
|
|
38
|
+
updater: user
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Directive('@transaction')
|
|
43
|
+
@Mutation(returns => [Operation], { description: "To modify multiple Operations' information" })
|
|
44
|
+
async updateMultipleOperation(
|
|
45
|
+
@Arg('patches', type => [OperationPatch]) patches: OperationPatch[],
|
|
46
|
+
@Ctx() context: any
|
|
47
|
+
): Promise<Operation[]> {
|
|
48
|
+
const { domain, user, tx } = context.state
|
|
49
|
+
|
|
50
|
+
let results = []
|
|
51
|
+
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
52
|
+
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
53
|
+
const operationRepo = tx.getRepository(Operation)
|
|
54
|
+
|
|
55
|
+
if (_createRecords.length > 0) {
|
|
56
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
57
|
+
const newRecord = _createRecords[i]
|
|
58
|
+
|
|
59
|
+
const result = await operationRepo.save({
|
|
60
|
+
...newRecord,
|
|
61
|
+
domain,
|
|
62
|
+
creator: user,
|
|
63
|
+
updater: user
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
results.push({ ...result, cuFlag: '+' })
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (_updateRecords.length > 0) {
|
|
71
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
72
|
+
const newRecord = _updateRecords[i]
|
|
73
|
+
const operation = await operationRepo.findOne(newRecord.id)
|
|
74
|
+
|
|
75
|
+
const result = await operationRepo.save({
|
|
76
|
+
...operation,
|
|
77
|
+
...newRecord,
|
|
78
|
+
updater: user
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return results
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@Directive('@transaction')
|
|
89
|
+
@Mutation(returns => Boolean, { description: 'To delete Operation' })
|
|
90
|
+
async deleteOperation(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
|
|
91
|
+
const { domain, tx } = context.state
|
|
92
|
+
|
|
93
|
+
await tx.getRepository(Operation).delete({ domain, id })
|
|
94
|
+
return true
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@Directive('@transaction')
|
|
98
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple operations' })
|
|
99
|
+
async deleteOperations(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<boolean> {
|
|
100
|
+
const { domain, tx } = context.state
|
|
101
|
+
|
|
102
|
+
await tx.getRepository(Operation).delete({
|
|
103
|
+
domain,
|
|
104
|
+
id: In(ids)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
return true
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
|
|
2
|
+
import { getRepository } from 'typeorm'
|
|
3
|
+
import { Domain, ListParam, convertListParams } from '@things-factory/shell'
|
|
4
|
+
import { User } from '@things-factory/auth-base'
|
|
5
|
+
import { Operation, OperationStatus } from './operation'
|
|
6
|
+
import { OperationList } from './operation-type'
|
|
7
|
+
|
|
8
|
+
@Resolver(Operation)
|
|
9
|
+
export class OperationQuery {
|
|
10
|
+
@Query(returns => Operation, { description: 'To fetch a Operation' })
|
|
11
|
+
async operation(@Arg('id') id: string, @Ctx() context: any): Promise<Operation> {
|
|
12
|
+
const { domain } = context.state
|
|
13
|
+
|
|
14
|
+
return await getRepository(Operation).findOne({
|
|
15
|
+
where: { domain, name }
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Query(returns => OperationList, { description: 'To fetch multiple Operations' })
|
|
20
|
+
async operations(@Args() params: ListParam, @Ctx() context: any): Promise<OperationList> {
|
|
21
|
+
const { domain } = context.state
|
|
22
|
+
|
|
23
|
+
const convertedParams = convertListParams(params, domain.id)
|
|
24
|
+
const [items, total] = await getRepository(Operation).findAndCount(convertedParams)
|
|
25
|
+
|
|
26
|
+
return { items, total }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@FieldResolver(type => Domain)
|
|
30
|
+
async domain(@Root() operation: Operation): Promise<Domain> {
|
|
31
|
+
return await getRepository(Domain).findOne(operation.domainId)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@FieldResolver(type => User)
|
|
35
|
+
async updater(@Root() operation: Operation): Promise<User> {
|
|
36
|
+
return await getRepository(User).findOne(operation.updaterId)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@FieldResolver(type => User)
|
|
40
|
+
async creator(@Root() operation: Operation): Promise<User> {
|
|
41
|
+
return await getRepository(User).findOne(operation.creatorId)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Field,
|
|
3
|
+
ID,
|
|
4
|
+
InputType,
|
|
5
|
+
Int,
|
|
6
|
+
ObjectType
|
|
7
|
+
} from 'type-graphql'
|
|
8
|
+
|
|
9
|
+
import { Operation } from './operation'
|
|
10
|
+
|
|
11
|
+
@InputType()
|
|
12
|
+
export class NewOperation {
|
|
13
|
+
@Field({ nullable: false })
|
|
14
|
+
name: string
|
|
15
|
+
|
|
16
|
+
@Field({ nullable: true })
|
|
17
|
+
description?: string
|
|
18
|
+
|
|
19
|
+
@Field({ nullable: true })
|
|
20
|
+
type?: string
|
|
21
|
+
|
|
22
|
+
@Field({ nullable: true })
|
|
23
|
+
operationStdChart?: string
|
|
24
|
+
|
|
25
|
+
@Field({ nullable: true })
|
|
26
|
+
operationStdTime?: string
|
|
27
|
+
|
|
28
|
+
@Field({ nullable: true })
|
|
29
|
+
active?: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@InputType()
|
|
33
|
+
export class OperationPatch {
|
|
34
|
+
@Field(type => ID, { nullable: true })
|
|
35
|
+
id!: string
|
|
36
|
+
|
|
37
|
+
@Field({ nullable: true })
|
|
38
|
+
name: string
|
|
39
|
+
|
|
40
|
+
@Field({ nullable: true })
|
|
41
|
+
description?: string
|
|
42
|
+
|
|
43
|
+
@Field({ nullable: true })
|
|
44
|
+
type?: string
|
|
45
|
+
|
|
46
|
+
@Field({ nullable: true })
|
|
47
|
+
operationStdChart?: string
|
|
48
|
+
|
|
49
|
+
@Field({ nullable: true })
|
|
50
|
+
operationStdTime?: string
|
|
51
|
+
|
|
52
|
+
@Field({ nullable: true })
|
|
53
|
+
active?: boolean
|
|
54
|
+
|
|
55
|
+
@Field()
|
|
56
|
+
cuFlag: string
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@ObjectType()
|
|
60
|
+
export class OperationList {
|
|
61
|
+
@Field(type => [Operation])
|
|
62
|
+
items: Operation[]
|
|
63
|
+
|
|
64
|
+
@Field(type => Int)
|
|
65
|
+
total: number
|
|
66
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Field,
|
|
3
|
+
ID,
|
|
4
|
+
ObjectType,
|
|
5
|
+
registerEnumType
|
|
6
|
+
} from 'type-graphql'
|
|
7
|
+
import {
|
|
8
|
+
Column,
|
|
9
|
+
CreateDateColumn,
|
|
10
|
+
Entity,
|
|
11
|
+
Index,
|
|
12
|
+
ManyToOne,
|
|
13
|
+
PrimaryGeneratedColumn,
|
|
14
|
+
RelationId,
|
|
15
|
+
UpdateDateColumn
|
|
16
|
+
} from 'typeorm'
|
|
17
|
+
|
|
18
|
+
import { User } from '@things-factory/auth-base'
|
|
19
|
+
import { Domain } from '@things-factory/shell'
|
|
20
|
+
|
|
21
|
+
export enum OperationStatus {
|
|
22
|
+
STATUS_A = 'STATUS_A',
|
|
23
|
+
STATUS_B = 'STATUS_B',
|
|
24
|
+
ASSY = 'Assembly',
|
|
25
|
+
INV = 'Inventory',
|
|
26
|
+
PACK = 'Packing',
|
|
27
|
+
SMT = 'SMT',
|
|
28
|
+
STD = 'Standard',
|
|
29
|
+
TEST = 'Test'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
registerEnumType(OperationStatus, {
|
|
33
|
+
name: 'OperationStatus',
|
|
34
|
+
description: 'state enumeration of a operation'
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
@Entity()
|
|
38
|
+
@Index('ix_operation_0', (operation: Operation) => [operation.domain, operation.name], { unique: true })
|
|
39
|
+
@ObjectType({ description: 'Entity for Operation' })
|
|
40
|
+
export class Operation {
|
|
41
|
+
@PrimaryGeneratedColumn('uuid')
|
|
42
|
+
@Field(type => ID, { nullable: false })
|
|
43
|
+
readonly id: string
|
|
44
|
+
|
|
45
|
+
@ManyToOne(type => Domain)
|
|
46
|
+
@Field(type => Domain, { nullable: false })
|
|
47
|
+
domain: Domain
|
|
48
|
+
|
|
49
|
+
@RelationId((operation: Operation) => operation.domain)
|
|
50
|
+
domainId: string
|
|
51
|
+
|
|
52
|
+
@Column()
|
|
53
|
+
@Field({ nullable: false })
|
|
54
|
+
name: string
|
|
55
|
+
|
|
56
|
+
@Column({
|
|
57
|
+
nullable: true
|
|
58
|
+
})
|
|
59
|
+
@Field({ nullable: true })
|
|
60
|
+
description?: string
|
|
61
|
+
|
|
62
|
+
@Column({
|
|
63
|
+
nullable: true
|
|
64
|
+
})
|
|
65
|
+
@Field({ nullable: true })
|
|
66
|
+
type?: string
|
|
67
|
+
|
|
68
|
+
@Column({
|
|
69
|
+
nullable: true
|
|
70
|
+
})
|
|
71
|
+
@Field({ nullable: true })
|
|
72
|
+
operationStdChart?: string
|
|
73
|
+
|
|
74
|
+
@Column({
|
|
75
|
+
nullable: true
|
|
76
|
+
})
|
|
77
|
+
@Field({ nullable: true })
|
|
78
|
+
operationStdTime?: string
|
|
79
|
+
|
|
80
|
+
@Column({
|
|
81
|
+
nullable: true
|
|
82
|
+
})
|
|
83
|
+
@Field({ nullable: true })
|
|
84
|
+
active?: boolean
|
|
85
|
+
|
|
86
|
+
@ManyToOne(type => User, {
|
|
87
|
+
nullable: true
|
|
88
|
+
})
|
|
89
|
+
@Field(type => User, { nullable: true })
|
|
90
|
+
creator?: User
|
|
91
|
+
|
|
92
|
+
@RelationId((operation: Operation) => operation.creator)
|
|
93
|
+
creatorId?: string
|
|
94
|
+
|
|
95
|
+
@ManyToOne(type => User, {
|
|
96
|
+
nullable: true
|
|
97
|
+
})
|
|
98
|
+
@Field(type => User, { nullable: true })
|
|
99
|
+
updater?: User
|
|
100
|
+
|
|
101
|
+
@RelationId((operation: Operation) => operation.creator)
|
|
102
|
+
updaterId?: string
|
|
103
|
+
|
|
104
|
+
@CreateDateColumn()
|
|
105
|
+
@Field({ nullable: true })
|
|
106
|
+
createdAt?: Date
|
|
107
|
+
|
|
108
|
+
@UpdateDateColumn()
|
|
109
|
+
@Field({ nullable: true })
|
|
110
|
+
updatedAt?: Date
|
|
111
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
|
|
2
|
+
import { getRepository, In } from 'typeorm'
|
|
3
|
+
import { Routing } from './routing'
|
|
4
|
+
import { NewRouting, RoutingPatch } from './routing-type'
|
|
5
|
+
|
|
6
|
+
@Resolver(Routing)
|
|
7
|
+
export class RoutingMutation {
|
|
8
|
+
@Directive('@transaction')
|
|
9
|
+
@Mutation(returns => Routing, { description: 'To create new Routing' })
|
|
10
|
+
async createRouting(@Arg('routing') routing: NewRouting, @Ctx() context: any): Promise<Routing> {
|
|
11
|
+
const { domain, user, tx } = context.state
|
|
12
|
+
|
|
13
|
+
return await tx.getRepository(Routing).save({
|
|
14
|
+
...routing,
|
|
15
|
+
domain,
|
|
16
|
+
creator: user,
|
|
17
|
+
updater: user
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Directive('@transaction')
|
|
22
|
+
@Mutation(returns => Routing, { description: 'To modify Routing information' })
|
|
23
|
+
async updateRouting(
|
|
24
|
+
@Arg('id') id: string,
|
|
25
|
+
@Arg('patch') patch: RoutingPatch,
|
|
26
|
+
@Ctx() context: any
|
|
27
|
+
): Promise<Routing> {
|
|
28
|
+
const { domain, user, tx } = context.state
|
|
29
|
+
|
|
30
|
+
const repository = tx.getRepository(Routing)
|
|
31
|
+
const routing = await repository.findOne({
|
|
32
|
+
where: { domain, id }
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return await repository.save({
|
|
36
|
+
...routing,
|
|
37
|
+
...patch,
|
|
38
|
+
updater: user
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Directive('@transaction')
|
|
43
|
+
@Mutation(returns => [Routing], { description: "To modify multiple Routings' information" })
|
|
44
|
+
async updateMultipleRouting(
|
|
45
|
+
@Arg('patches', type => [RoutingPatch]) patches: RoutingPatch[],
|
|
46
|
+
@Ctx() context: any
|
|
47
|
+
): Promise<Routing[]> {
|
|
48
|
+
const { domain, user, tx } = context.state
|
|
49
|
+
|
|
50
|
+
let results = []
|
|
51
|
+
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
52
|
+
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
53
|
+
const routingRepo = tx.getRepository(Routing)
|
|
54
|
+
|
|
55
|
+
if (_createRecords.length > 0) {
|
|
56
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
57
|
+
const newRecord = _createRecords[i]
|
|
58
|
+
|
|
59
|
+
const result = await routingRepo.save({
|
|
60
|
+
...newRecord,
|
|
61
|
+
domain,
|
|
62
|
+
creator: user,
|
|
63
|
+
updater: user
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
results.push({ ...result, cuFlag: '+' })
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (_updateRecords.length > 0) {
|
|
71
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
72
|
+
const newRecord = _updateRecords[i]
|
|
73
|
+
const routing = await routingRepo.findOne(newRecord.id)
|
|
74
|
+
|
|
75
|
+
const result = await routingRepo.save({
|
|
76
|
+
...routing,
|
|
77
|
+
...newRecord,
|
|
78
|
+
updater: user
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return results
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@Directive('@transaction')
|
|
89
|
+
@Mutation(returns => Boolean, { description: 'To delete Routing' })
|
|
90
|
+
async deleteRouting(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
|
|
91
|
+
const { domain, tx } = context.state
|
|
92
|
+
|
|
93
|
+
await tx.getRepository(Routing).delete({ domain, id })
|
|
94
|
+
return true
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@Directive('@transaction')
|
|
98
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple routings' })
|
|
99
|
+
async deleteRoutings(
|
|
100
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
101
|
+
@Ctx() context: any
|
|
102
|
+
): Promise<boolean> {
|
|
103
|
+
const { domain, tx } = context.state
|
|
104
|
+
|
|
105
|
+
await tx.getRepository(Routing).delete({
|
|
106
|
+
domain,
|
|
107
|
+
id: In(ids)
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
return true
|
|
111
|
+
}
|
|
112
|
+
}
|