-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add device:mUnlink API action #60
Conversation
|
||
--- | ||
|
||
### Optional: | ||
|
||
* `refresh`: if set to `wait_for`, Kuzzle will not respond until the documents are indexed | ||
* `strict`: (boolean) if set, makes the process fail preemptively if at least one link cannot be applied (e.g. devices that aren't attached to a tenant, or because of non-existing assets) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be true
by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO it's better not because some of the device can still be attached and you can correct the errors and then reimport the same document
@@ -18,7 +18,7 @@ The device document will be duplicated inside the tenant "devices" collection. | |||
### HTTP | |||
|
|||
``` http | |||
URL: http://kuzzle:7512/_/device-manager/devices/_mAttach | |||
URL: http://kuzzle:7512/_/device-manager/devices/_mAttach[?refresh=wait_for][&strict=true|false] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boolean flag are true if set and false if not set, they can't have explicit value
|
||
--- | ||
|
||
### Optional: | ||
|
||
* `refresh`: if set to `wait_for`, Kuzzle will not respond until the documents are indexed | ||
* `strict`: (boolean) if set, makes the process fail preemptively if at least one link cannot be applied (e.g. devices that aren't attached to a tenant, or because of non-existing assets) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO it's better not because some of the device can still be attached and you can correct the errors and then reimport the same document
lib/services/DeviceService.ts
Outdated
for (const device of devicesContent) { | ||
// Build Kuzzle mQueries | ||
deviceDocuments.push({ _id: device._id, body: { assetId: null } }); | ||
assetDocuments.push({ _id: device._source.assetId, body: { measures: null } }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An asset can have multiple linked device and thus measure from those devices. Here you are reseting every measures.
lib/services/DeviceService.ts
Outdated
private async eraseAssetMeasure (tenantId: string, device: Device) { | ||
const asset = await this.sdk.document.get(tenantId, 'assets', device._source.assetId); | ||
|
||
const measure = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicking/naming: this object represents one or more measures
lib/services/DeviceService.ts
Outdated
|
||
const measure = {}; | ||
|
||
for (const [key, value] of Object.entries(device._source.measures)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicking/naming: key and value represents the measureName and the measure itself
features/DeviceController.feature
Outdated
@@ -190,7 +190,7 @@ Feature: Device Manager device controller | |||
Then The document "tenant-ayse":"devices":"DummyTemp_attached-ayse-unlinked" content match: | |||
| assetId | null | | |||
And The document "tenant-ayse":"assets":"PERFO-unlinked" content match: | |||
| measures | null | | |||
| measures | {} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a test with an asset who have the measures of two different devices to ensure the feature is working as expected ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes ofc
lib/services/DeviceService.ts
Outdated
@@ -236,6 +236,7 @@ export class DeviceService { | |||
} | |||
|
|||
async mUnlink (devices: Device[], { strict }) { | |||
console.log('devices', devices); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug leftover
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, i was somehow sure i deleted them ... 👎
lib/services/DeviceService.ts
Outdated
@@ -294,12 +295,16 @@ export class DeviceService { | |||
const updatedAssets = await this.writeToDatabase( | |||
assetDocuments, | |||
async (assetDocuments: DeviceMRequestContent[]): Promise<JSONObject> => { | |||
|
|||
console.log(JSON.stringify(assetDocuments)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DItto
lib/services/DeviceService.ts
Outdated
|
||
const updated = await this.sdk.document.mUpdate( | ||
document.tenantId, | ||
'assets', | ||
assetDocuments); | ||
|
||
console.log(updated); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DItto
lib/services/DeviceService.ts
Outdated
measure[key] = value; | ||
for (const [measureName] of Object.entries(device._source.measures)) { | ||
if (measures[measureName]) { | ||
delete measures[measureName]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid the usage of delete
who always trigger deoptimization from turbofan because the object internal shape is changing.
You can set the value to undefined
, it will be ignored by the JSON parsers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
No description provided.