Skip to content

Commit

Permalink
Merge pull request #235 from telefonicaid/fix/remove_non_found_protocol
Browse files Browse the repository at this point in the history
Fix/remove non found protocol
  • Loading branch information
fgalan authored Mar 4, 2021
2 parents c9f8e85 + 42898ca commit 0d655fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Fix: ensure protocol exists before remove it (#234)
- Fix: print URI in logs about redirection error (#232)
- Upgrade NodeJS version from 10 to 12 in Dockerfile due to Node 10 End-of-Life
- Set Nodejs 12 as minimum version in packages.json (effectively removing Nodev10 from supported versions)
Expand Down
28 changes: 16 additions & 12 deletions lib/services/protocolData.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const context = {
};

function processConfiguration(protocol, description, iotagent, resource, configuration, callback) {
configurations.get(configuration.apikey, resource, protocol, function(error, oldConfiguration) {
configurations.get(configuration.apikey, resource, protocol, function (error, oldConfiguration) {
if (error) {
callback(error);
} else if (oldConfiguration.services.length === 0) {
Expand All @@ -61,7 +61,7 @@ function cleanConfigurations(protocol, iotagent, resource, callback) {
resource
},
/* eslint-disable-next-line no-unused-vars */
function(error, commandResult) {
function (error, commandResult) {
if (error) {
logger.error(context, 'MONGODB-003: Internal MongoDB Error removing services from protocol: %s', error);

Expand All @@ -87,7 +87,7 @@ function getProtocol(protocol, callback) {
};
const query = Protocol.model.find(condition).sort();

query.exec(function(error, protocol) {
query.exec(function (error, protocol) {
if (!error && protocol && protocol.length === 1) {
callback(null, protocol[0]);
} else if (error) {
Expand All @@ -107,7 +107,7 @@ function listProtocol(callback) {

const query = Protocol.model.find(condition).sort();

query.exec(function(error, protocols) {
query.exec(function (error, protocols) {
if (error) {
callback(error);
} else {
Expand All @@ -117,7 +117,7 @@ function listProtocol(callback) {
}

function save(newProtocol, callback) {
getProtocol(newProtocol.protocol, function(error, protocol) {
getProtocol(newProtocol.protocol, function (error, protocol) {
if (error && error.name !== 'PROTOCOL_NOT_FOUND') {
callback(error);
} else {
Expand Down Expand Up @@ -162,15 +162,19 @@ function removeProtocol(id, callback) {

logger.debug(context, 'Removing protocol with id [%s]', id);
/* eslint-disable-next-line no-unused-vars */
Protocol.model.deleteOne(condition, function(error, results) {
getProtocol(condition.protocol, function (error, protocol) {
if (error) {
logger.debug(context, 'Internal MongoDB Error getting device: %s', error);

callback(new errors.InternalDbError(error));
callback(error);
} else {
logger.debug(context, 'Protocol [%s] successfully removed.', id);

callback(null);
Protocol.model.deleteOne(condition, function (error, results) {
if (error) {
logger.debug(context, 'Internal MongoDB Error getting device: %s', error);
callback(new errors.InternalDbError(error));
} else {
logger.debug(context, 'Protocol [%s] successfully removed with results [%j]', id, results);
callback(null);
}
});
}
});
}
Expand Down

0 comments on commit 0d655fe

Please sign in to comment.