diff --git a/database/accounts/accounts.js b/database/accounts/accounts.js index 147cadd..ef0d040 100644 --- a/database/accounts/accounts.js +++ b/database/accounts/accounts.js @@ -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; \ No newline at end of file diff --git a/public/scripts/data.js b/public/scripts/data.js index 2360aed..ae8dc7f 100644 --- a/public/scripts/data.js +++ b/public/scripts/data.js @@ -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; } \ No newline at end of file diff --git a/routes/data.js b/routes/data.js index fcb4920..d010bd1 100644 --- a/routes/data.js +++ b/routes/data.js @@ -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; \ No newline at end of file