Skip to content

Commit

Permalink
Add basic metadata comparison method before update to legacy harvest …
Browse files Browse the repository at this point in the history
…method in api record controller
  • Loading branch information
alejandro-bulgaris-qcif committed Jun 26, 2024
1 parent 3ddae5a commit f5b3150
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion typescript/api/controllers/webservice/RecordController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,19 @@ export module Controllers {
return this.apiFailWrapper(req, res, 400, null, null, "Invalid request");
}

private isMetadataEqual(meta1:any, meta2:any): boolean {

let keys = _.keys(meta1);

for(let key of keys) {
if(_.get(meta1,key,'') != _.get(meta2,key,'')) {
return false;
}
}

return true;
}

public async legacyHarvest(req, res) {
const brand:BrandingModel = BrandingService.getBrand(req.session.branding);

Expand Down Expand Up @@ -1108,7 +1121,21 @@ export module Controllers {
recordResponses.push(await this.createHarvestRecord(brand, recordTypeModel, record['metadata']['data'], harvestId, 'update', user));
} else {
let oid = existingRecord[0].redboxOid;
recordResponses.push(await this.updateHarvestRecord(brand, recordTypeModel, 'update', record['metadata']['data'], oid, harvestId, user));
let oldMetadata = existingRecord[0].metadata;
let newMetadata = record['metadata']['data'];
let response = {
details: '',
message: `skip update of harvestId ${harvestId} oid ${oid} metadata sent is equal to metadata in existing record`,
harvestId: harvestId,
oid: oid,
status: true
};
if(this.isMetadataEqual(newMetadata,oldMetadata)) {
recordResponses.push(response);
} else {
response = await this.updateHarvestRecord(brand, recordTypeModel, 'update', newMetadata, oid, harvestId, user);
recordResponses.push(response);
}
}
}
}
Expand Down

0 comments on commit f5b3150

Please sign in to comment.