implement deletion of admin user, frontend and backend

This commit is contained in:
2025-08-06 11:52:39 +02:00
parent 7e87a01c59
commit cbea96f892
3 changed files with 46 additions and 2 deletions

View File

@@ -32,5 +32,23 @@ export const addUser = (userName: string, userPassword: string): number => {
return rowCount;
};
export const deleteUser = () => {
export const deleteUser = (userId: string) => {
// make sure to not delete the last entry
const deleteUserSQLStmt = `DELETE
FROM users
WHERE id = ?
AND (SELECT COUNT(*) FROM users) > 1;`;
const statement = db.prepare(deleteUserSQLStmt);
let rowCount;
try {
const info = statement.run(userId);
rowCount = info.changes;
} catch (error) {
console.log(error);
rowCount = 0;
}
return rowCount;
};