Skip to content

Commit

Permalink
remove duplicate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Feb 13, 2024
1 parent 1280753 commit b6b5dd8
Showing 1 changed file with 25 additions and 48 deletions.
73 changes: 25 additions & 48 deletions lib/services/northBound/deviceProvisioningServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,34 +269,34 @@ function handleGetDevice(req, res, next) {
);
}

/**
* This middleware handles the removal of a particular device specified with the deviceId.
*/
function handleRemoveDevice(req, res, next) {
function getDevice(deviceId, apikey, service, subservice, callback) {
deviceService.getDevice(deviceId, apikey, service, subservice, function (error, device) {
if (error) {
callback(error);
} else if (device) {
callback(null, device);
} else {
callback(new errors.DeviceNotFound(deviceId));
}
});
}

function applyRemoveDeviceHandler(device, callback) {
if (removeDeviceHandler) {
removeDeviceHandler(device, callback);
} else {
function getDevice(deviceId, apikey, service, subservice, callback) {
deviceService.getDevice(deviceId, apikey, service, subservice, function (error, device) {
if (error) {
callback(error);
} else if (device) {
callback(null, device);
} else {
callback(new errors.DeviceNotFound(deviceId));
}
}
});
}

function unregisterDevice(deviceId, apikey, service, subservice, device, callback) {
return deviceService.unregister(deviceId, apikey, service, subservice, callback);
function applyRemoveDeviceHandler(device, callback) {
if (removeDeviceHandler) {
removeDeviceHandler(device, callback);
} else {
callback(null, device);
}
}

function unregisterDevice(deviceId, apikey, service, subservice, device, callback) {
return deviceService.unregister(deviceId, apikey, service, subservice, callback);
}

/**
* This middleware handles the removal of a particular device specified with the deviceId.
*/
function handleRemoveDevice(req, res, next) {
async.waterfall(
[
apply(statsRegistry.add, 'deviceRemovalRequests', 1),
Expand Down Expand Up @@ -332,29 +332,6 @@ function handleRemoveDevice(req, res, next) {
* This middleware handles the removal of several devices specified in a array into a body
*/
function handleRemoveDevices(req, res, next) {
function getDevice(deviceId, apikey, service, subservice, callback) {
deviceService.getDevice(deviceId, apikey, service, subservice, function (error, device) {
if (error) {
callback(error);
} else if (device) {
callback(null, device);
} else {
callback(new errors.DeviceNotFound(deviceId));
}
});
}

function applyRemoveDeviceHandler(device, callback) {
if (removeDeviceHandler) {
removeDeviceHandler(device, callback);
} else {
callback(null, device);
}
}

function unregisterDevice(deviceId, apikey, service, subservice, device, callback) {
return deviceService.unregister(deviceId, apikey, service, subservice, callback);
}
logger.debug(context, 'Handling delete of devices: %j', req.body);
let theErrorOut = false;
for (let devicetoRemove of req.body) {
Expand Down Expand Up @@ -481,13 +458,13 @@ function loadContextRoutes(router) {
handleUpdateDevice
);

router.delete('/iot/devices', restUtils.checkRequestAttributes('headers', mandatoryHeaders), handleRemoveDevices);

router.delete(
'/iot/devices/:deviceId',
restUtils.checkRequestAttributes('headers', mandatoryHeaders),
handleRemoveDevice
);

router.delete('/iot/devices', restUtils.checkRequestAttributes('headers', mandatoryHeaders), handleRemoveDevices);
}

function setProvisioningHandler(newHandler) {
Expand Down

0 comments on commit b6b5dd8

Please sign in to comment.