@things-factory/dataset 5.0.0-alpha.4 → 5.0.0-alpha.42
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/README.md +13 -0
- package/assets/data-samples.jpg +0 -0
- package/client/bootstrap.js +21 -1
- package/client/pages/{data-entry-form.js → data-entry/data-entry-form.js} +15 -2
- package/client/pages/data-entry/data-entry-list-page.js +423 -0
- package/client/pages/data-ooc/data-ooc-list-page.js +483 -0
- package/client/pages/data-ooc/data-ooc-view.js +182 -0
- package/client/pages/data-report/data-report-embed-page.js +113 -0
- package/client/pages/data-report/data-report-list-page.js +465 -0
- package/client/pages/data-report/jasper-report-oocs-page.js +120 -0
- package/client/pages/data-report/jasper-report-samples-crosstab-page.js +120 -0
- package/client/pages/data-report/jasper-report-samples-page.js +120 -0
- package/client/pages/data-sample/data-sample-list-page.js +386 -0
- package/client/pages/data-sample/data-sample-view.js +97 -0
- package/client/pages/{data-sensor.js → data-sensor/data-sensor-list-page.js} +43 -64
- package/client/pages/{data-item-list.js → data-set/data-item-list.js} +37 -12
- package/client/pages/{data-set-importer.js → data-set/data-set-importer.js} +0 -0
- package/client/pages/data-set/data-set-list-page.js +712 -0
- package/client/route.js +34 -6
- package/config/config.development.js +13 -0
- package/config/config.production.js +1 -0
- package/dist-server/controllers/create-data-sample.js +133 -0
- package/dist-server/controllers/create-data-sample.js.map +1 -0
- package/dist-server/controllers/data-use-case.js +57 -0
- package/dist-server/controllers/data-use-case.js.map +1 -0
- package/dist-server/controllers/index.js +17 -0
- package/dist-server/controllers/index.js.map +1 -1
- package/dist-server/controllers/jasper-report.js +156 -0
- package/dist-server/controllers/jasper-report.js.map +1 -0
- package/dist-server/index.js +1 -0
- package/dist-server/index.js.map +1 -1
- package/dist-server/routes.js +13 -24
- package/dist-server/routes.js.map +1 -1
- package/dist-server/service/data-item/data-item-mutation.js +5 -1
- package/dist-server/service/data-item/data-item-mutation.js.map +1 -1
- package/dist-server/service/data-item/data-item-query.js +7 -2
- package/dist-server/service/data-item/data-item-query.js.map +1 -1
- package/dist-server/service/data-item/data-item-type.js +15 -7
- package/dist-server/service/data-item/data-item-type.js.map +1 -1
- package/dist-server/service/data-item/data-item.js +17 -3
- package/dist-server/service/data-item/data-item.js.map +1 -1
- package/dist-server/service/data-ooc/data-ooc-mutation.js +92 -0
- package/dist-server/service/data-ooc/data-ooc-mutation.js.map +1 -0
- package/dist-server/service/data-ooc/data-ooc-query.js +120 -0
- package/dist-server/service/data-ooc/data-ooc-query.js.map +1 -0
- package/dist-server/service/data-ooc/data-ooc-subscription.js +65 -0
- package/dist-server/service/data-ooc/data-ooc-subscription.js.map +1 -0
- package/dist-server/service/data-ooc/data-ooc-type.js +107 -0
- package/dist-server/service/data-ooc/data-ooc-type.js.map +1 -0
- package/dist-server/service/data-ooc/data-ooc.js +237 -0
- package/dist-server/service/data-ooc/data-ooc.js.map +1 -0
- package/dist-server/service/data-ooc/index.js +10 -0
- package/dist-server/service/data-ooc/index.js.map +1 -0
- package/dist-server/service/data-sample/data-sample-mutation.js +2 -138
- package/dist-server/service/data-sample/data-sample-mutation.js.map +1 -1
- package/dist-server/service/data-sample/data-sample-query.js +7 -2
- package/dist-server/service/data-sample/data-sample-query.js.map +1 -1
- package/dist-server/service/data-sample/data-sample-type.js +12 -42
- package/dist-server/service/data-sample/data-sample-type.js.map +1 -1
- package/dist-server/service/data-sample/data-sample.js +34 -3
- package/dist-server/service/data-sample/data-sample.js.map +1 -1
- package/dist-server/service/data-sensor/data-sensor-query.js +7 -2
- package/dist-server/service/data-sensor/data-sensor-query.js.map +1 -1
- package/dist-server/service/data-set/data-set-mutation.js +38 -9
- package/dist-server/service/data-set/data-set-mutation.js.map +1 -1
- package/dist-server/service/data-set/data-set-query.js +185 -3
- package/dist-server/service/data-set/data-set-query.js.map +1 -1
- package/dist-server/service/data-set/data-set-type.js +84 -3
- package/dist-server/service/data-set/data-set-type.js.map +1 -1
- package/dist-server/service/data-set/data-set.js +110 -15
- package/dist-server/service/data-set/data-set.js.map +1 -1
- package/dist-server/service/index.js +6 -2
- package/dist-server/service/index.js.map +1 -1
- package/package.json +19 -13
- package/server/controllers/create-data-sample.ts +177 -0
- package/server/controllers/data-use-case.ts +85 -0
- package/server/controllers/index.ts +1 -0
- package/server/controllers/jasper-report.ts +170 -0
- package/server/index.ts +1 -0
- package/server/routes.ts +21 -31
- package/server/service/data-item/data-item-mutation.ts +6 -1
- package/server/service/data-item/data-item-query.ts +9 -3
- package/server/service/data-item/data-item-type.ts +10 -6
- package/server/service/data-item/data-item.ts +15 -4
- package/server/service/data-ooc/data-ooc-mutation.ts +150 -0
- package/server/service/data-ooc/data-ooc-query.ts +69 -0
- package/server/service/data-ooc/data-ooc-subscription.ts +51 -0
- package/server/service/data-ooc/data-ooc-type.ts +68 -0
- package/server/service/data-ooc/data-ooc.ts +204 -0
- package/server/service/data-ooc/index.ts +7 -0
- package/server/service/data-sample/data-sample-mutation.ts +3 -172
- package/server/service/data-sample/data-sample-query.ts +9 -3
- package/server/service/data-sample/data-sample-type.ts +7 -28
- package/server/service/data-sample/data-sample.ts +33 -3
- package/server/service/data-sensor/data-sensor-query.ts +9 -3
- package/server/service/data-set/data-set-mutation.ts +52 -12
- package/server/service/data-set/data-set-query.ts +156 -4
- package/server/service/data-set/data-set-type.ts +65 -4
- package/server/service/data-set/data-set.ts +100 -12
- package/server/service/index.ts +6 -2
- package/things-factory.config.js +35 -7
- package/translations/en.json +46 -3
- package/translations/ko.json +45 -3
- package/translations/ms.json +44 -3
- package/translations/zh.json +44 -3
- package/client/pages/data-sample.js +0 -316
- package/client/pages/data-set.js +0 -457
@@ -0,0 +1,68 @@
|
|
1
|
+
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
2
|
+
|
3
|
+
import { ObjectRef, ScalarObject } from '@things-factory/shell'
|
4
|
+
|
5
|
+
import { DataOoc, DataOocStatus } from './data-ooc'
|
6
|
+
|
7
|
+
@InputType()
|
8
|
+
export class NewDataOoc {
|
9
|
+
@Field()
|
10
|
+
name: string
|
11
|
+
|
12
|
+
@Field({ nullable: true })
|
13
|
+
description?: string
|
14
|
+
|
15
|
+
@Field(type => ObjectRef, { nullable: true })
|
16
|
+
dataSet?: ObjectRef
|
17
|
+
|
18
|
+
@Field(type => ObjectRef, { nullable: true })
|
19
|
+
dataSample?: ObjectRef
|
20
|
+
|
21
|
+
@Field(type => DataOocStatus, { nullable: true })
|
22
|
+
state?: DataOocStatus
|
23
|
+
|
24
|
+
@Field(type => ScalarObject, { nullable: true })
|
25
|
+
data?: ScalarObject
|
26
|
+
|
27
|
+
@Field({ nullable: true })
|
28
|
+
rawData?: string
|
29
|
+
|
30
|
+
@Field({ nullable: true })
|
31
|
+
source?: string
|
32
|
+
|
33
|
+
@Field({ nullable: true })
|
34
|
+
ooc?: boolean
|
35
|
+
|
36
|
+
@Field({ nullable: true })
|
37
|
+
oos?: boolean
|
38
|
+
|
39
|
+
@Field({ nullable: true })
|
40
|
+
workDate?: string
|
41
|
+
|
42
|
+
@Field({ nullable: true })
|
43
|
+
workShift?: string
|
44
|
+
|
45
|
+
@Field({ nullable: true })
|
46
|
+
collectedAt?: Date
|
47
|
+
}
|
48
|
+
|
49
|
+
@InputType()
|
50
|
+
export class DataOocPatch {
|
51
|
+
@Field(type => ID, { nullable: true })
|
52
|
+
id?: string
|
53
|
+
|
54
|
+
@Field(type => DataOocStatus, { nullable: true })
|
55
|
+
state?: DataOocStatus
|
56
|
+
|
57
|
+
@Field({ nullable: true })
|
58
|
+
correctiveAction?: string
|
59
|
+
}
|
60
|
+
|
61
|
+
@ObjectType()
|
62
|
+
export class DataOocList {
|
63
|
+
@Field(type => [DataOoc])
|
64
|
+
items: DataOoc[]
|
65
|
+
|
66
|
+
@Field(type => Int)
|
67
|
+
total: number
|
68
|
+
}
|
@@ -0,0 +1,204 @@
|
|
1
|
+
import { Field, ID, ObjectType, registerEnumType } from 'type-graphql'
|
2
|
+
import {
|
3
|
+
Column,
|
4
|
+
CreateDateColumn,
|
5
|
+
Entity,
|
6
|
+
Index,
|
7
|
+
JoinColumn,
|
8
|
+
ManyToOne,
|
9
|
+
OneToOne,
|
10
|
+
PrimaryGeneratedColumn,
|
11
|
+
RelationId,
|
12
|
+
UpdateDateColumn
|
13
|
+
} from 'typeorm'
|
14
|
+
|
15
|
+
import { User } from '@things-factory/auth-base'
|
16
|
+
import { config } from '@things-factory/env'
|
17
|
+
import { Domain, ScalarObject } from '@things-factory/shell'
|
18
|
+
|
19
|
+
import { DataSample } from '../data-sample/data-sample'
|
20
|
+
import { DataSet } from '../data-set/data-set'
|
21
|
+
|
22
|
+
const ORMCONFIG = config.get('ormconfig', {})
|
23
|
+
const DATABASE_TYPE = ORMCONFIG.type
|
24
|
+
|
25
|
+
export enum DataOocStatus {
|
26
|
+
CREATED = 'CREATED',
|
27
|
+
REVIEWED = 'REVIEWED',
|
28
|
+
CORRECTED = 'CORRECTED'
|
29
|
+
}
|
30
|
+
|
31
|
+
registerEnumType(DataOocStatus, {
|
32
|
+
name: 'DataOocStatus',
|
33
|
+
description: 'Out of control data corrective action process progress status'
|
34
|
+
})
|
35
|
+
|
36
|
+
@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 })
|
40
|
+
@ObjectType({ description: 'Entity for Out of control data' })
|
41
|
+
export class DataOoc {
|
42
|
+
@PrimaryGeneratedColumn('uuid')
|
43
|
+
@Field(type => ID)
|
44
|
+
readonly id: string
|
45
|
+
|
46
|
+
@ManyToOne(type => Domain)
|
47
|
+
@Field({ nullable: true })
|
48
|
+
domain?: Domain
|
49
|
+
|
50
|
+
@RelationId((dataOoc: DataOoc) => dataOoc.domain)
|
51
|
+
domainId?: string
|
52
|
+
|
53
|
+
@Column()
|
54
|
+
@Field()
|
55
|
+
name: string
|
56
|
+
|
57
|
+
@Column({
|
58
|
+
nullable: true
|
59
|
+
})
|
60
|
+
@Field({ nullable: true })
|
61
|
+
description?: string
|
62
|
+
|
63
|
+
@ManyToOne(type => DataSet)
|
64
|
+
@Field(type => DataSet, { nullable: true })
|
65
|
+
dataSet?: DataSet
|
66
|
+
|
67
|
+
@RelationId((dataOoc: DataOoc) => dataOoc.dataSet)
|
68
|
+
dataSetId?: string
|
69
|
+
|
70
|
+
@OneToOne(type => DataSample)
|
71
|
+
@JoinColumn()
|
72
|
+
@Field(type => DataSample, { nullable: true })
|
73
|
+
dataSample?: DataSample
|
74
|
+
|
75
|
+
@RelationId((dataOoc: DataOoc) => dataOoc.dataSample)
|
76
|
+
dataSampleId?: string
|
77
|
+
|
78
|
+
@Column({
|
79
|
+
nullable: true
|
80
|
+
})
|
81
|
+
@Field({ nullable: true })
|
82
|
+
ooc?: boolean
|
83
|
+
|
84
|
+
@Column({
|
85
|
+
nullable: true
|
86
|
+
})
|
87
|
+
@Field({ nullable: true })
|
88
|
+
oos?: boolean
|
89
|
+
|
90
|
+
@Column({
|
91
|
+
nullable: true
|
92
|
+
})
|
93
|
+
@Field({ nullable: true })
|
94
|
+
state?: DataOocStatus
|
95
|
+
|
96
|
+
@Column({
|
97
|
+
nullable: true,
|
98
|
+
type:
|
99
|
+
DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
|
100
|
+
? 'longtext'
|
101
|
+
: DATABASE_TYPE == 'oracle'
|
102
|
+
? 'clob'
|
103
|
+
: 'varchar'
|
104
|
+
})
|
105
|
+
@Field({ nullable: true })
|
106
|
+
correctiveAction?: string
|
107
|
+
|
108
|
+
@Column({
|
109
|
+
nullable: true
|
110
|
+
})
|
111
|
+
@Field({ nullable: true })
|
112
|
+
type?: string
|
113
|
+
|
114
|
+
@Column({
|
115
|
+
nullable: true
|
116
|
+
})
|
117
|
+
@Field({ nullable: true })
|
118
|
+
useCase?: string
|
119
|
+
|
120
|
+
@Column('simple-json', { nullable: true })
|
121
|
+
@Field(type => ScalarObject, { nullable: true })
|
122
|
+
partitionKeys?: ScalarObject
|
123
|
+
|
124
|
+
@Column('simple-json', { nullable: true })
|
125
|
+
@Field(type => ScalarObject, { nullable: true })
|
126
|
+
data?: ScalarObject
|
127
|
+
|
128
|
+
@Column('simple-json', { nullable: true })
|
129
|
+
@Field(type => ScalarObject, { nullable: true })
|
130
|
+
spec?: ScalarObject
|
131
|
+
|
132
|
+
@Column('simple-json', { nullable: true })
|
133
|
+
@Field(type => ScalarObject, { nullable: true })
|
134
|
+
history?: ScalarObject
|
135
|
+
|
136
|
+
@Column({
|
137
|
+
nullable: true,
|
138
|
+
type:
|
139
|
+
DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
|
140
|
+
? 'longtext'
|
141
|
+
: DATABASE_TYPE == 'oracle'
|
142
|
+
? 'clob'
|
143
|
+
: 'varchar'
|
144
|
+
})
|
145
|
+
@Field({ nullable: true })
|
146
|
+
rawData?: string
|
147
|
+
|
148
|
+
@Column({
|
149
|
+
nullable: true
|
150
|
+
})
|
151
|
+
@Field({ nullable: true })
|
152
|
+
source?: string
|
153
|
+
|
154
|
+
@Column({ nullable: true })
|
155
|
+
@Field({ nullable: true })
|
156
|
+
workDate?: string
|
157
|
+
|
158
|
+
@Column({ nullable: true })
|
159
|
+
@Field({ nullable: true })
|
160
|
+
workShift?: string
|
161
|
+
|
162
|
+
@Column({ nullable: true })
|
163
|
+
@Field({ nullable: true })
|
164
|
+
collectedAt?: Date
|
165
|
+
|
166
|
+
@Column({ nullable: true })
|
167
|
+
@Field({ nullable: true })
|
168
|
+
correctedAt?: Date
|
169
|
+
|
170
|
+
@CreateDateColumn()
|
171
|
+
@Field({ nullable: true })
|
172
|
+
createdAt?: Date
|
173
|
+
|
174
|
+
@UpdateDateColumn()
|
175
|
+
@Field({ nullable: true })
|
176
|
+
updatedAt?: Date
|
177
|
+
|
178
|
+
@ManyToOne(type => User, {
|
179
|
+
nullable: true
|
180
|
+
})
|
181
|
+
@Field({ nullable: true })
|
182
|
+
corrector?: User
|
183
|
+
|
184
|
+
@RelationId((dataOoc: DataOoc) => dataOoc.corrector)
|
185
|
+
correctorId?: string
|
186
|
+
|
187
|
+
@ManyToOne(type => User, {
|
188
|
+
nullable: true
|
189
|
+
})
|
190
|
+
@Field({ nullable: true })
|
191
|
+
creator?: User
|
192
|
+
|
193
|
+
@RelationId((dataOoc: DataOoc) => dataOoc.creator)
|
194
|
+
creatorId?: string
|
195
|
+
|
196
|
+
@ManyToOne(type => User, {
|
197
|
+
nullable: true
|
198
|
+
})
|
199
|
+
@Field({ nullable: true })
|
200
|
+
updater?: User
|
201
|
+
|
202
|
+
@RelationId((dataOoc: DataOoc) => dataOoc.creator)
|
203
|
+
updaterId?: string
|
204
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { DataOoc } from './data-ooc'
|
2
|
+
import { DataOocMutation } from './data-ooc-mutation'
|
3
|
+
import { DataOocQuery } from './data-ooc-query'
|
4
|
+
import { DataOocSubscription } from './data-ooc-subscription'
|
5
|
+
|
6
|
+
export const entities = [DataOoc]
|
7
|
+
export const resolvers = [DataOocQuery, DataOocMutation, DataOocSubscription]
|
@@ -1,187 +1,18 @@
|
|
1
1
|
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
2
|
-
import { In } from 'typeorm'
|
3
2
|
|
4
|
-
import { DataItem } from '../data-item/data-item'
|
5
|
-
import { DataSet } from '../data-set/data-set'
|
6
3
|
import { DataSample } from './data-sample'
|
7
|
-
import {
|
4
|
+
import { NewDataSample } from './data-sample-type'
|
8
5
|
|
9
|
-
import
|
6
|
+
import { createDataSample } from '../../controllers/create-data-sample'
|
10
7
|
|
11
8
|
const debug = require('debug')('things-factory:dataset:data-sample:data-sample-mutation')
|
12
9
|
|
13
|
-
// parse variable javascript string pattern
|
14
|
-
const replaceVariables = (keys, dic) => {
|
15
|
-
for (const k in keys) {
|
16
|
-
const matches = keys[k].match(/\$\{\w*\}/g)
|
17
|
-
matches &&
|
18
|
-
matches.forEach(m => {
|
19
|
-
keys[k] = keys[k].replace(m, dic[m.slice(2, -1)])
|
20
|
-
})
|
21
|
-
}
|
22
|
-
return keys
|
23
|
-
}
|
24
|
-
|
25
|
-
// It is required UTC date for Partitioning File System like AWS S3.
|
26
|
-
// ex) %YYYY, %MM, %DD
|
27
|
-
const formatDate = (keys, _moment) => {
|
28
|
-
for (const k in keys) {
|
29
|
-
const matches = keys[k].match(/%\w*/g)
|
30
|
-
matches &&
|
31
|
-
matches.forEach(m => {
|
32
|
-
keys[k] = keys[k].replace(m, _moment.format(m.substr(1)))
|
33
|
-
})
|
34
|
-
}
|
35
|
-
return keys
|
36
|
-
}
|
37
|
-
|
38
10
|
@Resolver(DataSample)
|
39
11
|
export class DataSampleMutation {
|
40
12
|
@Directive('@privilege(category: "data-sample", privilege: "mutation", domainOwnerGranted: true)')
|
41
13
|
@Directive('@transaction')
|
42
14
|
@Mutation(returns => DataSample, { description: 'To create new data sample' })
|
43
15
|
async createDataSample(@Arg('dataSample') dataSample: NewDataSample, @Ctx() context: any): Promise<DataSample> {
|
44
|
-
|
45
|
-
|
46
|
-
const dataSet = await tx.getRepository(DataSet).findOne({ id: dataSample.dataSetId })
|
47
|
-
const dataItems = await tx.getRepository(DataItem).find({
|
48
|
-
where: {
|
49
|
-
domain,
|
50
|
-
dataSet
|
51
|
-
},
|
52
|
-
order: {
|
53
|
-
sequence: 'DESC'
|
54
|
-
}
|
55
|
-
})
|
56
|
-
|
57
|
-
const spec = dataItems.reduce((spec, dataItem) => {
|
58
|
-
spec[dataItem.tag] = {
|
59
|
-
...dataItem.spec,
|
60
|
-
name: dataItem.name /* do we need ? */
|
61
|
-
}
|
62
|
-
|
63
|
-
return spec
|
64
|
-
}, {})
|
65
|
-
|
66
|
-
var partitionKeys = {
|
67
|
-
...dataSet.partitionKeys,
|
68
|
-
year: '%YYYY',
|
69
|
-
month: '%MM',
|
70
|
-
date: '%DD',
|
71
|
-
variableX: '${x}',
|
72
|
-
variableDataSetId: '${dataSetId}'
|
73
|
-
}
|
74
|
-
|
75
|
-
const collectedAt = dataSample.collectedAt || new Date()
|
76
|
-
partitionKeys = formatDate(partitionKeys, moment(collectedAt).utc())
|
77
|
-
partitionKeys = replaceVariables(partitionKeys, {
|
78
|
-
dataSetId: dataSample.dataSetId,
|
79
|
-
...dataSample.data
|
80
|
-
})
|
81
|
-
|
82
|
-
return await tx.getRepository(DataSample).save({
|
83
|
-
name: dataSet.name,
|
84
|
-
description: dataSet.description,
|
85
|
-
...dataSample,
|
86
|
-
domain,
|
87
|
-
partitionKeys,
|
88
|
-
spec,
|
89
|
-
collectedAt,
|
90
|
-
creator: user,
|
91
|
-
updater: user
|
92
|
-
})
|
93
|
-
}
|
94
|
-
|
95
|
-
@Directive('@privilege(category: "data-sample", privilege: "mutation", domainOwnerGranted: true)')
|
96
|
-
@Directive('@transaction')
|
97
|
-
@Mutation(returns => DataSample, { description: 'To modify data sample information' })
|
98
|
-
async updateDataSample(
|
99
|
-
@Arg('id') id: string,
|
100
|
-
@Arg('patch') patch: DataSamplePatch,
|
101
|
-
@Ctx() context: any
|
102
|
-
): Promise<DataSample> {
|
103
|
-
const { domain, user, tx } = context.state
|
104
|
-
|
105
|
-
const repository = tx.getRepository(DataSample)
|
106
|
-
const dataSample = await repository.findOne({
|
107
|
-
where: { domain, id }
|
108
|
-
})
|
109
|
-
|
110
|
-
return await repository.save({
|
111
|
-
...dataSample,
|
112
|
-
...patch,
|
113
|
-
updater: user
|
114
|
-
})
|
115
|
-
}
|
116
|
-
|
117
|
-
@Directive('@privilege(category: "data-sample", privilege: "mutation", domainOwnerGranted: true)')
|
118
|
-
@Directive('@transaction')
|
119
|
-
@Mutation(returns => [DataSample], { description: "To modify multiple data samples' information" })
|
120
|
-
async updateMultipleDataSample(
|
121
|
-
@Arg('patches', type => [DataSamplePatch]) patches: DataSamplePatch[],
|
122
|
-
@Ctx() context: any
|
123
|
-
): Promise<DataSample[]> {
|
124
|
-
const { domain, user, tx } = context.state
|
125
|
-
|
126
|
-
let results = []
|
127
|
-
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
128
|
-
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
129
|
-
const dataSampleRepo = tx.getRepository(DataSample)
|
130
|
-
|
131
|
-
if (_createRecords.length > 0) {
|
132
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
133
|
-
const newRecord = _createRecords[i]
|
134
|
-
|
135
|
-
const result = await dataSampleRepo.save({
|
136
|
-
...newRecord,
|
137
|
-
domain,
|
138
|
-
creator: user,
|
139
|
-
updater: user
|
140
|
-
})
|
141
|
-
|
142
|
-
results.push({ ...result, cuFlag: '+' })
|
143
|
-
}
|
144
|
-
}
|
145
|
-
|
146
|
-
if (_updateRecords.length > 0) {
|
147
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
148
|
-
const newRecord = _updateRecords[i]
|
149
|
-
const dataSample = await dataSampleRepo.findOne(newRecord.id)
|
150
|
-
|
151
|
-
const result = await dataSampleRepo.save({
|
152
|
-
...dataSample,
|
153
|
-
...newRecord,
|
154
|
-
updater: user
|
155
|
-
})
|
156
|
-
|
157
|
-
results.push({ ...result, cuFlag: 'M' })
|
158
|
-
}
|
159
|
-
}
|
160
|
-
|
161
|
-
return results
|
162
|
-
}
|
163
|
-
|
164
|
-
@Directive('@privilege(category: "data-sample", privilege: "mutation", domainOwnerGranted: true)')
|
165
|
-
@Directive('@transaction')
|
166
|
-
@Mutation(returns => Boolean, { description: 'To delete a data sample' })
|
167
|
-
async deleteDataSample(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
|
168
|
-
const { domain, tx } = context.state
|
169
|
-
|
170
|
-
await tx.getRepository(DataSample).delete({ domain, id })
|
171
|
-
return true
|
172
|
-
}
|
173
|
-
|
174
|
-
@Directive('@privilege(category: "data-sample", privilege: "mutation", domainOwnerGranted: true)')
|
175
|
-
@Directive('@transaction')
|
176
|
-
@Mutation(returns => Boolean, { description: 'To delete multiple data samples' })
|
177
|
-
async deleteDataSamples(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<boolean> {
|
178
|
-
const { domain, tx } = context.state
|
179
|
-
|
180
|
-
await tx.getRepository(DataSample).delete({
|
181
|
-
domain,
|
182
|
-
id: In(ids)
|
183
|
-
})
|
184
|
-
|
185
|
-
return true
|
16
|
+
return await createDataSample(dataSample, context)
|
186
17
|
}
|
187
18
|
}
|
@@ -2,7 +2,7 @@ import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from
|
|
2
2
|
import { getRepository } from 'typeorm'
|
3
3
|
|
4
4
|
import { User } from '@things-factory/auth-base'
|
5
|
-
import {
|
5
|
+
import { Domain, getQueryBuilderFromListParams, ListParam } from '@things-factory/shell'
|
6
6
|
|
7
7
|
import { DataSet } from '../data-set/data-set'
|
8
8
|
import { DataSample } from './data-sample'
|
@@ -25,8 +25,14 @@ export class DataSampleQuery {
|
|
25
25
|
async dataSamples(@Args() params: ListParam, @Ctx() context: any): Promise<DataSampleList> {
|
26
26
|
const { domain } = context.state
|
27
27
|
|
28
|
-
const
|
29
|
-
|
28
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
29
|
+
repository: getRepository(DataSample),
|
30
|
+
params,
|
31
|
+
domain,
|
32
|
+
alias: 'datasample'
|
33
|
+
})
|
34
|
+
|
35
|
+
const [items, total] = await queryBuilder.getManyAndCount()
|
30
36
|
|
31
37
|
return { items, total }
|
32
38
|
}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { Field,
|
1
|
+
import { Field, InputType, Int, ObjectType } from 'type-graphql'
|
2
2
|
|
3
|
-
import { ScalarObject } from '@things-factory/shell'
|
3
|
+
import { ObjectRef, ScalarObject } from '@things-factory/shell'
|
4
4
|
|
5
5
|
import { DataSample } from './data-sample'
|
6
6
|
|
@@ -12,8 +12,8 @@ export class NewDataSample {
|
|
12
12
|
@Field({ nullable: true })
|
13
13
|
description?: string
|
14
14
|
|
15
|
-
@Field({ nullable: true })
|
16
|
-
|
15
|
+
@Field(type => ObjectRef, { nullable: true })
|
16
|
+
dataSet?: ObjectRef
|
17
17
|
|
18
18
|
@Field(type => ScalarObject, { nullable: true })
|
19
19
|
data?: ScalarObject
|
@@ -25,34 +25,13 @@ export class NewDataSample {
|
|
25
25
|
source?: string
|
26
26
|
|
27
27
|
@Field({ nullable: true })
|
28
|
-
|
29
|
-
}
|
30
|
-
|
31
|
-
@InputType()
|
32
|
-
export class DataSamplePatch {
|
33
|
-
@Field(type => ID, { nullable: true })
|
34
|
-
id?: string
|
35
|
-
|
36
|
-
@Field({ nullable: true })
|
37
|
-
name?: string
|
38
|
-
|
39
|
-
@Field({ nullable: true })
|
40
|
-
description?: string
|
41
|
-
|
42
|
-
@Field({ nullable: true })
|
43
|
-
dataSetId?: string
|
44
|
-
|
45
|
-
@Field(type => ScalarObject, { nullable: true })
|
46
|
-
data?: ScalarObject
|
28
|
+
workDate?: string
|
47
29
|
|
48
30
|
@Field({ nullable: true })
|
49
|
-
|
31
|
+
workShift?: string
|
50
32
|
|
51
33
|
@Field({ nullable: true })
|
52
|
-
|
53
|
-
|
54
|
-
@Field()
|
55
|
-
cuFlag: string
|
34
|
+
collectedAt?: Date
|
56
35
|
}
|
57
36
|
|
58
37
|
@ObjectType()
|
@@ -20,6 +20,11 @@ const ORMCONFIG = config.get('ormconfig', {})
|
|
20
20
|
const DATABASE_TYPE = ORMCONFIG.type
|
21
21
|
@Entity()
|
22
22
|
@Index('ix_data_sample_0', (dataSample: DataSample) => [dataSample.domain, dataSample.dataSet], { unique: false })
|
23
|
+
@Index(
|
24
|
+
'ix_data_sample_2',
|
25
|
+
(dataSample: DataSample) => [dataSample.domain, dataSample.dataSet, dataSample.collectedAt],
|
26
|
+
{ unique: false }
|
27
|
+
)
|
23
28
|
@ObjectType({ description: 'Entity for DataSample' })
|
24
29
|
export class DataSample {
|
25
30
|
@PrimaryGeneratedColumn('uuid')
|
@@ -49,16 +54,21 @@ export class DataSample {
|
|
49
54
|
@Field({ nullable: true })
|
50
55
|
type?: string
|
51
56
|
|
57
|
+
@Column({
|
58
|
+
nullable: true
|
59
|
+
})
|
60
|
+
@Field({ nullable: true })
|
61
|
+
useCase?: string
|
62
|
+
|
52
63
|
@Column('simple-json', { nullable: true })
|
53
64
|
@Field(type => ScalarObject, { nullable: true })
|
54
65
|
partitionKeys?: ScalarObject
|
55
66
|
|
56
|
-
@ManyToOne(type => DataSet
|
57
|
-
@Field(type => DataSet, { nullable:
|
67
|
+
@ManyToOne(type => DataSet)
|
68
|
+
@Field(type => DataSet, { nullable: false })
|
58
69
|
dataSet?: DataSet
|
59
70
|
|
60
71
|
@RelationId((dataSample: DataSample) => dataSample.dataSet)
|
61
|
-
@Field({ nullable: true })
|
62
72
|
dataSetId?: string
|
63
73
|
|
64
74
|
@Column('simple-json', { nullable: true })
|
@@ -87,6 +97,26 @@ export class DataSample {
|
|
87
97
|
@Field({ nullable: true })
|
88
98
|
source?: string
|
89
99
|
|
100
|
+
@Column({
|
101
|
+
nullable: true
|
102
|
+
})
|
103
|
+
@Field({ nullable: true })
|
104
|
+
ooc?: boolean
|
105
|
+
|
106
|
+
@Column({
|
107
|
+
nullable: true
|
108
|
+
})
|
109
|
+
@Field({ nullable: true })
|
110
|
+
oos?: boolean
|
111
|
+
|
112
|
+
@Column({ nullable: true })
|
113
|
+
@Field({ nullable: true })
|
114
|
+
workDate?: string
|
115
|
+
|
116
|
+
@Column({ nullable: true })
|
117
|
+
@Field({ nullable: true })
|
118
|
+
workShift?: string
|
119
|
+
|
90
120
|
@Column({ nullable: true })
|
91
121
|
@Field({ nullable: true })
|
92
122
|
collectedAt?: Date
|
@@ -2,7 +2,7 @@ import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graph
|
|
2
2
|
import { getRepository } from 'typeorm'
|
3
3
|
|
4
4
|
import { Appliance, User } from '@things-factory/auth-base'
|
5
|
-
import {
|
5
|
+
import { Domain, getQueryBuilderFromListParams, ListParam } from '@things-factory/shell'
|
6
6
|
|
7
7
|
import { DataSet } from '../data-set/data-set'
|
8
8
|
import { DataSensor } from './data-sensor'
|
@@ -23,8 +23,14 @@ export class DataSensorQuery {
|
|
23
23
|
async dataSensors(@Args() params: ListParam, @Ctx() context: any): Promise<DataSensorList> {
|
24
24
|
const { domain } = context.state
|
25
25
|
|
26
|
-
const
|
27
|
-
|
26
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
27
|
+
repository: getRepository(DataSensor),
|
28
|
+
params,
|
29
|
+
domain,
|
30
|
+
alias: 'datasensor'
|
31
|
+
})
|
32
|
+
|
33
|
+
const [items, total] = await queryBuilder.getManyAndCount()
|
28
34
|
|
29
35
|
return { items, total }
|
30
36
|
}
|