Add getOwner

This commit is contained in:
girish@cloudron.io
2016-01-13 12:28:38 -08:00
parent 5eb3c208f1
commit efaacdb534
3 changed files with 47 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ exports = module.exports = {
getByEmail: getByEmail,
getByAccessToken: getByAccessToken,
getByResetToken: getByResetToken,
getOwner: getOwner,
getAll: getAll,
getAllAdmins: getAllAdmins,
add: add,
@@ -56,6 +57,18 @@ function getByEmail(email, callback) {
});
}
function getOwner(callback) {
assert.strictEqual(typeof callback, 'function');
// the first created user it the admin
database.query('SELECT ' + USERS_FIELDS + ' FROM users WHERE admin=1 ORDER BY createdAt LIMIT 1', function (error, result) {
if (error) return callback(new DatabaseError(DatabaseError.INTERNAL_ERROR, error));
if (result.length === 0) return callback(new DatabaseError(DatabaseError.NOT_FOUND));
callback(null, result[0]);
});
}
function getByResetToken(resetToken, callback) {
assert.strictEqual(typeof resetToken, 'string');
assert.strictEqual(typeof callback, 'function');