Skip to content

Commit c6cde22

Browse files
author
Adrien Maret
authored
2.0.0-rc8 : Allows to register measure with a value of same mappings (#206)
1 parent f31a6ed commit c6cde22

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed

lib/core-classes/AssetCategoryService.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { MetadataContent } from '../types/MetadataContent';
22
import { AssetCategoryContent, FormattedMetadata, FormattedValue } from '../types/AssetCategoryContent';
33
import { JSONObject, Plugin, PluginContext } from 'kuzzle';
44
import { DeviceManagerConfiguration } from '../types';
5-
import isEqual from 'lodash.isequal';
5+
import _ from 'lodash';
66

77
export class AssetCategoryService {
88

@@ -33,7 +33,7 @@ export class AssetCategoryService {
3333
}
3434
}
3535
}
36-
36+
3737
async getMetadata (assetCategory : AssetCategoryContent, engineId : string) : Promise<MetadataContent[]> {
3838
let metadataList;
3939
metadataList = [];
@@ -107,7 +107,7 @@ export class AssetCategoryService {
107107
let find = false;
108108
for (const objectValue of metadata.objectValueList) {
109109
const fromattedObjectValue = this.formatMetadataForGet(objectValue.object);
110-
if (isEqual(fromattedObjectValue, value)) {
110+
if (_.isEqual(fromattedObjectValue, value)) {
111111
find = true;
112112
break;
113113
}
@@ -123,7 +123,7 @@ export class AssetCategoryService {
123123
if (metadata.key === name) {
124124
return true;
125125
}
126-
}
126+
}
127127
return false;
128128
}
129129

@@ -188,7 +188,7 @@ export class AssetCategoryService {
188188
else if (value.object ) {
189189
if (format) {
190190
return this.formatMetadataForGet(value.object);
191-
}
191+
}
192192
return value.object;
193193
}
194194
return value.boolean;

lib/core-classes/registers/MeasuresRegister.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { JSONObject, PluginImplementationError } from 'kuzzle';
2+
import _ from 'lodash';
23

34
import { measuresMappings } from '../../mappings';
45
import { MeasureDefinition } from '../../types';
@@ -27,7 +28,7 @@ export class MeasuresRegister {
2728
* sign: '%',
2829
* type: 'number',
2930
* },
30-
* mappings: { humidity: { type: 'float' } },
31+
* valuesMappings: { humidity: { type: 'float' } },
3132
* });
3233
* ```
3334
*/
@@ -37,8 +38,8 @@ export class MeasuresRegister {
3738
}
3839

3940
for (const [field, definition] of Object.entries(measure.valuesMappings)) {
40-
if (this.mappings.properties.values.properties[field]) {
41-
throw new PluginImplementationError(`Field "${type}" already exists in measures mappings.`);
41+
if (this.mappings.properties.values.properties[field] && ! _.isEqual(this.mappings.properties.values.properties[field], definition)) {
42+
throw new PluginImplementationError(`Measure "${type}" register a different type for value "${field}".`);
4243
}
4344

4445
this.mappings.properties.values.properties[field] = definition;

package-lock.json

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kuzzle-device-manager",
3-
"version": "2.0.0-rc7",
3+
"version": "2.0.0-rc8",
44
"description": "Manage your IoT devices and assets. Choose a provisioning strategy, receive and decode payload, handle your IoT business logic.",
55
"author": "The Kuzzle Team (support@kuzzle.io)",
66
"repository": {
@@ -27,8 +27,8 @@
2727
"csvtojson": "~2.0.10",
2828
"json-stable-stringify": "^1.0.1",
2929
"kuzzle-plugin-commons": "https://github.com/kuzzleio/kuzzle-plugin-commons/archive/refs/tags/1.0.4.tar.gz",
30-
"lodash.isequal": "^4.5.0",
31-
"uuid": "~8.3.2"
30+
"uuid": "~8.3.2",
31+
"lodash": "^4.17.21"
3232
},
3333
"devDependencies": {
3434
"@types/node": "^17.0.21",
@@ -40,7 +40,6 @@
4040
"eslint": "^8.10.0",
4141
"kuzzle": "^2.18.1",
4242
"kuzzle-sdk": "^7.9.1",
43-
"lodash": "^4.17.21",
4443
"should": "^13.2.3",
4544
"ts-node": "^10.7.0",
4645
"typescript": "^4.6.2"

0 commit comments

Comments
 (0)