34 lines
782 B
JavaScript
34 lines
782 B
JavaScript
const DBUtils = require('./DBUtil');
|
|
|
|
module.exports = {
|
|
getAccountByToken: (token) => {
|
|
return new Promise((resolve, reject) => {
|
|
if(!token){
|
|
reject('Must provide token');
|
|
return;
|
|
}
|
|
DBUtils.Models.Account.findOne({auth_token:token}, (err, account)=>{
|
|
if(err) {
|
|
reject('Invalid token');
|
|
return;
|
|
}
|
|
resolve(account);
|
|
});
|
|
})
|
|
},
|
|
getUserByAccountId: (id) => {
|
|
return new Promise((resolve, reject) => {
|
|
if(!id) {
|
|
reject('No account id provided');
|
|
return;
|
|
}
|
|
DBUtils.Models.User.findOne({account_id: id}, (err, doc) => {
|
|
if(err) {
|
|
reject('Unable to find user');
|
|
return;
|
|
}
|
|
resolve(doc);
|
|
});
|
|
});
|
|
}
|
|
}
|