Skip to content

Commit

Permalink
avoid duplicate origintypeInformation
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed May 14, 2024
1 parent 9034c02 commit 1bbd168
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/services/ngsi/entities-NGSI-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,11 @@ function sendUpdateValueNgsi2(entityName, originMeasures, originTypeInformation,
}
}
//Make a clone and overwrite
let typeInformation = JSON.parse(JSON.stringify(originTypeInformation));
let idTypeSSSList = pluginUtils.getIdTypeServSubServiceFromDevice(typeInformation);
let idTypeSSSList = pluginUtils.getIdTypeServSubServiceFromDevice(originTypeInformation);

//Check mandatory information: type
if (!typeInformation || !typeInformation.type) {
callback(new errors.TypeNotFound(null, entityName, typeInformation));
if (!originTypeInformation || !originTypeInformation.type) {
callback(new errors.TypeNotFound(null, entityName, originTypeInformation));
return;
}

Expand All @@ -291,7 +290,8 @@ function sendUpdateValueNgsi2(entityName, originMeasures, originTypeInformation,
const currentIsoDate = new Date().toISOString();
const currentMoment = moment(currentIsoDate);
//Managing timestamp (mustInsertTimeInstant flag to decide if we should insert Timestamp later on)
const mustInsertTimeInstant = typeInformation.timestamp !== undefined ? typeInformation.timestamp : false;
const mustInsertTimeInstant =
originTypeInformation.timestamp !== undefined ? originTypeInformation.timestamp : false;

// Check if measures is a single measure or a array of measures (a multimeasure)
if (originMeasures[0] && !originMeasures[0][0]) {
Expand Down Expand Up @@ -620,7 +620,7 @@ function sendUpdateValueNgsi2(entityName, originMeasures, originTypeInformation,
} // end for (let measures of originMeasures)

let url = '/v2/op/update';
let options = NGSIUtils.createRequestObject(url, typeInformation, token);
let options = NGSIUtils.createRequestObject(url, originTypeInformation, token);
options.json = payload;

// Prevent to update an entity with an empty payload: more than id and type
Expand All @@ -645,7 +645,7 @@ function sendUpdateValueNgsi2(entityName, originMeasures, originTypeInformation,
if (!multi) {
// recreate options object to use single entity update
url = '/v2/entities?options=upsert';
options = NGSIUtils.createRequestObject(url, typeInformation, token);
options = NGSIUtils.createRequestObject(url, originTypeInformation, token);
delete payload.actionType;

let entityAttrs = payload.entities[0];
Expand All @@ -670,7 +670,7 @@ function sendUpdateValueNgsi2(entityName, originMeasures, originTypeInformation,

request(
options,
generateNGSI2OperationHandler('update', entityName, typeInformation, token, options, callback)
generateNGSI2OperationHandler('update', entityName, originTypeInformation, token, options, callback)
);
} else {
logger.debug(
Expand Down

0 comments on commit 1bbd168

Please sign in to comment.