Skip to content

Commit

Permalink
Fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
mapedraza committed Aug 26, 2024
1 parent c42cebe commit 936d78c
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions lib/services/northBound/deviceGroupAdministrationServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function applyConfigurationMiddlewares(newConfiguration, callback) {
* @param {Function} next Invokes the next middleware in the chain.
*/
function handleCreateDeviceGroup(req, res, next) {
req.body = checkAndModifyGroupRecv(req._parsedUrl.pathname, req.body);
req.body = checkAndModifyGroupRecv(req._parsedUrl.pathname, req.body); // #FIXME1649: This line should be removed when /iot/services support is removed

for (let i = 0; i < req.body.services.length; i++) {
req.body.services[i] = applyMap(apiToInternal, req.body.services[i]);
Expand Down Expand Up @@ -169,7 +169,7 @@ function handleListDeviceGroups(req, res, next) {
} else {
translatedGroup = applyMap(internalToApi, group);
}
res.status(200).send(checkAndModifyGroupResp(req._parsedUrl.pathname, translatedGroup));
res.status(200).send(checkAndModifyGroupResp(req._parsedUrl.pathname, translatedGroup)); // #FIXME1649: Response should not use checkAndModifyGroupResp function when /iot/services support is removed
}
};

Expand Down Expand Up @@ -324,32 +324,21 @@ function clear(callback) {
callback();
}

function renameObjetKeys(keysMap, obj) {
return Object.keys(obj).reduce((acc, key) => {
// Si la clave existe en el mapa, usar la clave renombrada
const renamedKey = keysMap[key] || key;

// Agregar la clave renombrada al acumulador
acc[renamedKey] = obj[key];

return acc;
}, {});
}

// #FIXME1649: This function should be removed when /iot/services support is removed
function checkAndModifyGroupResp(route, payload) {
if (route === '/iot/services') {
return payload;
} else {
return renameObjetKeys({ services: 'groups' }, payload);
if (route === '/iot/groups') {
payload['groups'] = payload['services'];
delete payload['services'];
}
return payload;
}

// #FIXME1649: This function should be removed when /iot/services support is removed
function checkAndModifyGroupRecv(route, payload) {
if (route === '/iot/services') {
return payload;
} else {
return renameObjetKeys({ groups: 'services' }, payload);
if (route === '/iot/groups') {
payload['services'] = payload['groups'];
delete payload['groups'];
}
return payload;
}

exports.loadContextRoutes = loadContextRoutes;
Expand Down

0 comments on commit 936d78c

Please sign in to comment.