users: asyncify and merge userdb.del

This commit is contained in:
Girish Ramakrishnan
2021-06-26 09:57:07 -07:00
parent 147c8df6e3
commit e7d9af5aed
6 changed files with 80 additions and 139 deletions

View File

@@ -10,7 +10,6 @@ exports = module.exports = {
getAllWithGroupIdsPaged,
getByRole,
add,
del,
update,
count,
@@ -182,26 +181,6 @@ function add(userId, user, callback) {
});
}
function del(userId, callback) {
assert.strictEqual(typeof userId, 'string');
assert.strictEqual(typeof callback, 'function');
// also cleanup the groupMembers table
var queries = [];
queries.push({ query: 'DELETE FROM groupMembers WHERE userId = ?', args: [ userId ] });
queries.push({ query: 'DELETE FROM tokens WHERE identifier = ?', args: [ userId ] });
queries.push({ query: 'DELETE FROM appPasswords WHERE userId = ?', args: [ userId ] });
queries.push({ query: 'DELETE FROM users WHERE id = ?', args: [ userId ] });
database.transaction(queries, function (error, result) {
if (error && error.code === 'ER_NO_REFERENCED_ROW_2') return callback(new BoxError(BoxError.NOT_FOUND, error));
if (error) return callback(new BoxError(BoxError.DATABASE_ERROR, error));
if (result[3].affectedRows !== 1) return callback(new BoxError(BoxError.NOT_FOUND, 'User not found'));
callback(error);
});
}
function getByAccessToken(accessToken, callback) {
assert.strictEqual(typeof accessToken, 'string');
assert.strictEqual(typeof callback, 'function');