Skip to content

Commit acfd8a0

Browse files
cyrngetrousset
andauthored
fix(device-metadata): fetch device's metadata from assigned tenant when available (#374)
* fix(measure): fetch tenant device content if exist * Update lib/modules/decoder/PayloadService.ts --------- Co-authored-by: Eric <31733541+etrousset@users.noreply.github.com>
1 parent aa11885 commit acfd8a0

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/modules/decoder/PayloadService.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,20 @@ export class PayloadService extends BaseService {
174174
),
175175
);
176176

177+
// Due to the existence of a "devices" collection in the tenant index and a platform index,
178+
// we need to fetch the device content from the associated tenant if it exists.
179+
const updatedDevices = await Promise.all(
180+
devices.map((device) =>
181+
device._source.engineId && device._source.engineId.trim() !== ""
182+
? this.sdk.document.get<DeviceContent>(
183+
device._source.engineId,
184+
InternalCollection.DEVICES,
185+
device._id,
186+
)
187+
: device,
188+
),
189+
);
190+
177191
// If we have unknown devices, let's check if we should register them
178192
if (errors.length > 0) {
179193
const { _source } = await this.sdk.document.get(
@@ -186,7 +200,7 @@ export class PayloadService extends BaseService {
186200
const newDevices = await this.provisionDevices(deviceModel, errors, {
187201
refresh,
188202
});
189-
devices.push(...newDevices);
203+
updatedDevices.push(...newDevices);
190204
} else {
191205
this.app.log.info(
192206
`Skipping new devices "${errors.join(
@@ -196,7 +210,7 @@ export class PayloadService extends BaseService {
196210
}
197211
}
198212

199-
return devices;
213+
return updatedDevices;
200214
}
201215

202216
private async provisionDevices(

0 commit comments

Comments
 (0)