@things-factory/dataset 5.0.0-zeta.9 → 5.0.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.
Files changed (65) hide show
  1. package/README.md +25 -0
  2. package/assets/data-samples.jpg +0 -0
  3. package/client/{pages/data-entry → components}/data-entry-form.js +1 -1
  4. package/client/index.js +1 -0
  5. package/client/pages/data-entry/data-entry-list-page.js +2 -2
  6. package/client/pages/data-ooc/data-ooc-list-page.js +12 -17
  7. package/client/pages/data-report/data-report-list-page.js +1 -1
  8. package/client/pages/data-sample/data-sample-list-page.js +11 -12
  9. package/client/pages/data-sensor/data-sensor-list-page.js +1 -1
  10. package/client/pages/data-set/data-set-list-page.js +3 -2
  11. package/config/config.development.js +1 -1
  12. package/config/config.production.js +13 -1
  13. package/dist-server/controllers/create-data-sample.js +4 -37
  14. package/dist-server/controllers/create-data-sample.js.map +1 -1
  15. package/dist-server/controllers/data-use-case.js +11 -5
  16. package/dist-server/controllers/data-use-case.js.map +1 -1
  17. package/dist-server/controllers/jasper-report.js +14 -9
  18. package/dist-server/controllers/jasper-report.js.map +1 -1
  19. package/dist-server/service/data-ooc/data-ooc-query.js +4 -17
  20. package/dist-server/service/data-ooc/data-ooc-query.js.map +1 -1
  21. package/dist-server/service/data-ooc/data-ooc.js +7 -15
  22. package/dist-server/service/data-ooc/data-ooc.js.map +1 -1
  23. package/dist-server/service/data-sample/data-sample-query.js +4 -4
  24. package/dist-server/service/data-sample/data-sample-query.js.map +1 -1
  25. package/dist-server/service/data-sample/data-sample.js +7 -3
  26. package/dist-server/service/data-sample/data-sample.js.map +1 -1
  27. package/dist-server/service/data-set/data-set-mutation.js +13 -30
  28. package/dist-server/service/data-set/data-set-mutation.js.map +1 -1
  29. package/dist-server/service/data-set/data-set-query.js +3 -2
  30. package/dist-server/service/data-set/data-set-query.js.map +1 -1
  31. package/dist-server/service/data-set/data-set-type.js +12 -9
  32. package/dist-server/service/data-set/data-set-type.js.map +1 -1
  33. package/dist-server/service/data-set/data-set.js +1 -4
  34. package/dist-server/service/data-set/data-set.js.map +1 -1
  35. package/dist-server/service/data-set-history/data-set-history-query.js +4 -2
  36. package/dist-server/service/data-set-history/data-set-history-query.js.map +1 -1
  37. package/dist-server/service/data-set-history/data-set-history.js +46 -55
  38. package/dist-server/service/data-set-history/data-set-history.js.map +1 -1
  39. package/dist-server/service/data-set-history/event-subscriber.js +26 -0
  40. package/dist-server/service/data-set-history/event-subscriber.js.map +1 -0
  41. package/dist-server/service/data-set-history/index.js +3 -1
  42. package/dist-server/service/data-set-history/index.js.map +1 -1
  43. package/dist-server/service/index.js +5 -1
  44. package/dist-server/service/index.js.map +1 -1
  45. package/package.json +18 -18
  46. package/server/controllers/create-data-sample.ts +5 -37
  47. package/server/controllers/data-use-case.ts +17 -6
  48. package/server/controllers/jasper-report.ts +58 -48
  49. package/server/service/data-ooc/data-ooc-query.ts +3 -11
  50. package/server/service/data-ooc/data-ooc.ts +6 -16
  51. package/server/service/data-sample/data-sample-query.ts +3 -3
  52. package/server/service/data-sample/data-sample.ts +6 -4
  53. package/server/service/data-set/data-set-mutation.ts +8 -39
  54. package/server/service/data-set/data-set-query.ts +3 -2
  55. package/server/service/data-set/data-set-type.ts +2 -1
  56. package/server/service/data-set/data-set.ts +3 -5
  57. package/server/service/data-set-history/data-set-history-query.ts +4 -2
  58. package/server/service/data-set-history/data-set-history.ts +61 -60
  59. package/server/service/data-set-history/event-subscriber.ts +17 -0
  60. package/server/service/data-set-history/index.ts +2 -0
  61. package/server/service/index.ts +10 -1
  62. package/translations/en.json +1 -1
  63. package/translations/ko.json +2 -2
  64. package/translations/ms.json +1 -1
  65. package/translations/zh.json +1 -1
@@ -6,47 +6,53 @@ import { AthenaController } from '@things-factory/aws-base'
6
6
  import { config } from '@things-factory/env'
7
7
 
8
8
  const dataReportConfig = config.get('dataReport')
9
- const { jasper: {
10
- endpoint: { protocol: PROTOCOL, host:HOST, port:PORT },
11
- datasource: { database: DATABASE } }
12
- } = dataReportConfig
9
+ const {
10
+ jasper: {
11
+ endpoint: { protocol: PROTOCOL, host: HOST, port: PORT },
12
+ datasource: { database: DATABASE }
13
+ }
14
+ } = dataReportConfig || {
15
+ jasper: {
16
+ endpoint: {},
17
+ datasource: {}
18
+ }
19
+ }
13
20
 
14
- /** author: ywnam123 */
15
21
  function transformValuesToRows(queryResult) {
16
22
  var parseData = []
17
- let index = 1
18
- for (let i = 0; i < queryResult.Items.length; i++) {
19
- var j = 0
20
- const data = JSON.parse(queryResult.Items[i].data)
21
- const spec = JSON.parse(queryResult.Items[i].spec)
22
-
23
- for (let key in data) {
24
- if (Array.isArray(data[key])) {
25
- for (j = 0; j < data[key].length; j++) {
26
- for (let specKey in spec) {
27
- if (key === specKey) {
28
- parseData.push({
29
- item: spec[specKey].name,
30
- index: index + j,
31
- value: String(data[key][j])
32
- })
33
- }
23
+ let index = 1
24
+ for (let i = 0; i < queryResult.Items.length; i++) {
25
+ var j = 0
26
+ const data = JSON.parse(queryResult.Items[i].data)
27
+ const spec = JSON.parse(queryResult.Items[i].spec)
28
+
29
+ for (let key in data) {
30
+ if (Array.isArray(data[key])) {
31
+ for (j = 0; j < data[key].length; j++) {
32
+ for (let specKey in spec) {
33
+ if (key === specKey) {
34
+ parseData.push({
35
+ item: spec[specKey].name,
36
+ index: index + j,
37
+ value: String(data[key][j])
38
+ })
34
39
  }
35
40
  }
36
- } else {
37
- parseData.push({
38
- item: key,
39
- index,
40
- value: String(data[key])
41
- })
42
41
  }
43
- }
44
- if (j !== 0) {
45
- index = index + j
46
42
  } else {
47
- index = index + 1
43
+ parseData.push({
44
+ item: key,
45
+ index,
46
+ value: String(data[key])
47
+ })
48
48
  }
49
49
  }
50
+ if (j !== 0) {
51
+ index = index + j
52
+ } else {
53
+ index = index + 1
54
+ }
55
+ }
50
56
  }
51
57
 
52
58
  /** @todo considering trasformation in lambda, as massive dataset */
@@ -61,11 +67,12 @@ function pivotData(rows) {
61
67
  for (let key in data) {
62
68
  /** @todo rule to display or not, about unspecified spec */
63
69
  const value = data[key]
64
- !(spec[key]?.hidden) && parsedData.push({
65
- item: spec[key]?.name || key,
66
- index,
67
- value: Array.isArray(value) ? value.join(', ') : value
68
- })
70
+ !spec[key]?.hidden &&
71
+ parsedData.push({
72
+ item: spec[key]?.name || key,
73
+ index,
74
+ value: Array.isArray(value) ? value.join(', ') : value
75
+ })
69
76
  }
70
77
  if (j !== 0) {
71
78
  index = index + j
@@ -95,6 +102,7 @@ function parseJsonDataField(rows) {
95
102
  }
96
103
 
97
104
  const athenaClient = new AthenaController()
105
+
98
106
  async function queryAthena(params) {
99
107
  const { table, domain, dataSetId, fromWorkDate, toWorkDate, workShift, timezone } = params
100
108
  const queryData = {
@@ -108,7 +116,7 @@ async function queryAthena(params) {
108
116
  AND datasetid = '${dataSetId}'
109
117
  AND workdate >= '${fromWorkDate}'
110
118
  AND workdate <= '${toWorkDate}'
111
- ${workShift ? 'AND workshift = \'' + workShift + '\'' : ''}
119
+ ${workShift ? "AND workshift = '" + workShift + "'" : ''}
112
120
  ORDER BY collected_at`,
113
121
  db: DATABASE
114
122
  }
@@ -116,19 +124,23 @@ async function queryAthena(params) {
116
124
 
117
125
  return await athenaClient.query(queryData)
118
126
  }
119
- export async function renderJasperReport(context: any) {
120
- const { state: { domain }, query } = context
127
+
128
+ export async function renderJasperReport(context: any) {
129
+ const {
130
+ state: { domain },
131
+ query
132
+ } = context
121
133
 
122
134
  const template = await STORAGE.readFile(query['template'] || 'dynamic_header_sample.jrxml', 'utf-8')
123
135
  let templateType = query['templateType'] || 'crosstab'
124
136
  let parsedData = []
125
137
 
126
138
  // @todo: get dataset timezone
127
- /**
139
+ /**
128
140
  * const variables = await gql(dataSet(id:${dataSetId}) {
129
141
  * name, description, partition_keys, timezone
130
142
  * })
131
- */
143
+ */
132
144
 
133
145
  query['domain'] = domain?.subdomain
134
146
  query['timezone'] = domain?.timezone
@@ -137,8 +149,7 @@ export async function renderJasperReport(context: any) {
137
149
 
138
150
  if (!rows.length) {
139
151
  return '<h3>Not found result.</h3>'
140
- }
141
- else {
152
+ } else {
142
153
  const firstRow = rows[0]
143
154
  // uses the first row values as data-set has no history data.
144
155
  const parameters = {
@@ -146,18 +157,18 @@ export async function renderJasperReport(context: any) {
146
157
  description: firstRow.description,
147
158
  ...query
148
159
  }
149
-
160
+
150
161
  if (templateType === 'crosstab') {
151
162
  parsedData = pivotData(rows)
152
163
  } else {
153
164
  parsedData = parseJsonDataField(rows)
154
165
  }
155
-
166
+
156
167
  const formData = new FormData()
157
168
  formData.append('template', template)
158
169
  formData.append('jsonString', JSON.stringify(parsedData))
159
170
  formData.append('parameters', JSON.stringify(parameters))
160
-
171
+
161
172
  const reportUrl = `${PROTOCOL || 'http'}://${HOST}:${PORT}/rest/report/show_html`
162
173
  const response = await fetch(reportUrl, {
163
174
  method: 'POST',
@@ -166,5 +177,4 @@ export async function renderJasperReport(context: any) {
166
177
 
167
178
  return await response.text()
168
179
  }
169
-
170
180
  }
@@ -4,7 +4,6 @@ import { getRepository } from 'typeorm'
4
4
  import { User } from '@things-factory/auth-base'
5
5
  import { Domain, getQueryBuilderFromListParams, ListParam } from '@things-factory/shell'
6
6
 
7
- import { DataSample } from '../data-sample/data-sample'
8
7
  import { DataSetHistory } from '../data-set-history/data-set-history'
9
8
  import { DataItem } from '../data-set/data-item-type'
10
9
  import { DataSet } from '../data-set/data-set'
@@ -41,14 +40,14 @@ export class DataOocQuery {
41
40
  }
42
41
 
43
42
  @FieldResolver(type => [DataItem])
44
- async spec(@Root() dataOoc: DataOoc): Promise<[DataItem]> {
43
+ async dataItems(@Root() dataOoc: DataOoc): Promise<DataItem[]> {
45
44
  const dataSetHistory: DataSetHistory = await getRepository(DataSetHistory).findOne({
46
45
  where: {
47
- id: dataOoc.dataSetId,
46
+ originalId: dataOoc.dataSetId,
48
47
  version: dataOoc.dataSetVersion
49
48
  }
50
49
  })
51
- return dataSetHistory?.dataItems || dataOoc.spec || []
50
+ return dataSetHistory?.dataItems || []
52
51
  }
53
52
 
54
53
  @FieldResolver(type => DataSet)
@@ -58,13 +57,6 @@ export class DataOocQuery {
58
57
  })
59
58
  }
60
59
 
61
- @FieldResolver(type => DataSample)
62
- async dataSample(@Root() dataOoc: DataOoc): Promise<DataSample> {
63
- return await getRepository(DataSample).findOne({
64
- id: dataOoc.dataSampleId
65
- })
66
- }
67
-
68
60
  @FieldResolver(type => Domain)
69
61
  async domain(@Root() dataOoc: DataOoc): Promise<Domain> {
70
62
  return await getRepository(Domain).findOne(dataOoc.domainId)
@@ -4,9 +4,7 @@ import {
4
4
  CreateDateColumn,
5
5
  Entity,
6
6
  Index,
7
- JoinColumn,
8
7
  ManyToOne,
9
- OneToOne,
10
8
  PrimaryGeneratedColumn,
11
9
  RelationId,
12
10
  UpdateDateColumn
@@ -16,7 +14,7 @@ import { User } from '@things-factory/auth-base'
16
14
  import { config } from '@things-factory/env'
17
15
  import { Domain, ScalarObject } from '@things-factory/shell'
18
16
 
19
- import { DataSample } from '../data-sample/data-sample'
17
+ import { DataItem } from '../data-set/data-item-type'
20
18
  import { DataSet } from '../data-set/data-set'
21
19
 
22
20
  const ORMCONFIG = config.get('ormconfig', {})
@@ -34,9 +32,7 @@ registerEnumType(DataOocStatus, {
34
32
  })
35
33
 
36
34
  @Entity()
37
- @Index('ix_data_ooc_0', (dataOoc: DataOoc) => [dataOoc.domain, dataOoc.dataSet], { unique: false })
38
- @Index('ix_data_ooc_1', (dataOoc: DataOoc) => [dataOoc.domain, dataOoc.dataSample], { unique: true })
39
- @Index('ix_data_ooc_2', (dataOoc: DataOoc) => [dataOoc.domain, dataOoc.collectedAt], { unique: false })
35
+ @Index('ix_data_ooc_0', (dataOoc: DataOoc) => [dataOoc.domain, dataOoc.dataSet, dataOoc.collectedAt], { unique: false })
40
36
  @ObjectType({ description: 'Entity for Out of control data' })
41
37
  export class DataOoc {
42
38
  @PrimaryGeneratedColumn('uuid')
@@ -71,14 +67,6 @@ export class DataOoc {
71
67
  @Field({ nullable: true })
72
68
  dataSetVersion?: number
73
69
 
74
- @OneToOne(type => DataSample)
75
- @JoinColumn()
76
- @Field(type => DataSample, { nullable: true })
77
- dataSample?: DataSample
78
-
79
- @RelationId((dataOoc: DataOoc) => dataOoc.dataSample)
80
- dataSampleId?: string
81
-
82
70
  @Column({
83
71
  nullable: true
84
72
  })
@@ -129,10 +117,12 @@ export class DataOoc {
129
117
  @Field(type => ScalarObject, { nullable: true })
130
118
  data?: ScalarObject
131
119
 
132
- // TODO spec should be removed
133
120
  @Column('simple-json', { nullable: true })
134
121
  @Field(type => ScalarObject, { nullable: true })
135
- spec?: ScalarObject
122
+ judgment?: ScalarObject
123
+
124
+ @Field(type => [DataItem], { nullable: true })
125
+ dataItems?: DataItem[]
136
126
 
137
127
  @Column('simple-json', { nullable: true })
138
128
  @Field(type => ScalarObject, { nullable: true })
@@ -40,14 +40,14 @@ export class DataSampleQuery {
40
40
  }
41
41
 
42
42
  @FieldResolver(type => [DataItem])
43
- async spec(@Root() dataSample: DataSample): Promise<[DataItem]> {
43
+ async dataItems(@Root() dataSample: DataSample): Promise<DataItem[]> {
44
44
  const dataSetHistory: DataSetHistory = await getRepository(DataSetHistory).findOne({
45
45
  where: {
46
- id: dataSample.dataSetId,
46
+ originalId: dataSample.dataSetId,
47
47
  version: dataSample.dataSetVersion
48
48
  }
49
49
  })
50
- return dataSetHistory?.dataItems || dataSample.spec || []
50
+ return dataSetHistory?.dataItems || []
51
51
  }
52
52
 
53
53
  @FieldResolver(type => DataSet)
@@ -14,14 +14,14 @@ import { User } from '@things-factory/auth-base'
14
14
  import { config } from '@things-factory/env'
15
15
  import { Domain, ScalarObject } from '@things-factory/shell'
16
16
 
17
+ import { DataItem } from '../data-set/data-item-type'
17
18
  import { DataSet } from '../data-set/data-set'
18
19
 
19
20
  const ORMCONFIG = config.get('ormconfig', {})
20
21
  const DATABASE_TYPE = ORMCONFIG.type
21
22
  @Entity()
22
- @Index('ix_data_sample_0', (dataSample: DataSample) => [dataSample.domain, dataSample.dataSet], { unique: false })
23
23
  @Index(
24
- 'ix_data_sample_2',
24
+ 'ix_data_sample_0',
25
25
  (dataSample: DataSample) => [dataSample.domain, dataSample.dataSet, dataSample.collectedAt],
26
26
  { unique: false }
27
27
  )
@@ -79,10 +79,12 @@ export class DataSample {
79
79
  @Field(type => ScalarObject, { nullable: true })
80
80
  data?: ScalarObject
81
81
 
82
- // TODO spec should be removed
83
82
  @Column('simple-json', { nullable: true })
84
83
  @Field(type => ScalarObject, { nullable: true })
85
- spec?: ScalarObject
84
+ judgment?: ScalarObject
85
+
86
+ @Field(type => [DataItem], { nullable: true })
87
+ dataItems?: DataItem[]
86
88
 
87
89
  @Column({
88
90
  nullable: true,
@@ -3,7 +3,6 @@ import { In } from 'typeorm'
3
3
 
4
4
  import { createAttachment, deleteAttachmentsByRef } from '@things-factory/attachment-base'
5
5
 
6
- import { DataSetHistory } from '../data-set-history/data-set-history'
7
6
  import { DataSet } from './data-set'
8
7
  import { DataSetPatch, NewDataSet } from './data-set-type'
9
8
 
@@ -17,7 +16,6 @@ export class DataSetMutation {
17
16
  async createDataSet(@Arg('dataSet') dataSet: NewDataSet, @Ctx() context: any): Promise<DataSet> {
18
17
  const { domain, user, tx } = context.state
19
18
  const dataSetRepo = tx.getRepository(DataSet)
20
- const dataSetHistoryRepo = tx.getRepository(DataSetHistory)
21
19
 
22
20
  const result = await dataSetRepo.save({
23
21
  ...dataSet,
@@ -27,13 +25,7 @@ export class DataSetMutation {
27
25
  updater: user
28
26
  })
29
27
 
30
- await this._createAttachment(context, dataSet.reportTemplate, { refId: result.id, cuFlag: '+' })
31
-
32
- await dataSetHistoryRepo.save(
33
- await dataSetRepo.findOne(result.id, {
34
- relations: ['domain', 'creator', 'updater', 'supervisoryRole', 'entryRole']
35
- })
36
- )
28
+ await this._createAttachment(context, dataSet.reportTemplate, { ref: result, cuFlag: '+' })
37
29
 
38
30
  return result
39
31
  }
@@ -44,7 +36,6 @@ export class DataSetMutation {
44
36
  async updateDataSet(@Arg('id') id: string, @Arg('patch') patch: DataSetPatch, @Ctx() context: any): Promise<DataSet> {
45
37
  const { domain, user, tx } = context.state
46
38
  const dataSetRepo = tx.getRepository(DataSet)
47
- const dataSetHistoryRepo = tx.getRepository(DataSetHistory)
48
39
 
49
40
  const dataSet = await dataSetRepo.findOne({
50
41
  where: { domain, id }
@@ -53,17 +44,10 @@ export class DataSetMutation {
53
44
  const result = await dataSetRepo.save({
54
45
  ...dataSet,
55
46
  ...patch,
56
- version: (dataSet.version || 0) + 1,
57
47
  updater: user
58
48
  })
59
49
 
60
- await this._createAttachment(context, dataSet.reportTemplate, { refId: result.id, cuFlag: 'M' })
61
-
62
- await dataSetHistoryRepo.save(
63
- await dataSetRepo.findOne(id, {
64
- relations: ['domain', 'creator', 'updater', 'supervisoryRole', 'entryRole']
65
- })
66
- )
50
+ await this._createAttachment(context, dataSet.reportTemplate, { ref: result, cuFlag: 'M' })
67
51
 
68
52
  return result
69
53
  }
@@ -77,7 +61,6 @@ export class DataSetMutation {
77
61
  ): Promise<DataSet[]> {
78
62
  const { domain, user, tx } = context.state
79
63
  const dataSetRepo = tx.getRepository(DataSet)
80
- const dataSetHistoryRepo = tx.getRepository(DataSetHistory)
81
64
 
82
65
  let results = []
83
66
  const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
@@ -90,13 +73,12 @@ export class DataSetMutation {
90
73
 
91
74
  const result = await dataSetRepo.save({
92
75
  ...newRecord,
93
- version: 1,
94
76
  domain,
95
77
  creator: user,
96
78
  updater: user
97
79
  })
98
80
 
99
- await this._createAttachment(context, newRecord.reportTemplate, { refId: result.id, cuFlag })
81
+ await this._createAttachment(context, newRecord.reportTemplate, { ref: result, cuFlag })
100
82
 
101
83
  results.push({
102
84
  ...(await dataSetRepo.findOne(result.id, {
@@ -116,11 +98,10 @@ export class DataSetMutation {
116
98
  const result = await dataSetRepo.save({
117
99
  ...dataSet,
118
100
  ...newRecord,
119
- version: (dataSet.version || 0) + 1,
120
101
  updater: user
121
102
  })
122
103
 
123
- await this._createAttachment(context, newRecord.reportTemplate, { refId: result.id, cuFlag })
104
+ await this._createAttachment(context, newRecord.reportTemplate, { ref: result, cuFlag })
124
105
 
125
106
  results.push({
126
107
  ...(await dataSetRepo.findOne(result.id, {
@@ -131,8 +112,6 @@ export class DataSetMutation {
131
112
  }
132
113
  }
133
114
 
134
- results.forEach(result => dataSetHistoryRepo.save({ ...result }))
135
-
136
115
  return results
137
116
  }
138
117
 
@@ -172,20 +151,13 @@ export class DataSetMutation {
172
151
  ): Promise<boolean> {
173
152
  const { domain, tx } = context.state
174
153
  const dataSetRepo = tx.getRepository(DataSet)
175
- const dataSetHistoryRepo = tx.getRepository(DataSetHistory)
176
154
 
177
155
  await Promise.all(
178
156
  dataSets.map(async (dataSet: DataSet) => {
179
157
  const createdDataSet: DataSet = await dataSetRepo.save({
180
158
  domain,
181
- version: 1 /* overridable by dataSet's origin value */,
182
159
  ...dataSet
183
160
  })
184
- await dataSetHistoryRepo.save(
185
- ...(await dataSetRepo.findOne(createdDataSet.id, {
186
- relations: ['domain', 'creator', 'updater', 'supervisoryRole', 'entryRole']
187
- }))
188
- )
189
161
  })
190
162
  )
191
163
 
@@ -198,7 +170,6 @@ export class DataSetMutation {
198
170
  async copyDataSets(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<DataSet[]> {
199
171
  const { domain, user, tx } = context.state
200
172
  const dataSetRepo = tx.getRepository(DataSet)
201
- const dataSetHistoryRepo = tx.getRepository(DataSetHistory)
202
173
 
203
174
  const originals = await dataSetRepo.find({
204
175
  where: {
@@ -220,7 +191,6 @@ export class DataSetMutation {
220
191
  id: dataSetId,
221
192
  name: dataSet.name + ' (' + dataSetId + ')',
222
193
  active: false,
223
- version: 1,
224
194
  domain,
225
195
  creator: user,
226
196
  updater: user
@@ -228,21 +198,20 @@ export class DataSetMutation {
228
198
  })
229
199
 
230
200
  var copiedDataSets = await dataSetRepo.save(newCopys)
231
- await dataSetHistoryRepo.save(copiedDataSets)
232
201
 
233
202
  return copiedDataSets
234
203
  }
235
204
 
236
- async _createAttachment(context, attachment, { refId, cuFlag }) {
205
+ async _createAttachment(context, attachment, { ref, cuFlag }) {
237
206
  if (attachment) {
238
- const attachmentRef = 'report-' + refId
239
- cuFlag == 'M' && (await deleteAttachmentsByRef(null, { refBys: [attachmentRef] }, context))
207
+ cuFlag == 'M' && (await deleteAttachmentsByRef(null, { refBys: [ref.id] }, context))
240
208
  await createAttachment(
241
209
  null,
242
210
  {
243
211
  attachment: {
244
212
  file: attachment,
245
- refBy: attachmentRef
213
+ refType: `${DataSet.name}-report-template`,
214
+ refBy: ref.id
246
215
  }
247
216
  },
248
217
  context
@@ -103,7 +103,7 @@ export class DataSetQuery {
103
103
 
104
104
  @FieldResolver(type => [DataItem])
105
105
  async dataItems(@Root() dataSet: DataSet): Promise<DataItem[]> {
106
- /* TODO This fieldResolver should be removed. This is only for migration temporarily */
106
+ /* TODO this fieldResolver should be removed. This is only for migration temporarily */
107
107
  if (dataSet.dataItems) {
108
108
  return dataSet.dataItems as DataItem[]
109
109
  }
@@ -208,7 +208,8 @@ export class DataSetQuery {
208
208
  const attachment: Attachment = await getRepository(Attachment).findOne({
209
209
  where: {
210
210
  domain: dataset.domainId,
211
- refBy: `report-${dataset.id}`
211
+ refType: `${DataSet.name}-report-template`,
212
+ refBy: dataset.id
212
213
  }
213
214
  })
214
215
 
@@ -1,4 +1,5 @@
1
- import { FileUpload, GraphQLUpload } from 'graphql-upload'
1
+ import type { FileUpload } from 'graphql-upload/GraphQLUpload.js'
2
+ import GraphQLUpload from 'graphql-upload/GraphQLUpload.js'
2
3
  import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
3
4
 
4
5
  import { ObjectRef, ScalarObject } from '@things-factory/shell'
@@ -7,7 +7,8 @@ import {
7
7
  ManyToOne,
8
8
  PrimaryGeneratedColumn,
9
9
  RelationId,
10
- UpdateDateColumn
10
+ UpdateDateColumn,
11
+ VersionColumn
11
12
  } from 'typeorm'
12
13
 
13
14
  import { Role, User } from '@things-factory/auth-base'
@@ -76,10 +77,7 @@ export class DataSet {
76
77
  @Field({ nullable: true })
77
78
  description?: string
78
79
 
79
- @Column({
80
- nullable: true,
81
- default: 1
82
- })
80
+ @VersionColumn({ nullable: true, default: 1 })
83
81
  @Field({ nullable: true })
84
82
  version?: number = 1
85
83
 
@@ -6,6 +6,7 @@ import { Role, User } from '@things-factory/auth-base'
6
6
  import { Board } from '@things-factory/board-service'
7
7
  import { Domain, getQueryBuilderFromListParams, ListParam, ScalarDate } from '@things-factory/shell'
8
8
 
9
+ import { DataSet } from '../data-set/data-set'
9
10
  import { DataSetHistory } from './data-set-history'
10
11
  import { DataSetHistoryList } from './data-set-history-type'
11
12
 
@@ -21,7 +22,7 @@ export class DataSetHistoryQuery {
21
22
  const { domain } = context.state
22
23
 
23
24
  return await getRepository(DataSetHistory).findOne({
24
- where: { domain, id, updatedAt: timestamp }
25
+ where: { domain, originalId: id, updatedAt: timestamp }
25
26
  })
26
27
  }
27
28
 
@@ -101,7 +102,8 @@ export class DataSetHistoryQuery {
101
102
  const attachment: Attachment = await getRepository(Attachment).findOne({
102
103
  where: {
103
104
  domain: dataSetHistory.domainId,
104
- refBy: `report-${dataSetHistory.id}`
105
+ refType: `${DataSet.name}-report-template`,
106
+ refBy: dataSetHistory.originalId
105
107
  }
106
108
  })
107
109