nayota-show-sdk 1.3.86 → 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 +51 -20
- package/utils/iot-module-specs.test.js +95 -0
package/package.json
CHANGED
|
@@ -249,12 +249,25 @@ function mapIotComponentsToLegacy(item = {}) {
|
|
|
249
249
|
})
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
function
|
|
253
|
-
if (data
|
|
254
|
-
return data
|
|
252
|
+
function normalizeHierarchyField(data = {}, field) {
|
|
253
|
+
if (hasOwn(data, field)) {
|
|
254
|
+
return data[field]
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
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
|
|
258
271
|
}
|
|
259
272
|
|
|
260
273
|
function mapDepartsToIotBody(data = {}) {
|
|
@@ -265,39 +278,51 @@ function mapDepartsToIotBody(data = {}) {
|
|
|
265
278
|
: hasFather
|
|
266
279
|
? resolveLegacyReference(data.father)
|
|
267
280
|
: undefined
|
|
268
|
-
const metadata =
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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
|
+
])
|
|
276
295
|
|
|
277
296
|
return removeUndefinedFields({
|
|
278
297
|
...omitKeys(data, [
|
|
279
298
|
'_id',
|
|
280
299
|
'id',
|
|
281
300
|
'father',
|
|
301
|
+
'departTag',
|
|
282
302
|
'sort',
|
|
283
303
|
'status',
|
|
284
|
-
'mapCenter',
|
|
285
|
-
'latlng',
|
|
286
|
-
'zooms',
|
|
287
|
-
'powers',
|
|
288
304
|
'departNo'
|
|
289
305
|
]),
|
|
290
306
|
code: data.code || data.departNo || undefined,
|
|
307
|
+
hierarchyTag: resolveLegacyReference(
|
|
308
|
+
data.hierarchyTag != null ? data.hierarchyTag : data.departTag
|
|
309
|
+
),
|
|
291
310
|
parentId,
|
|
292
311
|
sortOrder: data.sortOrder != null ? data.sortOrder : data.sort,
|
|
293
312
|
isActive: data.isActive != null ? data.isActive : data.status,
|
|
294
|
-
|
|
313
|
+
mapCenter: normalizeHierarchyField(data, 'mapCenter'),
|
|
314
|
+
latlng: normalizeHierarchyField(data, 'latlng'),
|
|
315
|
+
zooms: normalizeHierarchyField(data, 'zooms'),
|
|
316
|
+
powers: normalizeHierarchyField(data, 'powers'),
|
|
317
|
+
floorPlan: data.floorPlan,
|
|
295
318
|
metadata: Object.keys(metadata).length ? metadata : undefined
|
|
296
319
|
})
|
|
297
320
|
}
|
|
298
321
|
|
|
299
322
|
function mapIotDepartsToLegacy(item = {}) {
|
|
300
323
|
const entity = withLegacyId(item)
|
|
324
|
+
const relationInfo = normalizeLegacyHierarchyRelationInfo(entity)
|
|
325
|
+
|
|
301
326
|
return removeUndefinedFields({
|
|
302
327
|
...entity,
|
|
303
328
|
father: entity.father != null ? entity.father : entity.parentId,
|
|
@@ -306,9 +331,15 @@ function mapIotDepartsToLegacy(item = {}) {
|
|
|
306
331
|
? entity.level
|
|
307
332
|
: Array.isArray(entity.ancestors) ? entity.ancestors.length : undefined,
|
|
308
333
|
status: entity.status != null ? entity.status : entity.isActive,
|
|
309
|
-
sort: entity.sort != null ? entity.sort :
|
|
310
|
-
|
|
311
|
-
|
|
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
|
|
312
343
|
})
|
|
313
344
|
}
|
|
314
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',
|