Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Update sequelize to 6.29.2
Browse files Browse the repository at this point in the history
closes #281

Signed-off-by: Oguzcan Kirmemis <[email protected]>
  • Loading branch information
oguzcankirmemis authored and wagmarcel committed Mar 22, 2023
1 parent 128540a commit 2aaa11a
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 59 deletions.
30 changes: 12 additions & 18 deletions public-interface/engine/api/v1/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,27 +191,24 @@ var command = function (accountId, commands, complexCommands, resultCallback) {
);
};

var getComplexCommands = function (accountId, cb) {
return complexCommand.findAllByAccount(accountId)
.nodeify(cb);
var getComplexCommands = function (accountId, resultCallback) {
return complexCommand.findAllByAccount(accountId, resultCallback);
};

var deleteComplexCommand = function (accountId, name, resultCallback) {
return complexCommand.delete(accountId, name)
.nodeify(resultCallback);
return complexCommand.delete(accountId, name, resultCallback);
};

var addComplexCommand = function (accountId, name, commands, resultCallback) {
return complexCommand.insert({ accountId: accountId, id: name, commands: commands})
return complexCommand.insert({ accountId: accountId, id: name, commands: commands}, resultCallback)
.catch(function (err) {
if (err && err.code) {
throw err;
}
else {
throw errBuilder.build(errBuilder.Errors.Generic.InternalServerError);
}
})
.nodeify(resultCallback);
});
};

var updateComplexCommand = function (accountId, name, commands, resultCallback) {
Expand All @@ -221,16 +218,13 @@ var updateComplexCommand = function (accountId, name, commands, resultCallback)
accountId: accountId,
id: name,
commands: commands
})
.catch(function (err) {
if (err && err.code) {
throw err;
}
else {
throw errBuilder.build(errBuilder.Errors.Generic.InternalServerError);
}
})
.nodeify(resultCallback);
}, resultCallback).catch(function (err) {
if (err && err.code) {
throw err;
} else {
throw errBuilder.build(errBuilder.Errors.Generic.InternalServerError);
}
});
};

var parseDatesFromRequest = function (dateFilterParams) {
Expand Down
4 changes: 2 additions & 2 deletions public-interface/engine/api/v1/invites.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports.getUserInvites = function (email, resultCallback) {

exports.getInvite = function (inviteId, resultCallback) {
return invites.findById(inviteId, null)
.nodeify(resultCallback);
.then(result => resultCallback(null, result));
};

exports.addInvite = function (accountId, host, email, resultCallback) {
Expand Down Expand Up @@ -155,7 +155,7 @@ exports.updateInviteStatus = function (inviteId, accept, userId, resultCallback)
.catch(function (err) {
logger.error('invites.updateInviteStatus error: ' + JSON.stringify(err));
return postgresProvider.rollback(transaction)
.done(function() {
.finally(function() {
var errMsg = errBuilder.build(errBuilder.Errors.Generic.InternalServerError);
if (err && err.code) {
errMsg = errBuilder.build(err);
Expand Down
6 changes: 3 additions & 3 deletions public-interface/engine/api/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ exports.updateUser = function (data, accountId) {
.catch (function(err) {
logger.warn("users.update - unable to update user, error: " + JSON.stringify(err));
return postgresProvider.rollback(transaction)
.done(function() {
.finally(function() {
if (err && err.code) {
throw errBuilder.build(err);
} else {
Expand Down Expand Up @@ -255,7 +255,7 @@ exports.deleteUser = function (userId) {
}).then(() => {
return keycloak.serviceAccount.deleteUser(userId);
}).catch (function (err) {
return postgresProvider.rollback(transaction).done(function() {
return postgresProvider.rollback(transaction).finally(function() {
if (err && err.code) {
logger.error("Could not delete user: " + userId);
throw err;
Expand Down Expand Up @@ -291,7 +291,7 @@ exports.deleteUserFromAccount = function (email, accountId, isSelf) {
})
.catch(function () {
return postgresProvider.rollback(transaction)
.done(function(err) {
.finally(function(err) {
throw err;
});
});
Expand Down
4 changes: 2 additions & 2 deletions public-interface/iot-entities/postgresql/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ exports.update = function (accountData, transaction) {
where: {
id: accountModel.id
},
returning: true,
returning: ["*"],
transaction: transaction
};

Expand Down Expand Up @@ -151,7 +151,7 @@ exports.refreshActivationCode = function (id, resultCallback) {
where: {
id: id
},
returning: true
returning: ["*"]
};

var data = {
Expand Down
31 changes: 13 additions & 18 deletions public-interface/iot-entities/postgresql/complexCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var complexCommands = require('./models').complexCommands,
sequelize = require('./models').sequelize,
interpreterHelper = require('../../lib/interpreter/helper'),
errBuilder = require("../../lib/errorHandler/index").errBuilder,
Q = require('q'),
interpreter = require('../../lib/interpreter/postgresInterpreter').complexCommands();

exports.findByAccountAndId = function (accountId, id, resultCallback) {
Expand All @@ -35,8 +34,8 @@ exports.findByAccountAndId = function (accountId, id, resultCallback) {
[commands, 'created', 'ASC']
]
}).then(function (foundComplexCommand) {
return Q.resolve(interpreterHelper.mapAppResults(foundComplexCommand, interpreter));
}).nodeify(resultCallback);
resultCallback(null, interpreterHelper.mapAppResults(foundComplexCommand, interpreter));
});
};

exports.findAllByAccount = function (accountId, resultCallback) {
Expand All @@ -50,10 +49,10 @@ exports.findAllByAccount = function (accountId, resultCallback) {
[commands, 'created', 'ASC'],
],
}).then(function (foundComplexCommand) {
return Q.resolve(interpreterHelper.mapAppResults(foundComplexCommand, interpreter));
resultCallback(null, interpreterHelper.mapAppResults(foundComplexCommand, interpreter));
}).catch(function (err) {
throw err;
}).nodeify(resultCallback);
});
};

exports.update = function (data, resultCallback) {
Expand All @@ -64,7 +63,7 @@ exports.update = function (data, resultCallback) {
var componentModel = interpreter.toDb(data);
return sequelize.transaction()
.then(function (t) {
return complexCommands.update(componentModel, {where: {accountId: componentModel.accountId, name: componentModel.name }, returning: true }, {transaction: t})
return complexCommands.update(componentModel, {where: {accountId: componentModel.accountId, name: componentModel.name }, returning: ["*"] }, {transaction: t})
.then(function (foundComplexCommand) {
if (foundComplexCommand && foundComplexCommand[1][0]) {
return commands.destroy({where: {complexCommandId: foundComplexCommand[1][0].dataValues.id}}, {transaction: t})
Expand All @@ -75,7 +74,7 @@ exports.update = function (data, resultCallback) {
return commands.bulkCreate(data.commands, {transaction: t})
.then(function () {
t.commit();
});
}).then(() => resultCallback());
});
}
else {
Expand All @@ -86,8 +85,7 @@ exports.update = function (data, resultCallback) {
t.rollback();
throw err;
});
})
.nodeify(resultCallback);
});
};

exports.insert = function (data, resultCallback) {
Expand All @@ -106,7 +104,7 @@ exports.insert = function (data, resultCallback) {
return commands.bulkCreate(data.commands, {transaction: t})
.then(function () {
t.commit();
});
}).then(() => resultCallback());
}).
catch(function (err) {
t.rollback();
Expand All @@ -117,28 +115,25 @@ exports.insert = function (data, resultCallback) {
throw err;
}
});
})
.nodeify(resultCallback);
});
};

exports.delete = function (accountId, id, resultCallback) {
return complexCommands.destroy({where: {accountId: accountId, name: id}})
.then(function (res) {
return res;
resultCallback(null, res);
})
.catch(function (err) {
throw err;
})
.nodeify(resultCallback);
});
};

exports.deleteAllByAccount = function (accountId, resultCallback) {
return complexCommands.destroy({where: {accountId: accountId}})
.then(function (res) {
return res;
resultCallback(null, res);
})
.catch(function (err) {
throw err;
})
.nodeify(resultCallback);
});
};
15 changes: 6 additions & 9 deletions public-interface/iot-entities/postgresql/deviceComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ var errBuilder = require("./../../lib/errorHandler").errBuilder,
devices = require('./models').devices,
interpreterHelper = require('../../lib/interpreter/helper'),
interpreter = require('../../lib/interpreter/postgresInterpreter').deviceComponents(),
Sequelize = require('sequelize'),
Q = require('q');
Sequelize = require('sequelize');

const Op = Sequelize.Op;

Expand Down Expand Up @@ -173,7 +172,7 @@ exports.updateLastObservationTS = function (componentId, date, resultCallback) {
componentId: componentId
}
};
deviceComponents.findOne(filter).then(function (comp) {
return deviceComponents.findOne(filter).then(function (comp) {
filter.where.last_observation_time = {
[Op.lt]: new Date(date)
};
Expand All @@ -182,15 +181,13 @@ exports.updateLastObservationTS = function (componentId, date, resultCallback) {
comp.last_observation_time = date;
deviceComponents.update(comp, filter)
.then(function () {
return Q.resolve();
resultCallback();
})
.catch(function (err) {
throw err;
}).nodeify(resultCallback);
});
} else {
Q.resolve();
resultCallback();
}
}).catch(function (err) {
throw err;
}).nodeify(resultCallback);
});
};
2 changes: 1 addition & 1 deletion public-interface/iot-entities/postgresql/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ exports.confirmActivation = function (deviceId, activationCode) {
}
accountId = account.id;
filter = {
returning: true,
returning: ["*"],
where: {
id: deviceId,
accountId: accountId
Expand Down
4 changes: 2 additions & 2 deletions public-interface/iot-entities/postgresql/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ exports.update = function (settingId, data, resultCallback) {
where: {
id: settingId
},
returning: true
returning: ["*"]
};

var settingModel = interpreter.toDb(data);
Expand Down Expand Up @@ -182,7 +182,7 @@ exports.updateDefault = function (userId, accountId, type, settingId, resultCall
type: type,
default: true
},
returning: true
returning: ["*"]
};

settings.update({default: false}, filter)
Expand Down
2 changes: 1 addition & 1 deletion public-interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"redis": "^3.1.2",
"request": "^2.88.0",
"request-promise": "^4.2.4",
"sequelize": "^5.22.4",
"sequelize": "^6.29.2",
"sequelize-cli": "^5.5.1",
"serve-favicon": "^2.3.0",
"shimmer": "^1.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ describe('invitesApi.updateInviteStatus', function () {
commit: sinon.stub().returns(Q.resolve()),
startTransaction: sinon.stub().returns(Q.resolve()),
rollback: sinon.stub().returns({
done: sinon.stub().returns(Q.resolve())
done: sinon.stub().returns(Q.resolve()),
finally: sinon.stub().returns(Q.resolve())
})
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ describe('usersApi.deleteUser', function () {
postgresProviderMock = {
startTransaction: sinon.stub().returns(Q.resolve()),
rollback: sinon.stub().returns({
done: rollbackDone
done: rollbackDone,
finally: rollbackDone
}),
commit: sinon.stub().returns(Q.resolve()),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ describe('usersApi.updateUser', function () {
postgresProviderMock = {
startTransaction: sinon.stub().returns(Q.resolve()),
rollback: sinon.stub().returns({
done: rollbackDone
done: rollbackDone,
finally: rollbackDone
}),
commit: sinon.stub().returns(Q.resolve())
};
Expand Down

0 comments on commit 2aaa11a

Please sign in to comment.