@things-factory/dataset 5.0.0-alpha.1 → 5.0.0-alpha.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.
- package/client/bootstrap.js +0 -2
- package/client/pages/data-item-list.js +9 -0
- package/client/pages/data-sample.js +30 -5
- package/client/pages/data-sensor.js +451 -0
- package/client/pages/data-set.js +12 -3
- package/client/route.js +4 -0
- package/dist-server/routes.js +64 -0
- package/dist-server/routes.js.map +1 -1
- package/dist-server/service/data-item/data-item-type.js +4 -4
- package/dist-server/service/data-item/data-item-type.js.map +1 -1
- package/dist-server/service/data-item/data-item.js +7 -0
- package/dist-server/service/data-item/data-item.js.map +1 -1
- package/dist-server/service/data-sample/data-sample-mutation.js +5 -5
- package/dist-server/service/data-sample/data-sample-mutation.js.map +1 -1
- package/dist-server/service/data-sample/data-sample-type.js +20 -0
- package/dist-server/service/data-sample/data-sample-type.js.map +1 -1
- package/dist-server/service/data-sample/data-sample.js +39 -0
- package/dist-server/service/data-sample/data-sample.js.map +1 -1
- package/dist-server/service/data-sensor/data-sensor-mutation.js +120 -0
- package/dist-server/service/data-sensor/data-sensor-mutation.js.map +1 -0
- package/dist-server/service/data-sensor/data-sensor-query.js +108 -0
- package/dist-server/service/data-sensor/data-sensor-query.js.map +1 -0
- package/dist-server/service/data-sensor/data-sensor-type.js +147 -0
- package/dist-server/service/data-sensor/data-sensor-type.js.map +1 -0
- package/dist-server/service/data-sensor/data-sensor.js +168 -0
- package/dist-server/service/data-sensor/data-sensor.js.map +1 -0
- package/dist-server/service/data-sensor/index.js +9 -0
- package/dist-server/service/data-sensor/index.js.map +1 -0
- package/dist-server/service/data-set/data-set-type.js +17 -0
- package/dist-server/service/data-set/data-set-type.js.map +1 -1
- package/dist-server/service/data-set/data-set.js +19 -0
- package/dist-server/service/data-set/data-set.js.map +1 -1
- package/dist-server/service/index.js +4 -0
- package/dist-server/service/index.js.map +1 -1
- package/package.json +12 -11
- package/server/routes.ts +76 -0
- package/server/service/data-item/data-item-type.ts +3 -3
- package/server/service/data-item/data-item.ts +6 -0
- package/server/service/data-sample/data-sample-mutation.ts +6 -3
- package/server/service/data-sample/data-sample-type.ts +15 -0
- package/server/service/data-sample/data-sample.ts +35 -0
- package/server/service/data-sensor/data-sensor-mutation.ts +110 -0
- package/server/service/data-sensor/data-sensor-query.ts +56 -0
- package/server/service/data-sensor/data-sensor-type.ts +98 -0
- package/server/service/data-sensor/data-sensor.ts +139 -0
- package/server/service/data-sensor/index.ts +6 -0
- package/server/service/data-set/data-set-type.ts +14 -0
- package/server/service/data-set/data-set.ts +17 -1
- package/server/service/index.ts +4 -0
- package/things-factory.config.js +4 -0
- package/translations/en.json +16 -5
- package/translations/ko.json +15 -4
- package/translations/ms.json +16 -5
- package/translations/zh.json +16 -5
package/client/bootstrap.js
CHANGED
@@ -135,6 +135,15 @@ class DataItemList extends localize(i18next)(LitElement) {
|
|
135
135
|
sortable: true,
|
136
136
|
width: 60
|
137
137
|
},
|
138
|
+
{
|
139
|
+
type: 'string',
|
140
|
+
name: 'tag',
|
141
|
+
header: i18next.t('field.tag'),
|
142
|
+
record: {
|
143
|
+
editable: true
|
144
|
+
},
|
145
|
+
width: 180
|
146
|
+
},
|
138
147
|
{
|
139
148
|
type: 'select',
|
140
149
|
name: 'type',
|
@@ -135,9 +135,14 @@ export class DataSample extends connect(store)(localize(i18next)(PageView)) {
|
|
135
135
|
width: 200
|
136
136
|
},
|
137
137
|
{
|
138
|
-
type: '
|
139
|
-
name: '
|
140
|
-
|
138
|
+
type: 'object',
|
139
|
+
name: 'dataSet',
|
140
|
+
header: i18next.t('field.data-set'),
|
141
|
+
record: {
|
142
|
+
editable: false
|
143
|
+
},
|
144
|
+
sortable: true,
|
145
|
+
width: 120
|
141
146
|
},
|
142
147
|
{
|
143
148
|
type: 'json',
|
@@ -157,7 +162,15 @@ export class DataSample extends connect(store)(localize(i18next)(PageView)) {
|
|
157
162
|
},
|
158
163
|
width: 200
|
159
164
|
},
|
160
|
-
|
165
|
+
{
|
166
|
+
type: 'code',
|
167
|
+
name: 'rawData',
|
168
|
+
header: i18next.t('field.raw-data'),
|
169
|
+
record: {
|
170
|
+
editable: false
|
171
|
+
},
|
172
|
+
width: 200
|
173
|
+
},
|
161
174
|
{
|
162
175
|
type: 'object',
|
163
176
|
name: 'updater',
|
@@ -171,6 +184,13 @@ export class DataSample extends connect(store)(localize(i18next)(PageView)) {
|
|
171
184
|
header: i18next.t('field.updated_at'),
|
172
185
|
sortable: true,
|
173
186
|
width: 180
|
187
|
+
},
|
188
|
+
{
|
189
|
+
type: 'datetime',
|
190
|
+
name: 'collectedAt',
|
191
|
+
header: i18next.t('field.collected_at'),
|
192
|
+
sortable: true,
|
193
|
+
width: 180
|
174
194
|
}
|
175
195
|
],
|
176
196
|
rows: {
|
@@ -210,7 +230,11 @@ export class DataSample extends connect(store)(localize(i18next)(PageView)) {
|
|
210
230
|
id
|
211
231
|
name
|
212
232
|
description
|
213
|
-
|
233
|
+
dataSet {
|
234
|
+
id
|
235
|
+
name
|
236
|
+
description
|
237
|
+
}
|
214
238
|
data
|
215
239
|
spec
|
216
240
|
updater {
|
@@ -218,6 +242,7 @@ export class DataSample extends connect(store)(localize(i18next)(PageView)) {
|
|
218
242
|
name
|
219
243
|
}
|
220
244
|
updatedAt
|
245
|
+
collectedAt
|
221
246
|
}
|
222
247
|
total
|
223
248
|
}
|
@@ -0,0 +1,451 @@
|
|
1
|
+
import '@operato/data-grist'
|
2
|
+
|
3
|
+
import gql from 'graphql-tag'
|
4
|
+
import { css, html } from 'lit'
|
5
|
+
import { connect } from 'pwa-helpers/connect-mixin'
|
6
|
+
|
7
|
+
import { client } from '@operato/graphql'
|
8
|
+
import { i18next, localize } from '@operato/i18n'
|
9
|
+
import { notify } from '@operato/layout'
|
10
|
+
import { PageView, store } from '@operato/shell'
|
11
|
+
import { CommonButtonStyles, ScrollbarStyles } from '@operato/styles'
|
12
|
+
import { isMobileDevice } from '@operato/utils'
|
13
|
+
|
14
|
+
export class DataSensor extends connect(store)(localize(i18next)(PageView)) {
|
15
|
+
static get properties() {
|
16
|
+
return {
|
17
|
+
active: String,
|
18
|
+
gristConfig: Object
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
static get styles() {
|
23
|
+
return [
|
24
|
+
ScrollbarStyles,
|
25
|
+
css`
|
26
|
+
:host {
|
27
|
+
display: flex;
|
28
|
+
flex-direction: column;
|
29
|
+
|
30
|
+
overflow: hidden;
|
31
|
+
}
|
32
|
+
|
33
|
+
ox-grist {
|
34
|
+
overflow-y: auto;
|
35
|
+
flex: 1;
|
36
|
+
}
|
37
|
+
|
38
|
+
#filters {
|
39
|
+
display: flex;
|
40
|
+
flex-direction: row;
|
41
|
+
justify-content: space-between;
|
42
|
+
|
43
|
+
background-color: white;
|
44
|
+
}
|
45
|
+
|
46
|
+
#filters > * {
|
47
|
+
padding: var(--padding-default) var(--padding-wide);
|
48
|
+
}
|
49
|
+
`
|
50
|
+
]
|
51
|
+
}
|
52
|
+
|
53
|
+
get context() {
|
54
|
+
return {
|
55
|
+
title: i18next.t('title.data-sensor list'),
|
56
|
+
help: 'integration/ui/data-sensor',
|
57
|
+
actions: [
|
58
|
+
{
|
59
|
+
title: i18next.t('button.copy'),
|
60
|
+
action: this._copyDataSensor.bind(this),
|
61
|
+
...CommonButtonStyles.copy
|
62
|
+
},
|
63
|
+
{
|
64
|
+
title: i18next.t('button.save'),
|
65
|
+
action: this._updateDataSensor.bind(this),
|
66
|
+
...CommonButtonStyles.save
|
67
|
+
},
|
68
|
+
{
|
69
|
+
title: i18next.t('button.delete'),
|
70
|
+
action: this._deleteDataSensor.bind(this),
|
71
|
+
...CommonButtonStyles.delete
|
72
|
+
}
|
73
|
+
]
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
render() {
|
78
|
+
return html`
|
79
|
+
<ox-grist
|
80
|
+
.mode=${isMobileDevice() ? 'LIST' : 'GRID'}
|
81
|
+
.config=${this.gristConfig}
|
82
|
+
.fetchHandler=${this.fetchHandler.bind(this)}
|
83
|
+
>
|
84
|
+
<div slot="headroom" id="filters">
|
85
|
+
<ox-filters-form></ox-filters-form>
|
86
|
+
</div>
|
87
|
+
</ox-grist>
|
88
|
+
`
|
89
|
+
}
|
90
|
+
|
91
|
+
get grist() {
|
92
|
+
return this.renderRoot.querySelector('ox-grist')
|
93
|
+
}
|
94
|
+
|
95
|
+
// update with url params value
|
96
|
+
_updateSearchConfig(lifecycle) {
|
97
|
+
// this.searchConfig = this.searchConfig.map(conf => {
|
98
|
+
// if (conf.name in lifecycle.params) {
|
99
|
+
// conf.value = lifecycle.params[conf.name]
|
100
|
+
// } else {
|
101
|
+
// delete conf.value
|
102
|
+
// }
|
103
|
+
// return conf
|
104
|
+
// })
|
105
|
+
}
|
106
|
+
|
107
|
+
// set default field value to record with searchConfig
|
108
|
+
_setDefaultFieldsValue(fields) {
|
109
|
+
// this.searchConfig.forEach(conf => {
|
110
|
+
// if (!fields[conf.name] && conf.value) {
|
111
|
+
// fields[conf.name] = conf.value
|
112
|
+
// }
|
113
|
+
// })
|
114
|
+
}
|
115
|
+
|
116
|
+
async pageInitialized(lifecycle) {
|
117
|
+
this._updateSearchConfig(lifecycle)
|
118
|
+
|
119
|
+
this.gristConfig = {
|
120
|
+
list: { fields: ['name', 'description', 'active'] },
|
121
|
+
columns: [
|
122
|
+
{ type: 'gutter', gutterName: 'sequence' },
|
123
|
+
{ type: 'gutter', gutterName: 'row-selector', multiple: true },
|
124
|
+
{
|
125
|
+
type: 'string',
|
126
|
+
name: 'name',
|
127
|
+
label: true,
|
128
|
+
header: i18next.t('field.name'),
|
129
|
+
record: {
|
130
|
+
editable: true
|
131
|
+
},
|
132
|
+
filter: 'search',
|
133
|
+
sortable: true,
|
134
|
+
width: 150
|
135
|
+
},
|
136
|
+
{
|
137
|
+
type: 'string',
|
138
|
+
name: 'description',
|
139
|
+
label: true,
|
140
|
+
header: i18next.t('field.description'),
|
141
|
+
record: {
|
142
|
+
editable: true
|
143
|
+
},
|
144
|
+
filter: 'search',
|
145
|
+
width: 200
|
146
|
+
},
|
147
|
+
{
|
148
|
+
type: 'checkbox',
|
149
|
+
name: 'active',
|
150
|
+
label: true,
|
151
|
+
header: i18next.t('field.active'),
|
152
|
+
record: {
|
153
|
+
editable: true
|
154
|
+
},
|
155
|
+
sortable: true,
|
156
|
+
width: 60
|
157
|
+
},
|
158
|
+
{
|
159
|
+
type: 'string',
|
160
|
+
name: 'deviceId',
|
161
|
+
label: true,
|
162
|
+
header: i18next.t('field.device-id'),
|
163
|
+
record: {
|
164
|
+
editable: true
|
165
|
+
},
|
166
|
+
filter: 'search',
|
167
|
+
sortable: true,
|
168
|
+
width: 150
|
169
|
+
},
|
170
|
+
{
|
171
|
+
type: 'string',
|
172
|
+
name: 'tag',
|
173
|
+
label: true,
|
174
|
+
header: i18next.t('field.tag'),
|
175
|
+
record: {
|
176
|
+
editable: true
|
177
|
+
},
|
178
|
+
sortable: true,
|
179
|
+
width: 150
|
180
|
+
},
|
181
|
+
{
|
182
|
+
type: 'object',
|
183
|
+
name: 'appliance',
|
184
|
+
header: i18next.t('field.appliance'),
|
185
|
+
record: {
|
186
|
+
editable: true,
|
187
|
+
options: {
|
188
|
+
queryName: 'appliances'
|
189
|
+
}
|
190
|
+
},
|
191
|
+
sortable: true,
|
192
|
+
width: 120
|
193
|
+
},
|
194
|
+
{
|
195
|
+
type: 'object',
|
196
|
+
name: 'dataSet',
|
197
|
+
header: i18next.t('field.data-set'),
|
198
|
+
record: {
|
199
|
+
editable: true,
|
200
|
+
options: {
|
201
|
+
queryName: 'dataSets'
|
202
|
+
}
|
203
|
+
},
|
204
|
+
sortable: true,
|
205
|
+
width: 120
|
206
|
+
},
|
207
|
+
{
|
208
|
+
type: 'string',
|
209
|
+
name: 'refBy',
|
210
|
+
label: true,
|
211
|
+
header: i18next.t('field.ref-by'),
|
212
|
+
record: {
|
213
|
+
editable: true
|
214
|
+
},
|
215
|
+
sortable: true,
|
216
|
+
width: 150
|
217
|
+
},
|
218
|
+
{
|
219
|
+
type: 'string',
|
220
|
+
name: 'model',
|
221
|
+
label: true,
|
222
|
+
header: i18next.t('field.model'),
|
223
|
+
record: {
|
224
|
+
editable: true
|
225
|
+
},
|
226
|
+
sortable: true,
|
227
|
+
width: 150
|
228
|
+
},
|
229
|
+
{
|
230
|
+
type: 'string',
|
231
|
+
name: 'brand',
|
232
|
+
label: true,
|
233
|
+
header: i18next.t('field.brand'),
|
234
|
+
record: {
|
235
|
+
editable: true
|
236
|
+
},
|
237
|
+
sortable: true,
|
238
|
+
width: 150
|
239
|
+
},
|
240
|
+
{
|
241
|
+
type: 'string',
|
242
|
+
name: 'serialNo',
|
243
|
+
label: true,
|
244
|
+
header: i18next.t('field.serial-no'),
|
245
|
+
record: {
|
246
|
+
editable: true
|
247
|
+
},
|
248
|
+
sortable: true,
|
249
|
+
width: 150
|
250
|
+
},
|
251
|
+
{
|
252
|
+
type: 'string',
|
253
|
+
name: 'netmask',
|
254
|
+
label: true,
|
255
|
+
header: i18next.t('field.netmask'),
|
256
|
+
record: {
|
257
|
+
editable: true
|
258
|
+
},
|
259
|
+
sortable: true,
|
260
|
+
width: 150
|
261
|
+
},
|
262
|
+
{
|
263
|
+
type: 'object',
|
264
|
+
name: 'updater',
|
265
|
+
header: i18next.t('field.updater'),
|
266
|
+
record: {
|
267
|
+
editable: false
|
268
|
+
},
|
269
|
+
sortable: true,
|
270
|
+
width: 120
|
271
|
+
},
|
272
|
+
{
|
273
|
+
type: 'datetime',
|
274
|
+
name: 'collectedAt',
|
275
|
+
header: i18next.t('field.collected_at'),
|
276
|
+
record: {
|
277
|
+
editable: false
|
278
|
+
},
|
279
|
+
sortable: true,
|
280
|
+
width: 180
|
281
|
+
}
|
282
|
+
],
|
283
|
+
rows: {
|
284
|
+
selectable: {
|
285
|
+
multiple: true
|
286
|
+
}
|
287
|
+
},
|
288
|
+
sorters: [
|
289
|
+
{
|
290
|
+
name: 'name'
|
291
|
+
}
|
292
|
+
]
|
293
|
+
}
|
294
|
+
|
295
|
+
await this.updateComplete
|
296
|
+
|
297
|
+
this.grist.fetch()
|
298
|
+
}
|
299
|
+
|
300
|
+
async pageUpdated(changes, lifecycle) {
|
301
|
+
if (this.active) {
|
302
|
+
// update with url params value
|
303
|
+
this._updateSearchConfig(lifecycle)
|
304
|
+
await this.updateComplete
|
305
|
+
|
306
|
+
this.grist.fetch()
|
307
|
+
}
|
308
|
+
}
|
309
|
+
|
310
|
+
async fetchHandler({ page, limit, sortings = [], filters = [] }) {
|
311
|
+
const response = await client.query({
|
312
|
+
query: gql`
|
313
|
+
query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
|
314
|
+
responses: dataSensors(filters: $filters, pagination: $pagination, sortings: $sortings) {
|
315
|
+
items {
|
316
|
+
id
|
317
|
+
name
|
318
|
+
description
|
319
|
+
active
|
320
|
+
deviceId
|
321
|
+
tag
|
322
|
+
appliance {
|
323
|
+
id
|
324
|
+
name
|
325
|
+
description
|
326
|
+
}
|
327
|
+
dataSet {
|
328
|
+
id
|
329
|
+
name
|
330
|
+
description
|
331
|
+
}
|
332
|
+
refBy
|
333
|
+
brand
|
334
|
+
model
|
335
|
+
serialNo
|
336
|
+
netmask
|
337
|
+
collecter {
|
338
|
+
id
|
339
|
+
name
|
340
|
+
}
|
341
|
+
collectedAt
|
342
|
+
updater {
|
343
|
+
id
|
344
|
+
name
|
345
|
+
}
|
346
|
+
updatedAt
|
347
|
+
}
|
348
|
+
total
|
349
|
+
}
|
350
|
+
}
|
351
|
+
`,
|
352
|
+
variables: {
|
353
|
+
filters,
|
354
|
+
pagination: { page, limit },
|
355
|
+
sortings
|
356
|
+
}
|
357
|
+
})
|
358
|
+
|
359
|
+
return {
|
360
|
+
total: response.data.responses.total || 0,
|
361
|
+
records: response.data.responses.items || []
|
362
|
+
}
|
363
|
+
}
|
364
|
+
|
365
|
+
async _deleteDataSensor() {
|
366
|
+
if (confirm(i18next.t('text.sure_to_x', { x: i18next.t('text.delete') }))) {
|
367
|
+
const ids = this.grist.selected.map(record => record.id)
|
368
|
+
if (ids && ids.length > 0) {
|
369
|
+
const response = await client.mutate({
|
370
|
+
mutation: gql`
|
371
|
+
mutation ($ids: [String!]!) {
|
372
|
+
deleteDataSensors(ids: $ids)
|
373
|
+
}
|
374
|
+
`,
|
375
|
+
variables: {
|
376
|
+
ids
|
377
|
+
}
|
378
|
+
})
|
379
|
+
|
380
|
+
if (!response.errors) {
|
381
|
+
this.grist.fetch()
|
382
|
+
notify({
|
383
|
+
message: i18next.t('text.info_x_successfully', { x: i18next.t('text.delete') })
|
384
|
+
})
|
385
|
+
}
|
386
|
+
}
|
387
|
+
}
|
388
|
+
}
|
389
|
+
|
390
|
+
async stateChanged(state) {
|
391
|
+
if (this.active && this._currentPopupName && !state.layout.viewparts[this._currentPopupName]) {
|
392
|
+
this.grist.fetch()
|
393
|
+
this._currentPopupName = null
|
394
|
+
}
|
395
|
+
}
|
396
|
+
|
397
|
+
async _copyDataSensor() {
|
398
|
+
var selected = this.grist.selected
|
399
|
+
if (selected.length == 0) return
|
400
|
+
|
401
|
+
if (!confirm(i18next.t('text.sure_to_x', { x: i18next.t('text.copy') }))) return
|
402
|
+
var response = await client.mutate({
|
403
|
+
mutation: gql`
|
404
|
+
mutation ($ids: [String!]!) {
|
405
|
+
copyDataSensors(ids: $ids) {
|
406
|
+
id
|
407
|
+
}
|
408
|
+
}
|
409
|
+
`,
|
410
|
+
variables: {
|
411
|
+
ids: selected.map(r => r.id)
|
412
|
+
}
|
413
|
+
})
|
414
|
+
|
415
|
+
if (!response.errors) this.grist.fetch()
|
416
|
+
}
|
417
|
+
|
418
|
+
async _updateDataSensor() {
|
419
|
+
let patches = this.grist.dirtyRecords
|
420
|
+
if (patches && patches.length) {
|
421
|
+
patches = patches.map(patch => {
|
422
|
+
let patchField = patch.id ? { id: patch.id } : {}
|
423
|
+
const dirtyFields = patch.__dirtyfields__
|
424
|
+
for (let key in dirtyFields) {
|
425
|
+
patchField[key] = dirtyFields[key].after
|
426
|
+
}
|
427
|
+
this._setDefaultFieldsValue(patchField)
|
428
|
+
patchField.cuFlag = patch.__dirty__
|
429
|
+
|
430
|
+
return patchField
|
431
|
+
})
|
432
|
+
|
433
|
+
const response = await client.mutate({
|
434
|
+
mutation: gql`
|
435
|
+
mutation ($patches: [DataSensorPatch!]!) {
|
436
|
+
updateMultipleDataSensor(patches: $patches) {
|
437
|
+
name
|
438
|
+
}
|
439
|
+
}
|
440
|
+
`,
|
441
|
+
variables: {
|
442
|
+
patches
|
443
|
+
}
|
444
|
+
})
|
445
|
+
|
446
|
+
if (!response.errors) this.grist.fetch()
|
447
|
+
}
|
448
|
+
}
|
449
|
+
}
|
450
|
+
|
451
|
+
window.customElements.define('data-sensor-page', DataSensor)
|
package/client/pages/data-set.js
CHANGED
@@ -181,6 +181,15 @@ export class DataSet extends connect(store)(localize(i18next)(PageView)) {
|
|
181
181
|
sortable: true,
|
182
182
|
width: 60
|
183
183
|
},
|
184
|
+
{
|
185
|
+
type: 'json',
|
186
|
+
name: 'partitionKeys',
|
187
|
+
header: i18next.t('field.partition-keys'),
|
188
|
+
record: {
|
189
|
+
editable: true
|
190
|
+
},
|
191
|
+
width: 200
|
192
|
+
},
|
184
193
|
{
|
185
194
|
type: 'crontab',
|
186
195
|
name: 'schedule',
|
@@ -259,6 +268,8 @@ export class DataSet extends connect(store)(localize(i18next)(PageView)) {
|
|
259
268
|
id
|
260
269
|
name
|
261
270
|
description
|
271
|
+
partitionKeys
|
272
|
+
slugger
|
262
273
|
active
|
263
274
|
schedule
|
264
275
|
timezone
|
@@ -354,9 +365,7 @@ export class DataSet extends connect(store)(localize(i18next)(PageView)) {
|
|
354
365
|
let patchField = patch.id ? { id: patch.id } : {}
|
355
366
|
const dirtyFields = patch.__dirtyfields__
|
356
367
|
for (let key in dirtyFields) {
|
357
|
-
|
358
|
-
patchField[key] = dirtyFields[key].after
|
359
|
-
}
|
368
|
+
patchField[key] = dirtyFields[key].after
|
360
369
|
}
|
361
370
|
this._setDefaultFieldsValue(patchField)
|
362
371
|
patchField.cuFlag = patch.__dirty__
|
package/client/route.js
CHANGED
package/dist-server/routes.js
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const typeorm_1 = require("typeorm");
|
4
|
+
const service_1 = require("./service");
|
5
|
+
const data_item_1 = require("./service/data-item/data-item");
|
6
|
+
const data_sensor_1 = require("./service/data-sensor/data-sensor");
|
1
7
|
const debug = require('debug')('things-factory:dataset:routes');
|
2
8
|
process.on('bootstrap-module-global-public-route', (app, globalPublicRouter) => {
|
3
9
|
/*
|
@@ -6,6 +12,64 @@ process.on('bootstrap-module-global-public-route', (app, globalPublicRouter) =>
|
|
6
12
|
* ex) routes.get('/path', async(context, next) => {})
|
7
13
|
* ex) routes.post('/path', async(context, next) => {})
|
8
14
|
*/
|
15
|
+
globalPublicRouter.post('/sensor-data', async (context, next) => {
|
16
|
+
// 데이타 검증
|
17
|
+
const { deviceId, data, rawData, timestamp = Date.now() } = context.request.body;
|
18
|
+
if (!deviceId || !data) {
|
19
|
+
throw new Error(`deviceId(${deviceId}) and data(${JSON.stringify(data)}) properties are mandatory`);
|
20
|
+
}
|
21
|
+
// make new data-sample
|
22
|
+
await (0, typeorm_1.getConnection)().transaction(async (tx) => {
|
23
|
+
// find sensor through deviceId
|
24
|
+
const sensor = await tx.getRepository(data_sensor_1.DataSensor).findOne({
|
25
|
+
where: { deviceId },
|
26
|
+
relations: ['domain', 'appliance', 'dataSet']
|
27
|
+
});
|
28
|
+
if (!sensor) {
|
29
|
+
throw new Error(`Sensor having given deviceId(${deviceId}) not found`);
|
30
|
+
}
|
31
|
+
if (!sensor.active) {
|
32
|
+
throw new Error(`State of the sensor given deviceId(${deviceId}) is not active`);
|
33
|
+
}
|
34
|
+
if (!sensor.appliance) {
|
35
|
+
throw new Error(`Appliance of the sensor given deviceId(${deviceId}) is not set up`);
|
36
|
+
}
|
37
|
+
if (!sensor.dataSet) {
|
38
|
+
throw new Error(`DataSet of the sensor given deviceId(${deviceId}) is not set up`);
|
39
|
+
}
|
40
|
+
const domain = sensor.domain;
|
41
|
+
const dataSet = sensor.dataSet;
|
42
|
+
const user = sensor.appliance;
|
43
|
+
const dataItems = await tx.getRepository(data_item_1.DataItem).find({
|
44
|
+
where: {
|
45
|
+
domain,
|
46
|
+
dataSet
|
47
|
+
},
|
48
|
+
order: {
|
49
|
+
sequence: 'DESC'
|
50
|
+
}
|
51
|
+
});
|
52
|
+
var spec = {};
|
53
|
+
dataItems.forEach(dataItem => {
|
54
|
+
spec[dataItem.name] = dataItem.spec;
|
55
|
+
});
|
56
|
+
await tx.getRepository(service_1.DataSample).save({
|
57
|
+
domain,
|
58
|
+
name: dataSet.name,
|
59
|
+
description: dataSet.description,
|
60
|
+
partitionKeys: dataSet.partitionKeys,
|
61
|
+
dataSet,
|
62
|
+
data,
|
63
|
+
rawData,
|
64
|
+
spec,
|
65
|
+
source: deviceId,
|
66
|
+
collectedAt: new Date(timestamp),
|
67
|
+
creator: user,
|
68
|
+
updater: user
|
69
|
+
});
|
70
|
+
});
|
71
|
+
return 'OK';
|
72
|
+
});
|
9
73
|
});
|
10
74
|
process.on('bootstrap-module-global-private-route', (app, globalPrivateRouter) => {
|
11
75
|
/*
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,+BAA+B,CAAC,CAAA;AAE/D,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE;IACpF;;;;;OAKG;
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":";;AAAA,qCAAuC;AAEvC,uCAAsC;AACtC,6DAAwD;AACxD,mE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CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE;IACpF;;OAEG;AACL,CAAC,CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,uCAA8C,EAAE,CAAC,GAAG,EAAE,mBAAmB,EAAE,EAAE;IACtF;;OAEG;AACL,CAAC,CAAC,CAAA"}
|
@@ -35,6 +35,10 @@ __decorate([
|
|
35
35
|
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true }),
|
36
36
|
__metadata("design:type", Number)
|
37
37
|
], DataItemPatch.prototype, "sequence", void 0);
|
38
|
+
__decorate([
|
39
|
+
(0, type_graphql_1.Field)({ nullable: true }),
|
40
|
+
__metadata("design:type", String)
|
41
|
+
], DataItemPatch.prototype, "tag", void 0);
|
38
42
|
__decorate([
|
39
43
|
(0, type_graphql_1.Field)(type => data_item_1.DataItemType, { nullable: true }),
|
40
44
|
__metadata("design:type", String)
|
@@ -43,10 +47,6 @@ __decorate([
|
|
43
47
|
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true }),
|
44
48
|
__metadata("design:type", Number)
|
45
49
|
], DataItemPatch.prototype, "quota", void 0);
|
46
|
-
__decorate([
|
47
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
48
|
-
__metadata("design:type", String)
|
49
|
-
], DataItemPatch.prototype, "options", void 0);
|
50
50
|
__decorate([
|
51
51
|
(0, type_graphql_1.Field)({ nullable: true }),
|
52
52
|
__metadata("design:type", Boolean)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"data-item-type.js","sourceRoot":"","sources":["../../../server/service/data-item/data-item-type.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAAoE;AAEpE,iDAAoD;AAEpD,2CAAoD;AAGpD,IAAa,aAAa,GAA1B,MAAa,aAAa;CAiCzB,CAAA;AA/BC;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBA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