-
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
Changes from 1 commit
0815a6e
b49599c
4842d41
7177f17
4072f92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,6 +236,7 @@ export class DeviceService { | |
} | ||
|
||
async mUnlink (devices: Device[], { strict }) { | ||
console.log('devices', devices); | ||
const unlinkedDevices = devices.filter(device => !device._source.assetId); | ||
|
||
if (strict && unlinkedDevices.length > 0) { | ||
|
@@ -270,7 +271,7 @@ export class DeviceService { | |
|
||
assetDocuments.push({ _id: device._source.assetId, body: { measures } }); | ||
} | ||
|
||
const updatedDevice = await this.writeToDatabase( | ||
deviceDocuments, | ||
async (deviceDocuments: DeviceMRequestContent[]): Promise<JSONObject> => { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. DItto |
||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. DItto |
||
|
||
return { | ||
successes: results.successes.concat(updated.successes), | ||
errors: results.errors.concat(updated.errors) | ||
|
@@ -315,17 +320,16 @@ export class DeviceService { | |
} | ||
|
||
private async eraseAssetMeasure (tenantId: string, device: Device) { | ||
const asset = await this.sdk.document.get(tenantId, 'assets', device._source.assetId); | ||
const { _source: { measures } } = await this.sdk.document.get(tenantId, 'assets', device._source.assetId); | ||
|
||
const measure = {}; | ||
|
||
for (const [key, value] of Object.entries(device._source.measures)) { | ||
if (!asset._source.measures[key]) { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Avoid the usage of |
||
} | ||
} | ||
|
||
return measure; | ||
return measures; | ||
} | ||
|
||
private async tenantExists (tenantId: string) { | ||
|
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 ... 👎