nayota-show-sdk 1.3.85 → 1.3.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/utils/iot-module-specs.js +54 -21
- package/utils/iot-module-specs.test.js +116 -0
package/package.json
CHANGED
|
@@ -193,7 +193,9 @@ function mapIotAreaToLegacy(item = {}) {
|
|
|
193
193
|
...entity,
|
|
194
194
|
depart: entity.hierarchyId,
|
|
195
195
|
visible: entity.isVisible,
|
|
196
|
-
|
|
196
|
+
area: normalizeLegacyNumber(entity.area),
|
|
197
|
+
areaSize: normalizeLegacyNumber(entity.area),
|
|
198
|
+
opacity: normalizeLegacyNumber(entity.opacity),
|
|
197
199
|
areaClass: entity.areaClassId,
|
|
198
200
|
targetDepartId: entity.targetHierarchyId,
|
|
199
201
|
type: metadata.legacyType || entity.type,
|
|
@@ -247,12 +249,25 @@ function mapIotComponentsToLegacy(item = {}) {
|
|
|
247
249
|
})
|
|
248
250
|
}
|
|
249
251
|
|
|
250
|
-
function
|
|
251
|
-
if (data
|
|
252
|
-
return data
|
|
252
|
+
function normalizeHierarchyField(data = {}, field) {
|
|
253
|
+
if (hasOwn(data, field)) {
|
|
254
|
+
return data[field]
|
|
253
255
|
}
|
|
254
256
|
|
|
255
|
-
return getNestedValue(data,
|
|
257
|
+
return getNestedValue(data, `relationInfo.${field}`)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function normalizeLegacyHierarchyRelationInfo(item = {}) {
|
|
261
|
+
const relationInfo = removeUndefinedFields({
|
|
262
|
+
...(item.relationInfo || {}),
|
|
263
|
+
image: getNestedValue(item, 'relationInfo.image') || item.floorPlan,
|
|
264
|
+
mapCenter: getNestedValue(item, 'relationInfo.mapCenter') || item.mapCenter,
|
|
265
|
+
latlng: getNestedValue(item, 'relationInfo.latlng') || item.latlng,
|
|
266
|
+
zooms: getNestedValue(item, 'relationInfo.zooms') || item.zooms,
|
|
267
|
+
powers: getNestedValue(item, 'relationInfo.powers') || item.powers
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
return Object.keys(relationInfo || {}).length ? relationInfo : undefined
|
|
256
271
|
}
|
|
257
272
|
|
|
258
273
|
function mapDepartsToIotBody(data = {}) {
|
|
@@ -263,39 +278,51 @@ function mapDepartsToIotBody(data = {}) {
|
|
|
263
278
|
: hasFather
|
|
264
279
|
? resolveLegacyReference(data.father)
|
|
265
280
|
: undefined
|
|
266
|
-
const metadata =
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
281
|
+
const metadata = omitKeys(data.metadata, [
|
|
282
|
+
'departTag',
|
|
283
|
+
'hierarchyTag',
|
|
284
|
+
'sort',
|
|
285
|
+
'level',
|
|
286
|
+
'fathers',
|
|
287
|
+
'mapCenter',
|
|
288
|
+
'latlng',
|
|
289
|
+
'zooms',
|
|
290
|
+
'powers',
|
|
291
|
+
'floorPlan',
|
|
292
|
+
'relationInfo',
|
|
293
|
+
'departNo'
|
|
294
|
+
])
|
|
274
295
|
|
|
275
296
|
return removeUndefinedFields({
|
|
276
297
|
...omitKeys(data, [
|
|
277
298
|
'_id',
|
|
278
299
|
'id',
|
|
279
300
|
'father',
|
|
301
|
+
'departTag',
|
|
280
302
|
'sort',
|
|
281
303
|
'status',
|
|
282
|
-
'mapCenter',
|
|
283
|
-
'latlng',
|
|
284
|
-
'zooms',
|
|
285
|
-
'powers',
|
|
286
304
|
'departNo'
|
|
287
305
|
]),
|
|
288
306
|
code: data.code || data.departNo || undefined,
|
|
307
|
+
hierarchyTag: resolveLegacyReference(
|
|
308
|
+
data.hierarchyTag != null ? data.hierarchyTag : data.departTag
|
|
309
|
+
),
|
|
289
310
|
parentId,
|
|
290
311
|
sortOrder: data.sortOrder != null ? data.sortOrder : data.sort,
|
|
291
312
|
isActive: data.isActive != null ? data.isActive : data.status,
|
|
292
|
-
|
|
313
|
+
mapCenter: normalizeHierarchyField(data, 'mapCenter'),
|
|
314
|
+
latlng: normalizeHierarchyField(data, 'latlng'),
|
|
315
|
+
zooms: normalizeHierarchyField(data, 'zooms'),
|
|
316
|
+
powers: normalizeHierarchyField(data, 'powers'),
|
|
317
|
+
floorPlan: data.floorPlan,
|
|
293
318
|
metadata: Object.keys(metadata).length ? metadata : undefined
|
|
294
319
|
})
|
|
295
320
|
}
|
|
296
321
|
|
|
297
322
|
function mapIotDepartsToLegacy(item = {}) {
|
|
298
323
|
const entity = withLegacyId(item)
|
|
324
|
+
const relationInfo = normalizeLegacyHierarchyRelationInfo(entity)
|
|
325
|
+
|
|
299
326
|
return removeUndefinedFields({
|
|
300
327
|
...entity,
|
|
301
328
|
father: entity.father != null ? entity.father : entity.parentId,
|
|
@@ -304,9 +331,15 @@ function mapIotDepartsToLegacy(item = {}) {
|
|
|
304
331
|
? entity.level
|
|
305
332
|
: Array.isArray(entity.ancestors) ? entity.ancestors.length : undefined,
|
|
306
333
|
status: entity.status != null ? entity.status : entity.isActive,
|
|
307
|
-
sort: entity.sort != null ? entity.sort :
|
|
308
|
-
|
|
309
|
-
|
|
334
|
+
sort: entity.sort != null ? entity.sort : entity.sortOrder,
|
|
335
|
+
hierarchyTag: entity.hierarchyTag,
|
|
336
|
+
departTag: entity.departTag != null ? entity.departTag : entity.hierarchyTag,
|
|
337
|
+
mapCenter: entity.mapCenter,
|
|
338
|
+
latlng: entity.latlng,
|
|
339
|
+
zooms: entity.zooms,
|
|
340
|
+
powers: entity.powers,
|
|
341
|
+
relationInfo,
|
|
342
|
+
departNo: entity.departNo || entity.code
|
|
310
343
|
})
|
|
311
344
|
}
|
|
312
345
|
|
|
@@ -190,6 +190,101 @@ describe('iotModuleSpecs departs hierarchy compatibility', () => {
|
|
|
190
190
|
})
|
|
191
191
|
})
|
|
192
192
|
|
|
193
|
+
test('writes hierarchy map fields as official v2 columns instead of metadata', () => {
|
|
194
|
+
const request = departs.updateOne.toRequest({
|
|
195
|
+
_id: 'e245a3f6-d2c7-4ce1-9e02-ba9bbb347ed7',
|
|
196
|
+
departTag: 'd4bd5d8b-163f-4df4-b8e2-6ee7de7a0e6d',
|
|
197
|
+
relationInfo: {
|
|
198
|
+
image: {
|
|
199
|
+
imagePath: 'upload.svg'
|
|
200
|
+
},
|
|
201
|
+
mapCenter: [120.1, 30.2],
|
|
202
|
+
latlng: [120.1, 30.2],
|
|
203
|
+
zooms: [17],
|
|
204
|
+
powers: ['read']
|
|
205
|
+
},
|
|
206
|
+
metadata: {
|
|
207
|
+
departTag: 'legacy-tag',
|
|
208
|
+
sort: 9,
|
|
209
|
+
level: 1,
|
|
210
|
+
fathers: ['legacy-parent'],
|
|
211
|
+
mapCenter: [1, 2],
|
|
212
|
+
latlng: [3, 4],
|
|
213
|
+
zooms: [5],
|
|
214
|
+
powers: ['legacy'],
|
|
215
|
+
keep: 'value'
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
expect(request.data.hierarchyTag).toBe('d4bd5d8b-163f-4df4-b8e2-6ee7de7a0e6d')
|
|
220
|
+
expect(request.data.mapCenter).toEqual([120.1, 30.2])
|
|
221
|
+
expect(request.data.latlng).toEqual([120.1, 30.2])
|
|
222
|
+
expect(request.data.zooms).toEqual([17])
|
|
223
|
+
expect(request.data.powers).toEqual(['read'])
|
|
224
|
+
expect(request.data.relationInfo).toEqual({
|
|
225
|
+
image: {
|
|
226
|
+
imagePath: 'upload.svg'
|
|
227
|
+
},
|
|
228
|
+
mapCenter: [120.1, 30.2],
|
|
229
|
+
latlng: [120.1, 30.2],
|
|
230
|
+
zooms: [17],
|
|
231
|
+
powers: ['read']
|
|
232
|
+
})
|
|
233
|
+
expect(request.data.metadata).toEqual({ keep: 'value' })
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
test('rebuilds legacy relationInfo from official hierarchy fields and ignores metadata fallbacks', () => {
|
|
237
|
+
const response = departs.list.fromResponse({
|
|
238
|
+
code: 0,
|
|
239
|
+
data: {
|
|
240
|
+
total: 1,
|
|
241
|
+
items: [
|
|
242
|
+
{
|
|
243
|
+
id: 'hierarchy-1',
|
|
244
|
+
name: '1F',
|
|
245
|
+
hierarchyTag: 'd4bd5d8b-163f-4df4-b8e2-6ee7de7a0e6d',
|
|
246
|
+
mapCenter: [120.1, 30.2],
|
|
247
|
+
latlng: [120.1, 30.2],
|
|
248
|
+
zooms: [17],
|
|
249
|
+
powers: ['read'],
|
|
250
|
+
floorPlan: {
|
|
251
|
+
imagePath: 'upload.svg'
|
|
252
|
+
},
|
|
253
|
+
metadata: {
|
|
254
|
+
mapCenter: [120.1, 30.2],
|
|
255
|
+
latlng: [120.1, 30.2],
|
|
256
|
+
zooms: [17],
|
|
257
|
+
powers: ['read'],
|
|
258
|
+
relationInfo: {
|
|
259
|
+
image: {
|
|
260
|
+
imagePath: 'upload.svg'
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
departNo: 'building4'
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
]
|
|
267
|
+
}
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
expect(response.data.rows[0].hierarchyTag).toBe('d4bd5d8b-163f-4df4-b8e2-6ee7de7a0e6d')
|
|
271
|
+
expect(response.data.rows[0].departTag).toBe('d4bd5d8b-163f-4df4-b8e2-6ee7de7a0e6d')
|
|
272
|
+
expect(response.data.rows[0].mapCenter).toEqual([120.1, 30.2])
|
|
273
|
+
expect(response.data.rows[0].latlng).toEqual([120.1, 30.2])
|
|
274
|
+
expect(response.data.rows[0].zooms).toEqual([17])
|
|
275
|
+
expect(response.data.rows[0].powers).toEqual(['read'])
|
|
276
|
+
expect(response.data.rows[0].relationInfo).toEqual({
|
|
277
|
+
image: {
|
|
278
|
+
imagePath: 'upload.svg'
|
|
279
|
+
},
|
|
280
|
+
mapCenter: [120.1, 30.2],
|
|
281
|
+
latlng: [120.1, 30.2],
|
|
282
|
+
zooms: [17],
|
|
283
|
+
powers: ['read']
|
|
284
|
+
})
|
|
285
|
+
expect(response.data.rows[0].departNo).toBeUndefined()
|
|
286
|
+
})
|
|
287
|
+
|
|
193
288
|
test('keeps explicit legacy father null as root move', () => {
|
|
194
289
|
const request = departs.updateOne.toRequest({
|
|
195
290
|
_id: 'e245a3f6-d2c7-4ce1-9e02-ba9bbb347ed7',
|
|
@@ -237,6 +332,27 @@ describe('iotModuleSpecs area space compatibility', () => {
|
|
|
237
332
|
expect(response.data.rows[0].centerCoordinate).toEqual([12, 34])
|
|
238
333
|
})
|
|
239
334
|
|
|
335
|
+
test('normalizes pg decimal strings to legacy numeric area fields', () => {
|
|
336
|
+
const response = area.list.fromResponse({
|
|
337
|
+
code: 0,
|
|
338
|
+
data: {
|
|
339
|
+
total: 1,
|
|
340
|
+
items: [
|
|
341
|
+
{
|
|
342
|
+
id: 'space-1',
|
|
343
|
+
name: '前厅区域',
|
|
344
|
+
area: '123.45',
|
|
345
|
+
opacity: '0.80'
|
|
346
|
+
}
|
|
347
|
+
]
|
|
348
|
+
}
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
expect(response.data.rows[0].area).toBe(123.45)
|
|
352
|
+
expect(response.data.rows[0].areaSize).toBe(123.45)
|
|
353
|
+
expect(response.data.rows[0].opacity).toBe(0.8)
|
|
354
|
+
})
|
|
355
|
+
|
|
240
356
|
test('does not clear areaClassId on partial statistics sync updates', () => {
|
|
241
357
|
const request = area.updateOne.toRequest({
|
|
242
358
|
_id: '4f168184-9ef0-4068-b494-2ee861db0c08',
|