Skip to content

Commit

Permalink
fix(assetservice): allow metadata update if existing in assetModel ma…
Browse files Browse the repository at this point in the history
…ppings
  • Loading branch information
QuentinRousselet committed Nov 25, 2024
1 parent 53b18fc commit bd2d669
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/modules/asset/AssetService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,26 @@ export class AssetService extends DigitalTwinService {
request: KuzzleRequest,
): Promise<KDocument<AssetContent>> {
const asset = await this.get(engineId, assetId, request);

const unknownMetadata = {};
for (const key in metadata) {
if (key in asset._source.metadata) {
asset._source.metadata[key] = metadata[key];
} else {
unknownMetadata[key] = metadata[key];
}
}
// ? If metadata key is unknown on the asset we check that it exists in the assetModel mappings
if (Object.keys(unknownMetadata).length > 0) {
const assetModel = await ask<AskModelAssetGet>(
"ask:device-manager:model:asset:get",
{ engineGroup: engineId.split("-")[1], model: asset._source.model },
);
for (const key in unknownMetadata) {
if (key in assetModel.asset.metadataMappings) {
asset._source.metadata[key] = unknownMetadata[key];
}
}
}

const updatedPayload = await this.app.trigger<EventAssetUpdateBefore>(
"device-manager:asset:update:before",
{ asset, metadata },
Expand Down

0 comments on commit bd2d669

Please sign in to comment.