@things-factory/board-service 6.1.113 → 6.1.115

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/board-service",
3
- "version": "6.1.113",
3
+ "version": "6.1.115",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -24,9 +24,9 @@
24
24
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
25
25
  },
26
26
  "dependencies": {
27
- "@things-factory/auth-base": "^6.1.112",
27
+ "@things-factory/auth-base": "^6.1.115",
28
28
  "@things-factory/env": "^6.1.112",
29
- "@things-factory/font-base": "^6.1.112",
29
+ "@things-factory/font-base": "^6.1.115",
30
30
  "content-disposition": "^0.5.3",
31
31
  "generic-pool": "^3.8.2"
32
32
  },
@@ -34,5 +34,5 @@
34
34
  "@thiagoelg/node-printer": "0.6.2",
35
35
  "puppeteer": "^20.7.3"
36
36
  },
37
- "gitHead": "5c2a899ed475188d9555fcdd70db9d41b298a2ed"
37
+ "gitHead": "3677982365595b0f3a8ec26e47c234878ecbb910"
38
38
  }
@@ -0,0 +1,120 @@
1
+ import { Field, ID, ObjectType } from 'type-graphql'
2
+ import { Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn, RelationId } from 'typeorm'
3
+
4
+ import {
5
+ HistoryActionColumn,
6
+ HistoryActionType,
7
+ HistoryEntityInterface,
8
+ HistoryOriginalIdColumn
9
+ } from '@operato/typeorm-history'
10
+ import { User } from '@things-factory/auth-base'
11
+ import { Domain } from '@things-factory/shell'
12
+ import { config } from '@things-factory/env'
13
+
14
+ import { Board } from './board'
15
+ import { Group } from '../group/group'
16
+
17
+ const ORMCONFIG = config.get('ormconfig', {})
18
+ const DATABASE_TYPE = ORMCONFIG.type
19
+
20
+ @Entity()
21
+ @Index('ix_board_history_0', (boardHistory: BoardHistory) => [boardHistory.originalId, boardHistory.version], {
22
+ unique: true
23
+ })
24
+ @ObjectType({ description: 'History Entity of Board' })
25
+ export class BoardHistory implements HistoryEntityInterface<Board> {
26
+ @PrimaryGeneratedColumn('uuid')
27
+ @Field(type => ID)
28
+ readonly id: string
29
+
30
+ @Column({ nullable: true, default: 1 })
31
+ @Field({ nullable: true })
32
+ version?: number = 1
33
+
34
+ @ManyToOne(type => Domain)
35
+ @Field(type => Domain, { nullable: true })
36
+ domain?: Domain
37
+
38
+ @RelationId((board: Board) => board.domain)
39
+ domainId?: string
40
+
41
+ @Column()
42
+ @Field()
43
+ name?: string
44
+
45
+ @Column({ nullable: true })
46
+ @Field({ nullable: true })
47
+ description?: string
48
+
49
+ @Column({
50
+ nullable: true,
51
+ type:
52
+ DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
53
+ ? 'longtext'
54
+ : DATABASE_TYPE == 'oracle'
55
+ ? 'clob'
56
+ : 'varchar'
57
+ })
58
+ @Field({ nullable: true })
59
+ model?: string
60
+
61
+ @Column({
62
+ nullable: true,
63
+ type:
64
+ DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
65
+ ? 'longtext'
66
+ : DATABASE_TYPE == 'oracle'
67
+ ? 'clob'
68
+ : 'varchar'
69
+ })
70
+ @Field({ nullable: true })
71
+ thumbnail?: string
72
+
73
+ @ManyToOne(type => Group, group => group.boards)
74
+ @Field(type => Group, { nullable: true })
75
+ group?: Group
76
+
77
+ @RelationId((board: Board) => board.group)
78
+ groupId?: string
79
+
80
+ @Column({ nullable: true })
81
+ @Field({ nullable: true })
82
+ createdAt?: Date
83
+
84
+ @Column({ nullable: true })
85
+ @Field({ nullable: true })
86
+ updatedAt?: Date
87
+
88
+ @ManyToOne(type => User, { nullable: true })
89
+ @Field(type => User, { nullable: true })
90
+ creator?: User
91
+
92
+ @RelationId((board: Board) => board.creator)
93
+ creatorId?: string
94
+
95
+ @ManyToOne(type => User, { nullable: true })
96
+ @Field(type => User, { nullable: true })
97
+ updater?: User
98
+
99
+ @RelationId((board: Board) => board.updater)
100
+ updaterId?: string
101
+
102
+ @Column({ nullable: true })
103
+ @Field({ nullable: true })
104
+ deletedAt?: Date
105
+
106
+ @HistoryOriginalIdColumn()
107
+ public originalId!: string
108
+
109
+ @HistoryActionColumn({
110
+ nullable: false,
111
+ type:
112
+ DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
113
+ ? 'enum'
114
+ : DATABASE_TYPE == 'oracle'
115
+ ? 'varchar2'
116
+ : 'smallint',
117
+ enum: HistoryActionType
118
+ })
119
+ public action!: HistoryActionType
120
+ }
@@ -83,15 +83,16 @@ export class BoardMutation {
83
83
  throw t('error.name must be unique from the original board', { name: patch.name })
84
84
  }
85
85
 
86
- if (patch.groupId !== undefined) {
87
- const groupRepository = tx.getRepository(Group)
88
- board.group =
89
- (await groupRepository.findOneBy({
90
- domain: { id: domain.id },
91
- id: patch.groupId
92
- })) || null
86
+ const { groupId, ...patched } = patch
93
87
 
94
- delete patch.groupId
88
+ if (groupId !== undefined) {
89
+ const groupRepository = tx.getRepository(Group)
90
+ board.group = groupId
91
+ ? (await groupRepository.findOneBy({
92
+ domain: { id: domain.id },
93
+ id: groupId
94
+ })) || null
95
+ : null
95
96
  }
96
97
 
97
98
  const { id: excluded, ...clone } = board
@@ -99,7 +100,8 @@ export class BoardMutation {
99
100
  const cloned = await repository.save({
100
101
  domain,
101
102
  ...clone,
102
- ...patch,
103
+ ...patched,
104
+ version: 1,
103
105
  updater: user,
104
106
  creator: user
105
107
  })
@@ -127,7 +129,10 @@ export class BoardMutation {
127
129
  const { domain, user, notify, tx } = context.state
128
130
  const repository = tx.getRepository(Board)
129
131
 
130
- const board = await repository.findOneBy({ domain: { id: domain.id }, id })
132
+ const board = await repository.findOne({
133
+ where: { domain: { id: domain.id }, id },
134
+ relations: ['creator']
135
+ })
131
136
 
132
137
  if (patch.model) {
133
138
  const base64 = await thumbnail({
@@ -142,20 +147,22 @@ export class BoardMutation {
142
147
  }
143
148
  }
144
149
 
145
- if (patch.groupId !== undefined) {
146
- const groupRepository = tx.getRepository(Group)
147
- board.group =
148
- (await groupRepository.findOneBy({
149
- domain: { id: domain.id },
150
- id: patch.groupId
151
- })) || null
150
+ const { groupId, ...patched } = patch
152
151
 
153
- delete patch.groupId
152
+ if (groupId !== undefined) {
153
+ const groupRepository = tx.getRepository(Group)
154
+ board.group = groupId
155
+ ? (await groupRepository.findOneBy({
156
+ domain: { id: domain.id },
157
+ id: groupId
158
+ })) || null
159
+ : null
154
160
  }
155
161
 
156
162
  const updated = await repository.save({
163
+ domain,
157
164
  ...board,
158
- ...patch,
165
+ ...patched,
159
166
  updater: user
160
167
  })
161
168
 
@@ -179,7 +186,7 @@ export class BoardMutation {
179
186
  const repository = tx.getRepository(Board)
180
187
  const board = await repository.findOneBy({ domain: { id: domain.id }, id })
181
188
 
182
- const deleted = await repository.delete(id)
189
+ const deleted = await repository.softDelete(id)
183
190
 
184
191
  notify &&
185
192
  notify({
@@ -23,7 +23,7 @@ export class NewBoard {
23
23
  @InputType()
24
24
  export class BoardPatch {
25
25
  @Field({ nullable: true })
26
- name: string
26
+ name?: string
27
27
 
28
28
  @Field({ nullable: true })
29
29
  description?: string
@@ -7,7 +7,10 @@ import {
7
7
  ManyToOne,
8
8
  PrimaryGeneratedColumn,
9
9
  RelationId,
10
- UpdateDateColumn
10
+ DeleteDateColumn,
11
+ UpdateDateColumn,
12
+ VersionColumn,
13
+ BeforeUpdate
11
14
  } from 'typeorm'
12
15
  import { Field, ID, ObjectType } from 'type-graphql'
13
16
 
@@ -21,7 +24,10 @@ const ORMCONFIG = config.get('ormconfig', {})
21
24
  const DATABASE_TYPE = ORMCONFIG.type
22
25
 
23
26
  @Entity()
24
- @Index('ix_board_0', (board: Board) => [board.domain, board.name], { unique: true })
27
+ @Index('ix_board_1', (board: Board) => [board.domain, board.name], {
28
+ unique: true,
29
+ where: '"deleted_at" IS NULL'
30
+ })
25
31
  @Index('ix_board_3', (board: Board) => [board.domain, board.group])
26
32
  @ObjectType({ description: 'Entity for Visualization Board' })
27
33
  export class Board {
@@ -29,6 +35,10 @@ export class Board {
29
35
  @Field(type => ID, { nullable: true })
30
36
  readonly id?: string
31
37
 
38
+ @VersionColumn({ nullable: true, default: 1 })
39
+ @Field({ nullable: true })
40
+ version?: number = 1
41
+
32
42
  @ManyToOne(type => Domain)
33
43
  @Field(type => Domain, { nullable: true })
34
44
  domain?: Domain
@@ -38,11 +48,9 @@ export class Board {
38
48
 
39
49
  @Column()
40
50
  @Field()
41
- name: string
51
+ name?: string
42
52
 
43
- @Column({
44
- nullable: true
45
- })
53
+ @Column({ nullable: true })
46
54
  @Field({ nullable: true })
47
55
  description?: string
48
56
 
@@ -102,4 +110,8 @@ export class Board {
102
110
 
103
111
  @RelationId((board: Board) => board.updater)
104
112
  updaterId?: string
113
+
114
+ @DeleteDateColumn()
115
+ @Field({ nullable: true })
116
+ deletedAt?: Date
105
117
  }
@@ -1,8 +1,10 @@
1
1
  import { EventSubscriber, EntitySubscriberInterface, InsertEvent, UpdateEvent } from 'typeorm'
2
2
 
3
+ import { HistoryEntitySubscriber } from '@operato/typeorm-history'
3
4
  import { pubsub, getRepository } from '@things-factory/shell'
4
5
 
5
6
  import { Board } from './board'
7
+ import { BoardHistory } from './board-history'
6
8
 
7
9
  @EventSubscriber()
8
10
  export class BoardSubscriber implements EntitySubscriberInterface<Board> {
@@ -10,13 +12,13 @@ export class BoardSubscriber implements EntitySubscriberInterface<Board> {
10
12
  return Board
11
13
  }
12
14
 
13
- // afterInsert(event: InsertEvent<Board>): Promise<any> | void {
14
- // const board = event.entity
15
+ async beforeUpdate(event: UpdateEvent<Board>): Promise<any> {
16
+ var board = event.entity
15
17
 
16
- // pubsub.publish('board', {
17
- // board
18
- // })
19
- // }
18
+ if (!board.version) {
19
+ board.version = 1
20
+ }
21
+ }
20
22
 
21
23
  async afterUpdate(event: UpdateEvent<Board>): Promise<any> {
22
24
  var board = event.entity
@@ -37,3 +39,14 @@ export class BoardSubscriber implements EntitySubscriberInterface<Board> {
37
39
  })
38
40
  }
39
41
  }
42
+
43
+ @EventSubscriber()
44
+ export class BoardHistoryEntitySubscriber extends HistoryEntitySubscriber<Board, BoardHistory> {
45
+ public get entity() {
46
+ return Board
47
+ }
48
+
49
+ public get historyEntity() {
50
+ return BoardHistory
51
+ }
52
+ }
@@ -1,9 +1,10 @@
1
1
  import { Board } from './board'
2
+ import { BoardHistory } from './board-history'
2
3
  import { BoardQuery } from './board-query'
3
4
  import { BoardMutation } from './board-mutation'
4
5
  import { BoardSubscription } from './board-subscription'
5
- import { BoardSubscriber } from './event-subscriber'
6
+ import { BoardSubscriber, BoardHistoryEntitySubscriber } from './event-subscriber'
6
7
 
7
- export const entities = [Board]
8
+ export const entities = [Board, BoardHistory]
8
9
  export const resolvers = [BoardQuery, BoardMutation, BoardSubscription]
9
- export const subscribers = [BoardSubscriber]
10
+ export const subscribers = [BoardSubscriber, BoardHistoryEntitySubscriber]