Skip to content

Commit

Permalink
finish user and locker db clear
Browse files Browse the repository at this point in the history
  • Loading branch information
birdpump committed May 23, 2024
1 parent 445fc23 commit 4c8629c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
24 changes: 18 additions & 6 deletions controllers/admin/adminData.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,22 @@ export async function manualCreateUser(data) {
//todo user should also be added to userData
}

export async function clearUserDB() {
await User.destroy({
truncate: true,
cascade: true,
restartIdentity: true
});
export async function clearLockerDB(data) {
if(data.areYouSure){
await Locker.destroy({
truncate: true,
cascade: true,
restartIdentity: true
});
}
}

export async function clearUserDB(data) {
if(data.areYouSure){
await User.destroy({
truncate: true,
cascade: true,
restartIdentity: true
});
}
}
15 changes: 13 additions & 2 deletions routes/admin/adminData.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
deleteUser,
removeLockerFromUser,
manualCreateUser,
clearUserDB
clearUserDB, clearLockerDB
} from "../../controllers/admin/adminData.js";

import {ensureAuthenticated} from "./adminAuth.js";
Expand Down Expand Up @@ -182,9 +182,20 @@ adminRouter.post('/manual/create-user', async (req, res, next) => {
});


adminRouter.post('/db-action/clear-lockers', async (req, res, next) => {
const dataBody = req.body;
try {
await clearLockerDB(dataBody);
res.sendStatus(200);
} catch (error) {
next(error);
}
});

adminRouter.post('/db-action/clear-users', async (req, res, next) => {
const dataBody = req.body;
try {
await clearUserDB();
await clearUserDB(dataBody);
res.sendStatus(200);
} catch (error) {
next(error);
Expand Down

0 comments on commit 4c8629c

Please sign in to comment.