@things-factory/dataset 5.0.0-y.0 → 5.0.0-zeta.10
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/client/bootstrap.js +2 -3
- package/client/pages/data-entry/data-entry-list-page.js +1 -35
- package/client/pages/data-ooc/data-ooc-list-page.js +11 -83
- package/client/pages/data-ooc/data-ooc-view.js +19 -14
- package/client/pages/data-report/data-report-list-page.js +1 -35
- package/client/pages/data-sample/data-sample-list-page.js +11 -26
- package/client/pages/data-sample/data-sample-view.js +3 -2
- package/client/pages/data-sensor/data-sensor-list-page.js +0 -4
- package/client/pages/data-set/data-item-list.js +32 -98
- package/client/pages/data-set/data-set-list-page.js +0 -5
- package/dist-server/controllers/create-data-sample.js +10 -44
- package/dist-server/controllers/create-data-sample.js.map +1 -1
- package/dist-server/controllers/data-use-case.js +11 -5
- package/dist-server/controllers/data-use-case.js.map +1 -1
- package/dist-server/controllers/index.js +1 -1
- package/dist-server/controllers/index.js.map +1 -1
- package/dist-server/service/data-item/index.js +1 -4
- package/dist-server/service/data-item/index.js.map +1 -1
- package/dist-server/service/data-ooc/data-ooc-query.js +15 -10
- package/dist-server/service/data-ooc/data-ooc-query.js.map +1 -1
- package/dist-server/service/data-ooc/data-ooc-type.js +4 -0
- package/dist-server/service/data-ooc/data-ooc-type.js.map +1 -1
- package/dist-server/service/data-ooc/data-ooc.js +11 -14
- package/dist-server/service/data-ooc/data-ooc.js.map +1 -1
- package/dist-server/service/data-sample/data-sample-query.js +18 -0
- package/dist-server/service/data-sample/data-sample-query.js.map +1 -1
- package/dist-server/service/data-sample/data-sample-type.js +4 -0
- package/dist-server/service/data-sample/data-sample-type.js.map +1 -1
- package/dist-server/service/data-sample/data-sample.js +12 -3
- package/dist-server/service/data-sample/data-sample.js.map +1 -1
- package/dist-server/service/{data-item → data-set}/data-item-type.js +60 -33
- package/dist-server/service/data-set/data-item-type.js.map +1 -0
- package/dist-server/service/data-set/data-set-mutation.js +40 -63
- package/dist-server/service/data-set/data-set-mutation.js.map +1 -1
- package/dist-server/service/data-set/data-set-query.js +15 -10
- package/dist-server/service/data-set/data-set-query.js.map +1 -1
- package/dist-server/service/data-set/data-set-type.js +10 -1
- package/dist-server/service/data-set/data-set-type.js.map +1 -1
- package/dist-server/service/data-set/data-set.js +14 -3
- package/dist-server/service/data-set/data-set.js.map +1 -1
- package/dist-server/service/data-set-history/data-set-history-query.js +173 -0
- package/dist-server/service/data-set-history/data-set-history-query.js.map +1 -0
- package/dist-server/service/data-set-history/data-set-history-type.js +29 -0
- package/dist-server/service/data-set-history/data-set-history-type.js.map +1 -0
- package/dist-server/service/data-set-history/data-set-history.js +205 -0
- package/dist-server/service/data-set-history/data-set-history.js.map +1 -0
- package/dist-server/service/data-set-history/index.js +8 -0
- package/dist-server/service/data-set-history/index.js.map +1 -0
- package/dist-server/service/index.js +6 -3
- package/dist-server/service/index.js.map +1 -1
- package/package.json +18 -17
- package/server/controllers/create-data-sample.ts +12 -49
- package/server/controllers/data-use-case.ts +19 -7
- package/server/controllers/index.ts +1 -1
- package/server/service/data-item/index.ts +0 -3
- package/server/service/data-ooc/data-ooc-query.ts +13 -8
- package/server/service/data-ooc/data-ooc-type.ts +3 -0
- package/server/service/data-ooc/data-ooc.ts +9 -14
- package/server/service/data-sample/data-sample-query.ts +14 -1
- package/server/service/data-sample/data-sample-type.ts +3 -0
- package/server/service/data-sample/data-sample.ts +10 -3
- package/server/service/data-set/data-item-type.ts +82 -0
- package/server/service/data-set/data-set-mutation.ts +64 -60
- package/server/service/data-set/data-set-query.ts +14 -12
- package/server/service/data-set/data-set-type.ts +8 -1
- package/server/service/data-set/data-set.ts +9 -3
- package/server/service/data-set-history/data-set-history-query.ts +110 -0
- package/server/service/data-set-history/data-set-history-type.ts +12 -0
- package/server/service/data-set-history/data-set-history.ts +160 -0
- package/server/service/data-set-history/index.ts +5 -0
- package/server/service/index.ts +7 -4
- package/translations/en.json +4 -4
- package/translations/ko.json +10 -10
- package/translations/ms.json +4 -4
- package/translations/zh.json +4 -4
- package/dist-server/service/data-item/data-item-mutation.js +0 -73
- package/dist-server/service/data-item/data-item-mutation.js.map +0 -1
- package/dist-server/service/data-item/data-item-query.js +0 -104
- package/dist-server/service/data-item/data-item-query.js.map +0 -1
- package/dist-server/service/data-item/data-item-type.js.map +0 -1
- package/server/service/data-item/data-item-mutation.ts +0 -61
- package/server/service/data-item/data-item-query.ts +0 -58
- package/server/service/data-item/data-item-type.ts +0 -57
@@ -1,4 +1,5 @@
|
|
1
|
-
import { DataItem
|
1
|
+
import { DataItem } from '../service/data-set/data-item-type'
|
2
|
+
import { DataSet } from '../service/data-set/data-set'
|
2
3
|
|
3
4
|
export type DataItemSpec = {
|
4
5
|
type: string
|
@@ -13,7 +14,11 @@ export type DataItemSpecSet = {
|
|
13
14
|
specs: DataItemSpec[]
|
14
15
|
}
|
15
16
|
|
16
|
-
export type EvaluationResult = {
|
17
|
+
export type EvaluationResult = {
|
18
|
+
oos: boolean
|
19
|
+
ooc: boolean
|
20
|
+
judgment?: { [tag: string]: { ooc: boolean; oos: boolean } }
|
21
|
+
}
|
17
22
|
|
18
23
|
export abstract class DataUseCase {
|
19
24
|
static registry: { [name: string]: DataUseCase } = {}
|
@@ -33,6 +38,7 @@ export abstract class DataUseCase {
|
|
33
38
|
public static evaluate(dataSet: DataSet, dataItems: DataItem[], data: any): EvaluationResult {
|
34
39
|
var ooc = false
|
35
40
|
var oos = false
|
41
|
+
var judgment: { [tag: string]: { ooc: boolean; oos: boolean } } = {}
|
36
42
|
|
37
43
|
if (!dataSet.useCase) {
|
38
44
|
return { ooc, oos }
|
@@ -49,7 +55,7 @@ export abstract class DataUseCase {
|
|
49
55
|
}
|
50
56
|
|
51
57
|
let values: any | any[] = data[tag]
|
52
|
-
if (
|
58
|
+
if (values == null) {
|
53
59
|
continue // TODO what if in case no value ?
|
54
60
|
}
|
55
61
|
|
@@ -57,6 +63,9 @@ export abstract class DataUseCase {
|
|
57
63
|
values = [values]
|
58
64
|
}
|
59
65
|
|
66
|
+
let oocForTag = false
|
67
|
+
let oosForTag = false
|
68
|
+
|
60
69
|
for (let j = 0; j < useCases.length; j++) {
|
61
70
|
const useCase = useCases[j]
|
62
71
|
|
@@ -68,17 +77,20 @@ export abstract class DataUseCase {
|
|
68
77
|
const result = useCase.evaluate(specs, values)
|
69
78
|
|
70
79
|
if (result) {
|
80
|
+
oocForTag ||= result.ooc
|
81
|
+
oosForTag ||= result.oos
|
71
82
|
ooc ||= result.ooc
|
72
83
|
oos ||= result.oos
|
73
84
|
}
|
85
|
+
}
|
74
86
|
|
75
|
-
|
76
|
-
|
77
|
-
|
87
|
+
judgment[tag] = {
|
88
|
+
ooc: oocForTag,
|
89
|
+
oos: oosForTag
|
78
90
|
}
|
79
91
|
}
|
80
92
|
|
81
|
-
return { ooc, oos }
|
93
|
+
return { ooc, oos, judgment }
|
82
94
|
}
|
83
95
|
|
84
96
|
public abstract evaluate(specs: any, values: any[]): EvaluationResult
|
@@ -4,7 +4,8 @@ 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 {
|
7
|
+
import { DataSetHistory } from '../data-set-history/data-set-history'
|
8
|
+
import { DataItem } from '../data-set/data-item-type'
|
8
9
|
import { DataSet } from '../data-set/data-set'
|
9
10
|
import { DataOoc } from './data-ooc'
|
10
11
|
import { DataOocList } from './data-ooc-type'
|
@@ -38,6 +39,17 @@ export class DataOocQuery {
|
|
38
39
|
return { items, total }
|
39
40
|
}
|
40
41
|
|
42
|
+
@FieldResolver(type => [DataItem])
|
43
|
+
async dataItems(@Root() dataOoc: DataOoc): Promise<DataItem[]> {
|
44
|
+
const dataSetHistory: DataSetHistory = await getRepository(DataSetHistory).findOne({
|
45
|
+
where: {
|
46
|
+
id: dataOoc.dataSetId,
|
47
|
+
version: dataOoc.dataSetVersion
|
48
|
+
}
|
49
|
+
})
|
50
|
+
return dataSetHistory?.dataItems || []
|
51
|
+
}
|
52
|
+
|
41
53
|
@FieldResolver(type => DataSet)
|
42
54
|
async dataSet(@Root() dataOoc: DataOoc): Promise<DataSet> {
|
43
55
|
return await getRepository(DataSet).findOne({
|
@@ -45,13 +57,6 @@ export class DataOocQuery {
|
|
45
57
|
})
|
46
58
|
}
|
47
59
|
|
48
|
-
@FieldResolver(type => DataSample)
|
49
|
-
async dataSample(@Root() dataOoc: DataOoc): Promise<DataSample> {
|
50
|
-
return await getRepository(DataSample).findOne({
|
51
|
-
id: dataOoc.dataSampleId
|
52
|
-
})
|
53
|
-
}
|
54
|
-
|
55
60
|
@FieldResolver(type => Domain)
|
56
61
|
async domain(@Root() dataOoc: DataOoc): Promise<Domain> {
|
57
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 {
|
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')
|
@@ -67,13 +63,9 @@ export class DataOoc {
|
|
67
63
|
@RelationId((dataOoc: DataOoc) => dataOoc.dataSet)
|
68
64
|
dataSetId?: string
|
69
65
|
|
70
|
-
@
|
71
|
-
@
|
72
|
-
|
73
|
-
dataSample?: DataSample
|
74
|
-
|
75
|
-
@RelationId((dataOoc: DataOoc) => dataOoc.dataSample)
|
76
|
-
dataSampleId?: string
|
66
|
+
@Column({ nullable: true })
|
67
|
+
@Field({ nullable: true })
|
68
|
+
dataSetVersion?: number
|
77
69
|
|
78
70
|
@Column({
|
79
71
|
nullable: true
|
@@ -127,7 +119,10 @@ export class DataOoc {
|
|
127
119
|
|
128
120
|
@Column('simple-json', { nullable: true })
|
129
121
|
@Field(type => ScalarObject, { nullable: true })
|
130
|
-
|
122
|
+
judgment?: ScalarObject
|
123
|
+
|
124
|
+
@Field(type => [DataItem], { nullable: true })
|
125
|
+
dataItems?: DataItem[]
|
131
126
|
|
132
127
|
@Column('simple-json', { nullable: true })
|
133
128
|
@Field(type => ScalarObject, { nullable: true })
|
@@ -4,6 +4,8 @@ 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 { DataSetHistory } from '../data-set-history/data-set-history'
|
8
|
+
import { DataItem } from '../data-set/data-item-type'
|
7
9
|
import { DataSet } from '../data-set/data-set'
|
8
10
|
import { DataSample } from './data-sample'
|
9
11
|
import { DataSampleList } from './data-sample-type'
|
@@ -37,8 +39,19 @@ export class DataSampleQuery {
|
|
37
39
|
return { items, total }
|
38
40
|
}
|
39
41
|
|
42
|
+
@FieldResolver(type => [DataItem])
|
43
|
+
async dataItems(@Root() dataSample: DataSample): Promise<DataItem[]> {
|
44
|
+
const dataSetHistory: DataSetHistory = await getRepository(DataSetHistory).findOne({
|
45
|
+
where: {
|
46
|
+
id: dataSample.dataSetId,
|
47
|
+
version: dataSample.dataSetVersion
|
48
|
+
}
|
49
|
+
})
|
50
|
+
return dataSetHistory?.dataItems || []
|
51
|
+
}
|
52
|
+
|
40
53
|
@FieldResolver(type => DataSet)
|
41
|
-
async dataSet(@Root() dataSample: DataSample): Promise<
|
54
|
+
async dataSet(@Root() dataSample: DataSample): Promise<DataSet> {
|
42
55
|
return await getRepository(DataSet).findOne(dataSample.dataSetId)
|
43
56
|
}
|
44
57
|
|
@@ -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
|
-
'
|
24
|
+
'ix_data_sample_0',
|
25
25
|
(dataSample: DataSample) => [dataSample.domain, dataSample.dataSet, dataSample.collectedAt],
|
26
26
|
{ unique: false }
|
27
27
|
)
|
@@ -71,13 +71,20 @@ export class DataSample {
|
|
71
71
|
@RelationId((dataSample: DataSample) => dataSample.dataSet)
|
72
72
|
dataSetId?: string
|
73
73
|
|
74
|
+
@Column({ nullable: true })
|
75
|
+
@Field({ nullable: true })
|
76
|
+
dataSetVersion?: number
|
77
|
+
|
74
78
|
@Column('simple-json', { nullable: true })
|
75
79
|
@Field(type => ScalarObject, { nullable: true })
|
76
80
|
data?: ScalarObject
|
77
81
|
|
78
82
|
@Column('simple-json', { nullable: true })
|
79
83
|
@Field(type => ScalarObject, { nullable: true })
|
80
|
-
|
84
|
+
judgment?: ScalarObject
|
85
|
+
|
86
|
+
@Field(type => [DataItem], { nullable: true })
|
87
|
+
dataItems?: DataItem[]
|
81
88
|
|
82
89
|
@Column({
|
83
90
|
nullable: true,
|
@@ -0,0 +1,82 @@
|
|
1
|
+
import { Field, InputType, Int, ObjectType, registerEnumType } from 'type-graphql'
|
2
|
+
|
3
|
+
import { ScalarObject } from '@things-factory/shell'
|
4
|
+
|
5
|
+
export enum DataItemType {
|
6
|
+
number = 'number',
|
7
|
+
text = 'text',
|
8
|
+
boolean = 'boolean',
|
9
|
+
select = 'select',
|
10
|
+
file = 'file'
|
11
|
+
}
|
12
|
+
|
13
|
+
registerEnumType(DataItemType, {
|
14
|
+
name: 'DataItemType',
|
15
|
+
description: 'state enumeration of a data-item'
|
16
|
+
})
|
17
|
+
|
18
|
+
@ObjectType({ description: 'Entity for DataItem' })
|
19
|
+
export class DataItem {
|
20
|
+
@Field()
|
21
|
+
name: string
|
22
|
+
|
23
|
+
@Field({ nullable: true })
|
24
|
+
description?: string
|
25
|
+
|
26
|
+
@Field({ nullable: true })
|
27
|
+
tag?: string
|
28
|
+
|
29
|
+
@Field({ nullable: true })
|
30
|
+
active?: boolean
|
31
|
+
|
32
|
+
@Field({ nullable: true })
|
33
|
+
hidden?: boolean
|
34
|
+
|
35
|
+
@Field({ nullable: true })
|
36
|
+
type?: DataItemType
|
37
|
+
|
38
|
+
@Field(type => ScalarObject, { nullable: true })
|
39
|
+
options?: ScalarObject
|
40
|
+
|
41
|
+
@Field({ nullable: true })
|
42
|
+
unit?: string
|
43
|
+
|
44
|
+
@Field(type => Int, { nullable: true })
|
45
|
+
quota: number
|
46
|
+
|
47
|
+
@Field(type => ScalarObject, { nullable: true })
|
48
|
+
spec?: ScalarObject
|
49
|
+
}
|
50
|
+
|
51
|
+
@InputType()
|
52
|
+
export class DataItemPatch {
|
53
|
+
@Field({ nullable: true })
|
54
|
+
name?: string
|
55
|
+
|
56
|
+
@Field({ nullable: true })
|
57
|
+
description?: string
|
58
|
+
|
59
|
+
@Field({ nullable: true })
|
60
|
+
tag?: string
|
61
|
+
|
62
|
+
@Field(type => DataItemType, { nullable: true })
|
63
|
+
type?: DataItemType
|
64
|
+
|
65
|
+
@Field(type => ScalarObject, { nullable: true })
|
66
|
+
options?: ScalarObject
|
67
|
+
|
68
|
+
@Field({ nullable: true })
|
69
|
+
unit?: string
|
70
|
+
|
71
|
+
@Field(type => Int, { nullable: true })
|
72
|
+
quota?: number
|
73
|
+
|
74
|
+
@Field({ nullable: true })
|
75
|
+
active?: boolean
|
76
|
+
|
77
|
+
@Field({ nullable: true })
|
78
|
+
hidden?: boolean
|
79
|
+
|
80
|
+
@Field(type => ScalarObject, { nullable: true })
|
81
|
+
spec?: ScalarObject
|
82
|
+
}
|
@@ -1,10 +1,9 @@
|
|
1
1
|
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
2
|
-
import {
|
2
|
+
import { In } from 'typeorm'
|
3
3
|
|
4
4
|
import { createAttachment, deleteAttachmentsByRef } from '@things-factory/attachment-base'
|
5
|
-
import { Domain } from '@things-factory/shell'
|
6
5
|
|
7
|
-
import {
|
6
|
+
import { DataSetHistory } from '../data-set-history/data-set-history'
|
8
7
|
import { DataSet } from './data-set'
|
9
8
|
import { DataSetPatch, NewDataSet } from './data-set-type'
|
10
9
|
|
@@ -17,9 +16,12 @@ export class DataSetMutation {
|
|
17
16
|
@Mutation(returns => DataSet, { description: 'To create new DataSet' })
|
18
17
|
async createDataSet(@Arg('dataSet') dataSet: NewDataSet, @Ctx() context: any): Promise<DataSet> {
|
19
18
|
const { domain, user, tx } = context.state
|
19
|
+
const dataSetRepo = tx.getRepository(DataSet)
|
20
|
+
const dataSetHistoryRepo = tx.getRepository(DataSetHistory)
|
20
21
|
|
21
|
-
const result = await
|
22
|
+
const result = await dataSetRepo.save({
|
22
23
|
...dataSet,
|
24
|
+
version: 1,
|
23
25
|
domain,
|
24
26
|
creator: user,
|
25
27
|
updater: user
|
@@ -27,6 +29,12 @@ export class DataSetMutation {
|
|
27
29
|
|
28
30
|
await this._createAttachment(context, dataSet.reportTemplate, { refId: result.id, cuFlag: '+' })
|
29
31
|
|
32
|
+
await dataSetHistoryRepo.save(
|
33
|
+
await dataSetRepo.findOne(result.id, {
|
34
|
+
relations: ['domain', 'creator', 'updater', 'supervisoryRole', 'entryRole']
|
35
|
+
})
|
36
|
+
)
|
37
|
+
|
30
38
|
return result
|
31
39
|
}
|
32
40
|
|
@@ -35,20 +43,28 @@ export class DataSetMutation {
|
|
35
43
|
@Mutation(returns => DataSet, { description: 'To modify DataSet information' })
|
36
44
|
async updateDataSet(@Arg('id') id: string, @Arg('patch') patch: DataSetPatch, @Ctx() context: any): Promise<DataSet> {
|
37
45
|
const { domain, user, tx } = context.state
|
46
|
+
const dataSetRepo = tx.getRepository(DataSet)
|
47
|
+
const dataSetHistoryRepo = tx.getRepository(DataSetHistory)
|
38
48
|
|
39
|
-
const
|
40
|
-
const dataSet = await repository.findOne({
|
49
|
+
const dataSet = await dataSetRepo.findOne({
|
41
50
|
where: { domain, id }
|
42
51
|
})
|
43
52
|
|
44
|
-
const result = await
|
53
|
+
const result = await dataSetRepo.save({
|
45
54
|
...dataSet,
|
46
55
|
...patch,
|
56
|
+
version: (dataSet.version || 0) + 1,
|
47
57
|
updater: user
|
48
58
|
})
|
49
59
|
|
50
60
|
await this._createAttachment(context, dataSet.reportTemplate, { refId: result.id, cuFlag: 'M' })
|
51
61
|
|
62
|
+
await dataSetHistoryRepo.save(
|
63
|
+
await dataSetRepo.findOne(id, {
|
64
|
+
relations: ['domain', 'creator', 'updater', 'supervisoryRole', 'entryRole']
|
65
|
+
})
|
66
|
+
)
|
67
|
+
|
52
68
|
return result
|
53
69
|
}
|
54
70
|
|
@@ -60,11 +76,12 @@ export class DataSetMutation {
|
|
60
76
|
@Ctx() context: any
|
61
77
|
): Promise<DataSet[]> {
|
62
78
|
const { domain, user, tx } = context.state
|
79
|
+
const dataSetRepo = tx.getRepository(DataSet)
|
80
|
+
const dataSetHistoryRepo = tx.getRepository(DataSetHistory)
|
63
81
|
|
64
82
|
let results = []
|
65
83
|
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
66
84
|
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
67
|
-
const dataSetRepo = tx.getRepository(DataSet)
|
68
85
|
|
69
86
|
if (_createRecords.length > 0) {
|
70
87
|
const cuFlag = '+'
|
@@ -73,6 +90,7 @@ export class DataSetMutation {
|
|
73
90
|
|
74
91
|
const result = await dataSetRepo.save({
|
75
92
|
...newRecord,
|
93
|
+
version: 1,
|
76
94
|
domain,
|
77
95
|
creator: user,
|
78
96
|
updater: user
|
@@ -80,7 +98,12 @@ export class DataSetMutation {
|
|
80
98
|
|
81
99
|
await this._createAttachment(context, newRecord.reportTemplate, { refId: result.id, cuFlag })
|
82
100
|
|
83
|
-
results.push({
|
101
|
+
results.push({
|
102
|
+
...(await dataSetRepo.findOne(result.id, {
|
103
|
+
relations: ['domain', 'creator', 'updater', 'supervisoryRole', 'entryRole']
|
104
|
+
})),
|
105
|
+
cuFlag
|
106
|
+
})
|
84
107
|
}
|
85
108
|
}
|
86
109
|
|
@@ -93,15 +116,23 @@ export class DataSetMutation {
|
|
93
116
|
const result = await dataSetRepo.save({
|
94
117
|
...dataSet,
|
95
118
|
...newRecord,
|
119
|
+
version: (dataSet.version || 0) + 1,
|
96
120
|
updater: user
|
97
121
|
})
|
98
122
|
|
99
123
|
await this._createAttachment(context, newRecord.reportTemplate, { refId: result.id, cuFlag })
|
100
124
|
|
101
|
-
results.push({
|
125
|
+
results.push({
|
126
|
+
...(await dataSetRepo.findOne(result.id, {
|
127
|
+
relations: ['domain', 'creator', 'updater', 'supervisoryRole', 'entryRole']
|
128
|
+
})),
|
129
|
+
cuFlag
|
130
|
+
})
|
102
131
|
}
|
103
132
|
}
|
104
133
|
|
134
|
+
results.forEach(result => dataSetHistoryRepo.save({ ...result }))
|
135
|
+
|
105
136
|
return results
|
106
137
|
}
|
107
138
|
|
@@ -139,20 +170,22 @@ export class DataSetMutation {
|
|
139
170
|
@Arg('dataSets', type => [DataSetPatch]) dataSets: DataSet[],
|
140
171
|
@Ctx() context: any
|
141
172
|
): Promise<boolean> {
|
142
|
-
const tx
|
143
|
-
const
|
173
|
+
const { domain, tx } = context.state
|
174
|
+
const dataSetRepo = tx.getRepository(DataSet)
|
175
|
+
const dataSetHistoryRepo = tx.getRepository(DataSetHistory)
|
176
|
+
|
144
177
|
await Promise.all(
|
145
178
|
dataSets.map(async (dataSet: DataSet) => {
|
146
|
-
const createdDataSet: DataSet = await
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
)
|
155
|
-
|
179
|
+
const createdDataSet: DataSet = await dataSetRepo.save({
|
180
|
+
domain,
|
181
|
+
version: 1 /* overridable by dataSet's origin value */,
|
182
|
+
...dataSet
|
183
|
+
})
|
184
|
+
await dataSetHistoryRepo.save(
|
185
|
+
...(await dataSetRepo.findOne(createdDataSet.id, {
|
186
|
+
relations: ['domain', 'creator', 'updater', 'supervisoryRole', 'entryRole']
|
187
|
+
}))
|
188
|
+
)
|
156
189
|
})
|
157
190
|
)
|
158
191
|
|
@@ -164,69 +197,40 @@ export class DataSetMutation {
|
|
164
197
|
@Mutation(returns => [DataSet], { description: 'To copy multiple data-sets' })
|
165
198
|
async copyDataSets(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<DataSet[]> {
|
166
199
|
const { domain, user, tx } = context.state
|
200
|
+
const dataSetRepo = tx.getRepository(DataSet)
|
201
|
+
const dataSetHistoryRepo = tx.getRepository(DataSetHistory)
|
167
202
|
|
168
|
-
const originals = await
|
203
|
+
const originals = await dataSetRepo.find({
|
169
204
|
where: {
|
170
205
|
id: In(ids),
|
171
206
|
domain
|
172
207
|
},
|
173
|
-
relations: ['domain', '
|
208
|
+
relations: ['domain', 'supervisoryRole', 'entryRole']
|
174
209
|
})
|
175
210
|
|
176
211
|
if (originals.length == 0) {
|
177
212
|
return []
|
178
213
|
}
|
179
214
|
|
180
|
-
var newDataItems = []
|
181
|
-
|
182
215
|
var newCopys = originals.map(dataSet => {
|
183
216
|
let dataSetId = crypto.randomUUID()
|
184
|
-
newDataItems.push(
|
185
|
-
...dataSet.dataItems.map(dataItem => {
|
186
|
-
return {
|
187
|
-
dataSet: dataSetId,
|
188
|
-
name: dataItem.name,
|
189
|
-
description: dataItem.description,
|
190
|
-
sequence: dataItem.sequence,
|
191
|
-
tag: dataItem.tag,
|
192
|
-
active: dataItem.active,
|
193
|
-
type: dataItem.type,
|
194
|
-
quota: dataItem.quota,
|
195
|
-
spec: dataItem.spec,
|
196
|
-
unit: dataItem.unit,
|
197
|
-
options: dataItem.options,
|
198
|
-
hidden: dataItem.hidden,
|
199
|
-
// connection: dataItem.connection,
|
200
|
-
// params: dataItem.params,
|
201
|
-
domain,
|
202
|
-
creator: user,
|
203
|
-
updater: user
|
204
|
-
}
|
205
|
-
})
|
206
|
-
)
|
207
217
|
|
208
218
|
return {
|
219
|
+
...dataSet,
|
209
220
|
id: dataSetId,
|
210
221
|
name: dataSet.name + ' (' + dataSetId + ')',
|
211
|
-
type: dataSet.type,
|
212
|
-
description: dataSet.description,
|
213
222
|
active: false,
|
214
|
-
|
215
|
-
timezone: dataSet.timezone,
|
216
|
-
|
223
|
+
version: 1,
|
217
224
|
domain,
|
218
225
|
creator: user,
|
219
226
|
updater: user
|
220
227
|
}
|
221
228
|
})
|
222
229
|
|
223
|
-
var copiedDataSets = await
|
224
|
-
|
230
|
+
var copiedDataSets = await dataSetRepo.save(newCopys)
|
231
|
+
await dataSetHistoryRepo.save(copiedDataSets)
|
225
232
|
|
226
|
-
return copiedDataSets
|
227
|
-
dataSet.dataItems = copiedDataItems.filter(dataItem => dataItem.dataSet == dataSet.id)
|
228
|
-
return dataSet
|
229
|
-
})
|
233
|
+
return copiedDataSets
|
230
234
|
}
|
231
235
|
|
232
236
|
async _createAttachment(context, attachment, { refId, cuFlag }) {
|
@@ -34,6 +34,7 @@ export class DataSetQuery {
|
|
34
34
|
repository: getRepository(DataSet),
|
35
35
|
params,
|
36
36
|
domain,
|
37
|
+
alias: 'dataset',
|
37
38
|
searchables: ['name', 'description', 'supervisoryRole']
|
38
39
|
})
|
39
40
|
|
@@ -57,18 +58,16 @@ export class DataSetQuery {
|
|
57
58
|
return { items: [], total: 0 }
|
58
59
|
}
|
59
60
|
|
60
|
-
const
|
61
|
+
const [items, total] = await getQueryBuilderFromListParams({
|
61
62
|
repository: getRepository(DataSet),
|
62
63
|
params,
|
63
64
|
domain,
|
64
65
|
alias: 'dataset',
|
65
66
|
searchables: ['name', 'description']
|
66
67
|
})
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
const [items, total] = await queryBuilder.getManyAndCount()
|
68
|
+
.andWhere(`dataset.active = :active`, { active: true })
|
69
|
+
.andWhere('dataset.entryRole IN (:...roles)', { roles })
|
70
|
+
.getManyAndCount()
|
72
71
|
|
73
72
|
return { items, total }
|
74
73
|
}
|
@@ -88,24 +87,27 @@ export class DataSetQuery {
|
|
88
87
|
return { items: [], total: 0 }
|
89
88
|
}
|
90
89
|
|
91
|
-
const
|
90
|
+
const [items, total] = await getQueryBuilderFromListParams({
|
92
91
|
repository: getRepository(DataSet),
|
93
92
|
params,
|
94
93
|
domain,
|
95
94
|
alias: 'dataset',
|
96
95
|
searchables: ['name', 'description']
|
97
96
|
})
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
const [items, total] = await queryBuilder.getManyAndCount()
|
97
|
+
.andWhere(`dataset.active = :active`, { active: true })
|
98
|
+
.andWhere('dataset.supervisoryRole IN (:...roles)', { roles })
|
99
|
+
.getManyAndCount()
|
103
100
|
|
104
101
|
return { items, total }
|
105
102
|
}
|
106
103
|
|
107
104
|
@FieldResolver(type => [DataItem])
|
108
105
|
async dataItems(@Root() dataSet: DataSet): Promise<DataItem[]> {
|
106
|
+
/* TODO this fieldResolver should be removed. This is only for migration temporarily */
|
107
|
+
if (dataSet.dataItems) {
|
108
|
+
return dataSet.dataItems as DataItem[]
|
109
|
+
}
|
110
|
+
|
109
111
|
return await getRepository(DataItem).find({
|
110
112
|
dataSet
|
111
113
|
})
|