Add mailboxdb.updateName()
This commit is contained in:
@@ -18,6 +18,8 @@ exports = module.exports = {
|
||||
getByOwnerId: getByOwnerId,
|
||||
delByOwnerId: delByOwnerId,
|
||||
|
||||
updateName: updateName,
|
||||
|
||||
_clear: clear,
|
||||
|
||||
TYPE_USER: 'user',
|
||||
@@ -80,6 +82,20 @@ function delByOwnerId(id, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function updateName(oldName, newName, callback) {
|
||||
assert.strictEqual(typeof oldName, 'string');
|
||||
assert.strictEqual(typeof newName, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
database.query('UPDATE mailboxes SET name=? WHERE name=?', [ newName, oldName ], function (error, result) {
|
||||
if (error && error.code === 'ER_DUP_ENTRY') return callback(new DatabaseError(DatabaseError.ALREADY_EXISTS, 'mailbox already exists'));
|
||||
if (error) return callback(new DatabaseError(DatabaseError.INTERNAL_ERROR, error));
|
||||
if (result.affectedRows !== 1) return callback(new DatabaseError(DatabaseError.NOT_FOUND));
|
||||
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
|
||||
function getMailbox(name, callback) {
|
||||
assert.strictEqual(typeof name, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
Reference in New Issue
Block a user