Add functions to remove account
parent
23e85b7af3
commit
08545bfb5c
|
@ -85,6 +85,14 @@ async function edit(id, email, password, isAdmin) {
|
||||||
return new User(id, email, isAdmin);
|
return new User(id, email, isAdmin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function remove(id) {
|
||||||
|
const query = `DELETE FROM accounts.users
|
||||||
|
WHERE user_id = $1
|
||||||
|
RETURNING email, admin;`;
|
||||||
|
const row = (await database.executeQuery(query, [id]))[0];
|
||||||
|
return new User(id, row[0], row[1]);
|
||||||
|
}
|
||||||
|
|
||||||
async function retrieveAll() {
|
async function retrieveAll() {
|
||||||
const query = `SELECT user_id, email, admin
|
const query = `SELECT user_id, email, admin
|
||||||
FROM accounts.users
|
FROM accounts.users
|
||||||
|
@ -109,6 +117,7 @@ async function getFromID(id) {
|
||||||
|
|
||||||
exports.create = create;
|
exports.create = create;
|
||||||
exports.edit = edit;
|
exports.edit = edit;
|
||||||
|
exports.remove = remove;
|
||||||
exports.retrieveAll = retrieveAll;
|
exports.retrieveAll = retrieveAll;
|
||||||
exports.getFromID = getFromID;
|
exports.getFromID = getFromID;
|
||||||
exports.passport = passport;
|
exports.passport = passport;
|
|
@ -45,3 +45,4 @@ async function checkDataValidity() {
|
||||||
else submitButton.disabled = true;
|
else submitButton.disabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Form.addRemoveFunction(deleteButton, submissionForm, "account");
|
|
@ -150,7 +150,9 @@ router.post('/account', adminLoggedIn, (req, res, next) => {
|
||||||
const isAdmin = !!req.body.admin;
|
const isAdmin = !!req.body.admin;
|
||||||
|
|
||||||
const accountID = req.body.account;
|
const accountID = req.body.account;
|
||||||
|
const remove = req.body.remove;
|
||||||
|
|
||||||
|
if(remove) accounts.remove(accountID).then(res.redirect('/manage'));
|
||||||
if(accountID) accounts.edit(accountID, email, password, isAdmin).then(res.redirect('/manage'));
|
if(accountID) accounts.edit(accountID, email, password, isAdmin).then(res.redirect('/manage'));
|
||||||
else accounts.create(req.body.email, req.body.password, !!req.body.admin).then(res.redirect('/manage'));
|
else accounts.create(req.body.email, req.body.password, !!req.body.admin).then(res.redirect('/manage'));
|
||||||
});
|
});
|
||||||
|
|
Reference in New Issue