Add function to get user information

main
sudoer777 2021-11-25 12:04:18 -07:00
parent 173c075aa3
commit 4d3b6989e4
3 changed files with 21 additions and 0 deletions

View File

@ -75,6 +75,16 @@ async function retrieveAll() {
return accountsList;
}
async function getFromID(id) {
const query = `SELECT user_id, email, admin
FROM accounts.users
WHERE user_id = $1;`;
const row = (await database.executeQuery(query, [id]))[0];
return new User(id, row[1], row[2]);
}
exports.createUser = createUser;
exports.retrieveAll = retrieveAll;
exports.getFromID = getFromID;
exports.passport = passport;

View File

@ -75,4 +75,10 @@ export async function getAccounts() {
const response = await fetch(`/data/accounts`);
const accounts = await response.json();
return accounts;
}
export async function getAccount(accountID) {
const response = await fetch(`/data/account?account=${accountID}`);
const account = await response.json();
return account;
}

View File

@ -76,4 +76,9 @@ router.get('/accounts', adminLoggedIn, function(req, res, next) {
.then(data => res.json(data));
})
router.get('/account', adminLoggedIn, function(req, res, next) {
accounts.getFromID(req.query.account)
.then(data => res.json(data));
})
module.exports = router;