@things-factory/rack-base 8.0.0-beta.1 → 8.0.0-beta.4
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/dist-client/bootstrap.d.ts +1 -0
- package/dist-client/bootstrap.js +2 -0
- package/dist-client/bootstrap.js.map +1 -0
- package/dist-client/index.js +2 -0
- package/dist-client/index.js.map +1 -0
- package/dist-client/pages/cell/cell-importer.d.ts +23 -0
- package/dist-client/pages/cell/cell-importer.js +94 -0
- package/dist-client/pages/cell/cell-importer.js.map +1 -0
- package/dist-client/pages/cell/cell-list-page.d.ts +54 -0
- package/dist-client/pages/cell/cell-list-page.js +290 -0
- package/dist-client/pages/cell/cell-list-page.js.map +1 -0
- package/dist-client/pages/rack/rack-importer.d.ts +23 -0
- package/dist-client/pages/rack/rack-importer.js +94 -0
- package/dist-client/pages/rack/rack-importer.js.map +1 -0
- package/dist-client/pages/rack/rack-list-page.d.ts +54 -0
- package/dist-client/pages/rack/rack-list-page.js +294 -0
- package/dist-client/pages/rack/rack-list-page.js.map +1 -0
- package/dist-client/route.d.ts +1 -0
- package/dist-client/route.js +11 -0
- package/dist-client/route.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -0
- package/package.json +6 -6
- package/client/bootstrap.ts +0 -1
- package/client/pages/cell/cell-importer.ts +0 -87
- package/client/pages/cell/cell-list-page.ts +0 -308
- package/client/pages/rack/rack-importer.ts +0 -87
- package/client/pages/rack/rack-list-page.ts +0 -312
- package/client/route.ts +0 -11
- package/server/index.ts +0 -1
- package/server/migrations/index.ts +0 -9
- package/server/routes.ts +0 -26
- package/server/service/cell/cell-mutation.ts +0 -133
- package/server/service/cell/cell-query.ts +0 -50
- package/server/service/cell/cell-type.ts +0 -96
- package/server/service/cell/cell.ts +0 -112
- package/server/service/cell/index.ts +0 -6
- package/server/service/index.ts +0 -22
- package/server/service/rack/index.ts +0 -6
- package/server/service/rack/rack-mutation.ts +0 -133
- package/server/service/rack/rack-query.ts +0 -64
- package/server/service/rack/rack-type.ts +0 -54
- package/server/service/rack/rack.ts +0 -76
- /package/{client/index.ts → dist-client/index.d.ts} +0 -0
|
@@ -1,9 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
|
|
2
|
-
/*
|
|
3
|
-
* can add global public routes to application (auth not required, tenancy not required)
|
|
4
|
-
*
|
|
5
|
-
* ex) routes.get('/path', async(context, next) => {})
|
|
6
|
-
* ex) routes.post('/path', async(context, next) => {})
|
|
7
|
-
*/
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
process.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRouter) => {
|
|
11
|
-
/*
|
|
12
|
-
* can add global private routes to application (auth required, tenancy not required)
|
|
13
|
-
*/
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
process.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {
|
|
17
|
-
/*
|
|
18
|
-
* can add domain public routes to application (auth not required, tenancy required)
|
|
19
|
-
*/
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
process.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {
|
|
23
|
-
/*
|
|
24
|
-
* can add domain private routes to application (auth required, tenancy required)
|
|
25
|
-
*/
|
|
26
|
-
})
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
-
import { In } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { deleteAttachmentsByRef } from '@things-factory/attachment-base'
|
|
5
|
-
|
|
6
|
-
import { Cell } from './cell'
|
|
7
|
-
import { CellPatch, NewCell } from './cell-type'
|
|
8
|
-
|
|
9
|
-
@Resolver(Cell)
|
|
10
|
-
export class CellMutation {
|
|
11
|
-
@Directive('@transaction')
|
|
12
|
-
@Mutation(returns => Cell, { description: 'To create new Cell' })
|
|
13
|
-
async createCell(@Arg('cell') cell: NewCell, @Ctx() context: ResolverContext): Promise<Cell> {
|
|
14
|
-
const { domain, user, tx } = context.state
|
|
15
|
-
|
|
16
|
-
return await tx.getRepository(Cell).save({
|
|
17
|
-
...cell,
|
|
18
|
-
domain,
|
|
19
|
-
creator: user,
|
|
20
|
-
updater: user
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
@Directive('@transaction')
|
|
25
|
-
@Mutation(returns => Cell, { description: 'To modify Cell information' })
|
|
26
|
-
async updateCell(
|
|
27
|
-
@Arg('id') id: string,
|
|
28
|
-
@Arg('patch') patch: CellPatch,
|
|
29
|
-
@Ctx() context: ResolverContext
|
|
30
|
-
): Promise<Cell> {
|
|
31
|
-
const { domain, user, tx } = context.state
|
|
32
|
-
|
|
33
|
-
const repository = tx.getRepository(Cell)
|
|
34
|
-
const cell = await repository.findOne({
|
|
35
|
-
where: { domain: { id: domain.id }, id }
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
return await repository.save({
|
|
39
|
-
...cell,
|
|
40
|
-
...patch,
|
|
41
|
-
updater: user
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@Directive('@transaction')
|
|
46
|
-
@Mutation(returns => [Cell], { description: "To modify multiple Cells' information" })
|
|
47
|
-
async updateMultipleCell(
|
|
48
|
-
@Arg('patches', type => [CellPatch]) patches: CellPatch[],
|
|
49
|
-
@Ctx() context: ResolverContext
|
|
50
|
-
): Promise<Cell[]> {
|
|
51
|
-
const { domain, user, tx } = context.state
|
|
52
|
-
|
|
53
|
-
let results = []
|
|
54
|
-
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
55
|
-
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
56
|
-
const cellRepo = tx.getRepository(Cell)
|
|
57
|
-
|
|
58
|
-
if (_createRecords.length > 0) {
|
|
59
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
60
|
-
const newRecord = _createRecords[i]
|
|
61
|
-
|
|
62
|
-
const result = await cellRepo.save({
|
|
63
|
-
...newRecord,
|
|
64
|
-
domain,
|
|
65
|
-
creator: user,
|
|
66
|
-
updater: user
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
results.push({ ...result, cuFlag: '+' })
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (_updateRecords.length > 0) {
|
|
74
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
75
|
-
const updateRecord = _updateRecords[i]
|
|
76
|
-
const cell = await cellRepo.findOneBy({ id: updateRecord.id })
|
|
77
|
-
|
|
78
|
-
const result = await cellRepo.save({
|
|
79
|
-
...cell,
|
|
80
|
-
...updateRecord,
|
|
81
|
-
updater: user
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
results.push({ ...result, cuFlag: 'M' })
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return results
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
@Directive('@transaction')
|
|
92
|
-
@Mutation(returns => Boolean, { description: 'To delete Cell' })
|
|
93
|
-
async deleteCell(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
94
|
-
const { domain, tx } = context.state
|
|
95
|
-
|
|
96
|
-
await tx.getRepository(Cell).delete({ domain: { id: domain.id }, id })
|
|
97
|
-
await deleteAttachmentsByRef(null, { refBys: [id] }, context)
|
|
98
|
-
|
|
99
|
-
return true
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
@Directive('@transaction')
|
|
103
|
-
@Mutation(returns => Boolean, { description: 'To delete multiple Cells' })
|
|
104
|
-
async deleteCells(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<boolean> {
|
|
105
|
-
const { domain, tx } = context.state
|
|
106
|
-
|
|
107
|
-
await tx.getRepository(Cell).delete({
|
|
108
|
-
domain: { id: domain.id },
|
|
109
|
-
id: In(ids)
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
await deleteAttachmentsByRef(null, { refBys: ids }, context)
|
|
113
|
-
|
|
114
|
-
return true
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
@Directive('@transaction')
|
|
118
|
-
@Mutation(returns => Boolean, { description: 'To import multiple Cells' })
|
|
119
|
-
async importCells(
|
|
120
|
-
@Arg('cells', type => [CellPatch]) cells: CellPatch[],
|
|
121
|
-
@Ctx() context: ResolverContext
|
|
122
|
-
): Promise<boolean> {
|
|
123
|
-
const { domain, tx } = context.state
|
|
124
|
-
|
|
125
|
-
await Promise.all(
|
|
126
|
-
cells.map(async (cell: CellPatch) => {
|
|
127
|
-
const createdCell: Cell = await tx.getRepository(Cell).save({ domain, ...cell })
|
|
128
|
-
})
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
return true
|
|
132
|
-
}
|
|
133
|
-
}
|
|
@@ -1,50 +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 { Cell } from './cell'
|
|
7
|
-
import { CellList } from './cell-type'
|
|
8
|
-
|
|
9
|
-
@Resolver(Cell)
|
|
10
|
-
export class CellQuery {
|
|
11
|
-
@Query(returns => Cell!, { nullable: true, description: 'To fetch a Cell' })
|
|
12
|
-
async cell(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Cell> {
|
|
13
|
-
const { domain } = context.state
|
|
14
|
-
|
|
15
|
-
return await getRepository(Cell).findOne({
|
|
16
|
-
where: { domain: { id: domain.id }, id }
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@Query(returns => CellList, { description: 'To fetch multiple Cells' })
|
|
21
|
-
async cells(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<CellList> {
|
|
22
|
-
const { domain } = context.state
|
|
23
|
-
|
|
24
|
-
const queryBuilder = getQueryBuilderFromListParams({
|
|
25
|
-
domain,
|
|
26
|
-
params,
|
|
27
|
-
repository: await getRepository(Cell),
|
|
28
|
-
searchables: ['name', 'description']
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
const [items, total] = await queryBuilder.getManyAndCount()
|
|
32
|
-
|
|
33
|
-
return { items, total }
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@FieldResolver(type => Domain)
|
|
37
|
-
async domain(@Root() cell: Cell): Promise<Domain> {
|
|
38
|
-
return await getRepository(Domain).findOneBy({ id: cell.domainId })
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@FieldResolver(type => User)
|
|
42
|
-
async updater(@Root() cell: Cell): Promise<User> {
|
|
43
|
-
return await getRepository(User).findOneBy({ id: cell.updaterId })
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@FieldResolver(type => User)
|
|
47
|
-
async creator(@Root() cell: Cell): Promise<User> {
|
|
48
|
-
return await getRepository(User).findOneBy({ id: cell.creatorId })
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
-
|
|
3
|
-
import { Cell } from './cell'
|
|
4
|
-
|
|
5
|
-
@InputType()
|
|
6
|
-
export class NewCell {
|
|
7
|
-
@Field({ nullable: true })
|
|
8
|
-
stationCd: string
|
|
9
|
-
|
|
10
|
-
@Field()
|
|
11
|
-
equipCd: string
|
|
12
|
-
|
|
13
|
-
@Field()
|
|
14
|
-
cellCd: string
|
|
15
|
-
|
|
16
|
-
@Field()
|
|
17
|
-
indCd: string
|
|
18
|
-
|
|
19
|
-
@Field()
|
|
20
|
-
channelNo: string
|
|
21
|
-
|
|
22
|
-
@Field()
|
|
23
|
-
panNo: string
|
|
24
|
-
|
|
25
|
-
@Field({ nullable: true })
|
|
26
|
-
equipZone?: string
|
|
27
|
-
|
|
28
|
-
@Field({ nullable: true })
|
|
29
|
-
sideCd?: string
|
|
30
|
-
|
|
31
|
-
@Field({ nullable: true })
|
|
32
|
-
cellSeq?: number
|
|
33
|
-
|
|
34
|
-
@Field({ nullable: true })
|
|
35
|
-
printerCd?: string
|
|
36
|
-
|
|
37
|
-
@Field({ nullable: true })
|
|
38
|
-
activeFlag?: boolean
|
|
39
|
-
|
|
40
|
-
@Field({ nullable: true })
|
|
41
|
-
status?: string
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
@InputType()
|
|
45
|
-
export class CellPatch {
|
|
46
|
-
@Field(type => ID, { nullable: true })
|
|
47
|
-
id?: string
|
|
48
|
-
|
|
49
|
-
@Field({ nullable: true })
|
|
50
|
-
stationCd?: string
|
|
51
|
-
|
|
52
|
-
@Field({ nullable: true })
|
|
53
|
-
equipCd?: string
|
|
54
|
-
|
|
55
|
-
@Field({ nullable: true })
|
|
56
|
-
cellCd?: string
|
|
57
|
-
|
|
58
|
-
@Field({ nullable: true })
|
|
59
|
-
indCd?: string
|
|
60
|
-
|
|
61
|
-
@Field({ nullable: true })
|
|
62
|
-
channelNo?: string
|
|
63
|
-
|
|
64
|
-
@Field({ nullable: true })
|
|
65
|
-
panNo?: string
|
|
66
|
-
|
|
67
|
-
@Field({ nullable: true })
|
|
68
|
-
equipZone?: string
|
|
69
|
-
|
|
70
|
-
@Field({ nullable: true })
|
|
71
|
-
sideCd?: string
|
|
72
|
-
|
|
73
|
-
@Field({ nullable: true })
|
|
74
|
-
cellSeq?: number
|
|
75
|
-
|
|
76
|
-
@Field({ nullable: true })
|
|
77
|
-
printerCd?: string
|
|
78
|
-
|
|
79
|
-
@Field({ nullable: true })
|
|
80
|
-
activeFlag?: boolean
|
|
81
|
-
|
|
82
|
-
@Field({ nullable: true })
|
|
83
|
-
status?: string
|
|
84
|
-
|
|
85
|
-
@Field({ nullable: true })
|
|
86
|
-
cuFlag?: string
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
@ObjectType()
|
|
90
|
-
export class CellList {
|
|
91
|
-
@Field(type => [Cell])
|
|
92
|
-
items: Cell[]
|
|
93
|
-
|
|
94
|
-
@Field(type => Int)
|
|
95
|
-
total: number
|
|
96
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { Field, ID, ObjectType } 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
|
-
@Entity()
|
|
17
|
-
@Index('ix_cell_0', (cell: Cell) => [cell.domain, cell.cellCd], { unique: true })
|
|
18
|
-
@ObjectType({ description: 'Entity for Cell' })
|
|
19
|
-
export class Cell {
|
|
20
|
-
@PrimaryGeneratedColumn('uuid')
|
|
21
|
-
@Field(type => ID)
|
|
22
|
-
readonly id: string
|
|
23
|
-
|
|
24
|
-
@ManyToOne(type => Domain)
|
|
25
|
-
@Field(type => Domain)
|
|
26
|
-
domain?: Domain
|
|
27
|
-
|
|
28
|
-
@RelationId((cell: Cell) => cell.domain)
|
|
29
|
-
domainId?: string
|
|
30
|
-
|
|
31
|
-
@Column({ nullable: true, length: 30 })
|
|
32
|
-
@Field({ nullable: true })
|
|
33
|
-
stationCd: string
|
|
34
|
-
|
|
35
|
-
@Column({ length: 30 })
|
|
36
|
-
@Field()
|
|
37
|
-
equipCd: string
|
|
38
|
-
|
|
39
|
-
@Column({ length: 30 })
|
|
40
|
-
@Field()
|
|
41
|
-
cellCd: string
|
|
42
|
-
|
|
43
|
-
@Column({ length: 30 })
|
|
44
|
-
@Field()
|
|
45
|
-
indCd: string
|
|
46
|
-
|
|
47
|
-
@Column({ length: 40 })
|
|
48
|
-
@Field()
|
|
49
|
-
channelNo: string
|
|
50
|
-
|
|
51
|
-
@Column({ length: 40 })
|
|
52
|
-
@Field()
|
|
53
|
-
panNo: string
|
|
54
|
-
|
|
55
|
-
@Column({ nullable: true, length: 30 })
|
|
56
|
-
@Field({ nullable: true })
|
|
57
|
-
equipZone?: string
|
|
58
|
-
|
|
59
|
-
@Column({ nullable: true, length: 30 })
|
|
60
|
-
@Field({ nullable: true })
|
|
61
|
-
sideCd?: string
|
|
62
|
-
|
|
63
|
-
@Column({ nullable: true, width: 10 })
|
|
64
|
-
@Field({ nullable: true })
|
|
65
|
-
cellSeq?: number
|
|
66
|
-
|
|
67
|
-
@Column({ nullable: true, length: 30 })
|
|
68
|
-
@Field({ nullable: true })
|
|
69
|
-
printerCd?: string
|
|
70
|
-
|
|
71
|
-
@Column({
|
|
72
|
-
nullable: true
|
|
73
|
-
})
|
|
74
|
-
@Field({ nullable: true })
|
|
75
|
-
activeFlag?: boolean
|
|
76
|
-
|
|
77
|
-
@Column({ nullable: true, width: 10 })
|
|
78
|
-
@Field({ nullable: true })
|
|
79
|
-
status?: string
|
|
80
|
-
|
|
81
|
-
@Column({
|
|
82
|
-
nullable: true
|
|
83
|
-
})
|
|
84
|
-
@Field({ nullable: true })
|
|
85
|
-
params?: string
|
|
86
|
-
|
|
87
|
-
@CreateDateColumn()
|
|
88
|
-
@Field({ nullable: true })
|
|
89
|
-
createdAt?: Date
|
|
90
|
-
|
|
91
|
-
@UpdateDateColumn()
|
|
92
|
-
@Field({ nullable: true })
|
|
93
|
-
updatedAt?: Date
|
|
94
|
-
|
|
95
|
-
@ManyToOne(type => User, {
|
|
96
|
-
nullable: true
|
|
97
|
-
})
|
|
98
|
-
@Field(type => User, { nullable: true })
|
|
99
|
-
creator?: User
|
|
100
|
-
|
|
101
|
-
@RelationId((cell: Cell) => cell.creator)
|
|
102
|
-
creatorId?: string
|
|
103
|
-
|
|
104
|
-
@ManyToOne(type => User, {
|
|
105
|
-
nullable: true
|
|
106
|
-
})
|
|
107
|
-
@Field(type => User, { nullable: true })
|
|
108
|
-
updater?: User
|
|
109
|
-
|
|
110
|
-
@RelationId((cell: Cell) => cell.updater)
|
|
111
|
-
updaterId?: string
|
|
112
|
-
}
|
package/server/service/index.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/* EXPORT ENTITY TYPES */
|
|
2
|
-
export * from './rack/rack'
|
|
3
|
-
export * from './cell/cell'
|
|
4
|
-
|
|
5
|
-
/* IMPORT ENTITIES AND RESOLVERS */
|
|
6
|
-
import { entities as RackEntities, resolvers as RackResolvers } from './rack'
|
|
7
|
-
import { entities as CellEntities, resolvers as CellResolvers } from './cell'
|
|
8
|
-
|
|
9
|
-
export const entities = [
|
|
10
|
-
/* ENTITIES */
|
|
11
|
-
...RackEntities,
|
|
12
|
-
...CellEntities,
|
|
13
|
-
]
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export const schema = {
|
|
17
|
-
resolverClasses: [
|
|
18
|
-
/* RESOLVER CLASSES */
|
|
19
|
-
...RackResolvers,
|
|
20
|
-
...CellResolvers,
|
|
21
|
-
]
|
|
22
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
-
import { In } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { deleteAttachmentsByRef } from '@things-factory/attachment-base'
|
|
5
|
-
|
|
6
|
-
import { Rack } from './rack'
|
|
7
|
-
import { NewRack, RackPatch } from './rack-type'
|
|
8
|
-
|
|
9
|
-
@Resolver(Rack)
|
|
10
|
-
export class RackMutation {
|
|
11
|
-
@Directive('@transaction')
|
|
12
|
-
@Mutation(returns => Rack, { description: 'To create new Rack' })
|
|
13
|
-
async createRack(@Arg('rack') rack: NewRack, @Ctx() context: ResolverContext): Promise<Rack> {
|
|
14
|
-
const { domain, user, tx } = context.state
|
|
15
|
-
|
|
16
|
-
return await tx.getRepository(Rack).save({
|
|
17
|
-
...rack,
|
|
18
|
-
domain,
|
|
19
|
-
creator: user,
|
|
20
|
-
updater: user
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
@Directive('@transaction')
|
|
25
|
-
@Mutation(returns => Rack, { description: 'To modify Rack information' })
|
|
26
|
-
async updateRack(
|
|
27
|
-
@Arg('id') id: string,
|
|
28
|
-
@Arg('patch') patch: RackPatch,
|
|
29
|
-
@Ctx() context: ResolverContext
|
|
30
|
-
): Promise<Rack> {
|
|
31
|
-
const { domain, user, tx } = context.state
|
|
32
|
-
|
|
33
|
-
const repository = tx.getRepository(Rack)
|
|
34
|
-
const rack = await repository.findOne({
|
|
35
|
-
where: { domain: { id: domain.id }, id }
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
return await repository.save({
|
|
39
|
-
...rack,
|
|
40
|
-
...patch,
|
|
41
|
-
updater: user
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@Directive('@transaction')
|
|
46
|
-
@Mutation(returns => [Rack], { description: "To modify multiple Racks' information" })
|
|
47
|
-
async updateMultipleRack(
|
|
48
|
-
@Arg('patches', type => [RackPatch]) patches: RackPatch[],
|
|
49
|
-
@Ctx() context: ResolverContext
|
|
50
|
-
): Promise<Rack[]> {
|
|
51
|
-
const { domain, user, tx } = context.state
|
|
52
|
-
|
|
53
|
-
let results = []
|
|
54
|
-
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
55
|
-
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
56
|
-
const rackRepo = tx.getRepository(Rack)
|
|
57
|
-
|
|
58
|
-
if (_createRecords.length > 0) {
|
|
59
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
60
|
-
const newRecord = _createRecords[i]
|
|
61
|
-
|
|
62
|
-
const result = await rackRepo.save({
|
|
63
|
-
...newRecord,
|
|
64
|
-
domain,
|
|
65
|
-
creator: user,
|
|
66
|
-
updater: user
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
results.push({ ...result, cuFlag: '+' })
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (_updateRecords.length > 0) {
|
|
74
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
75
|
-
const updateRecord = _updateRecords[i]
|
|
76
|
-
const rack = await rackRepo.findOneBy({ id: updateRecord.id })
|
|
77
|
-
|
|
78
|
-
const result = await rackRepo.save({
|
|
79
|
-
...rack,
|
|
80
|
-
...updateRecord,
|
|
81
|
-
updater: user
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
results.push({ ...result, cuFlag: 'M' })
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return results
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
@Directive('@transaction')
|
|
92
|
-
@Mutation(returns => Boolean, { description: 'To delete Rack' })
|
|
93
|
-
async deleteRack(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
94
|
-
const { domain, tx } = context.state
|
|
95
|
-
|
|
96
|
-
await tx.getRepository(Rack).delete({ domain: { id: domain.id }, id })
|
|
97
|
-
await deleteAttachmentsByRef(null, { refBys: [id] }, context)
|
|
98
|
-
|
|
99
|
-
return true
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
@Directive('@transaction')
|
|
103
|
-
@Mutation(returns => Boolean, { description: 'To delete multiple Racks' })
|
|
104
|
-
async deleteRacks(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<boolean> {
|
|
105
|
-
const { domain, tx } = context.state
|
|
106
|
-
|
|
107
|
-
await tx.getRepository(Rack).delete({
|
|
108
|
-
domain: { id: domain.id },
|
|
109
|
-
id: In(ids)
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
await deleteAttachmentsByRef(null, { refBys: ids }, context)
|
|
113
|
-
|
|
114
|
-
return true
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
@Directive('@transaction')
|
|
118
|
-
@Mutation(returns => Boolean, { description: 'To import multiple Racks' })
|
|
119
|
-
async importRacks(
|
|
120
|
-
@Arg('racks', type => [RackPatch]) racks: RackPatch[],
|
|
121
|
-
@Ctx() context: ResolverContext
|
|
122
|
-
): Promise<boolean> {
|
|
123
|
-
const { domain, tx } = context.state
|
|
124
|
-
|
|
125
|
-
await Promise.all(
|
|
126
|
-
racks.map(async (rack: RackPatch) => {
|
|
127
|
-
const createdRack: Rack = await tx.getRepository(Rack).save({ domain, ...rack })
|
|
128
|
-
})
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
return true
|
|
132
|
-
}
|
|
133
|
-
}
|
|
@@ -1,64 +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 { Rack } from './rack'
|
|
8
|
-
import { RackList } from './rack-type'
|
|
9
|
-
|
|
10
|
-
@Resolver(Rack)
|
|
11
|
-
export class RackQuery {
|
|
12
|
-
@Query(returns => Rack!, { nullable: true, description: 'To fetch a Rack' })
|
|
13
|
-
async rack(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Rack> {
|
|
14
|
-
const { domain } = context.state
|
|
15
|
-
|
|
16
|
-
return await getRepository(Rack).findOne({
|
|
17
|
-
where: { domain: { id: domain.id }, id }
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@Query(returns => RackList, { description: 'To fetch multiple Racks' })
|
|
22
|
-
async racks(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<RackList> {
|
|
23
|
-
const { domain } = context.state
|
|
24
|
-
|
|
25
|
-
const queryBuilder = getQueryBuilderFromListParams({
|
|
26
|
-
domain,
|
|
27
|
-
params,
|
|
28
|
-
repository: await getRepository(Rack),
|
|
29
|
-
searchables: ['name', 'description']
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
const [items, total] = await queryBuilder.getManyAndCount()
|
|
33
|
-
|
|
34
|
-
return { items, total }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@FieldResolver(type => String)
|
|
38
|
-
async thumbnail(@Root() rack: Rack): Promise<string | undefined> {
|
|
39
|
-
const attachment: Attachment = await getRepository(Attachment).findOne({
|
|
40
|
-
where: {
|
|
41
|
-
domain: { id: rack.domainId },
|
|
42
|
-
refType: Rack.name,
|
|
43
|
-
refBy: rack.id
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
return attachment?.fullpath
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
@FieldResolver(type => Domain)
|
|
51
|
-
async domain(@Root() rack: Rack): Promise<Domain> {
|
|
52
|
-
return await getRepository(Domain).findOneBy({ id: rack.domainId })
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
@FieldResolver(type => User)
|
|
56
|
-
async updater(@Root() rack: Rack): Promise<User> {
|
|
57
|
-
return await getRepository(User).findOneBy({ id: rack.updaterId })
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@FieldResolver(type => User)
|
|
61
|
-
async creator(@Root() rack: Rack): Promise<User> {
|
|
62
|
-
return await getRepository(User).findOneBy({ id: rack.creatorId })
|
|
63
|
-
}
|
|
64
|
-
}
|