* Add some user lookup functionality

* Fix INTL to/from order
* Remove VIA kludge when initially creating a NetMail message
This commit is contained in:
Bryan Ashby 2018-01-01 18:10:38 -07:00
parent e7109b0f0c
commit 84a1f70fc2
2 changed files with 42 additions and 4 deletions

View file

@ -414,12 +414,48 @@ module.exports = class User {
if(row) {
return cb(null, row.id, row.user_name);
}
return cb(Errors.DoesNotExist('No matching username'));
}
);
}
static getUserIdAndNameByRealName(realName, cb) {
userDb.get(
`SELECT id, user_name
FROM user
WHERE id = (
SELECT user_id
FROM user_property
WHERE prop_name='real_name' AND prop_value=?
);`,
[ realName ],
(err, row) => {
if(err) {
return cb(err);
}
if(row) {
return cb(null, row.id, row.user_name);
}
return cb(Errors.DoesNotExist('No matching real name'));
}
);
}
static getUserIdAndNameByLookup(lookup, cb) {
User.getUserIdAndName(lookup, (err, userId, userName) => {
if(err) {
User.getUserIdAndNameByRealName(lookup, (err, userId, userName) => {
return cb(err, userId, userName);
});
} else {
return cb(null, userId, userName);
}
});
}
static getUserName(userId, cb) {
userDb.get(
`SELECT user_name