CEO updated

This commit is contained in:
andrei-mihnea-cerbu
2024-04-20 03:18:44 +03:00
parent 869305a491
commit 57c2c7ec55
81 changed files with 3517 additions and 1035 deletions
+12 -7
View File
@@ -59,7 +59,7 @@ router.post('/login', validateBody, (req, res) => {
return res.status(httpStatus.UNAUTHORIZED).json({message: 'Invalid credentials.'});
}
return res.status(httpStatus.Ok).json({message: 'Logged in.'});
return res.status(httpStatus.OK).json({message: 'Logged in.', data: ceoDB.readFile()});
});
router.post('/set_security_levels', validateBody, (req, res) => {
@@ -99,13 +99,16 @@ router.delete('/users/:id', validateBody, (req, res) => {
const usersDB = req.app.get('usersDB');
const { id } = req.params;
const userIndex = usersDB.findIndexByKeyValueInArray('id', id);
if(userIndex === -1){
let usersJson = usersDB.readFile();
const userIndex = usersJson.findIndex(user => user.id === id);
if (userIndex === -1) {
return res.status(httpStatus.NOT_FOUND).json({message: 'User not found in system.'});
}
let usersJson = usersDB.readFile;
usersJson.splice(userIndex, 1);
usersDB.writeFile(usersJson);
return res.status(httpStatus.OK).json({ message: 'User deleted successfully.' });
@@ -114,6 +117,7 @@ router.delete('/users/:id', validateBody, (req, res) => {
router.post('/departments', validateBody, (req, res) => {
const departmentsDB = req.app.get('departmentsDB');
const { name } = req.body;
console.log(name);
let jsonDepartments = departmentsDB.readFile();
const nameExists = Object.values(jsonDepartments).some(department => department.name === name);
@@ -164,17 +168,18 @@ router.delete('/departments/:name', validateBody, (req, res) => {
router.put('/', validateBody, (req, res) => {
const ceoDB = req.app.get('ceoDB');
const { name, email } = req.body;
const {id} = ceoDB.readFile()
const {id, department} = ceoDB.readFile()
const newCeo = {
id: id,
name: name,
email: email,
password: crypto.randomBytes(16).toString('hex')
password: crypto.randomBytes(16).toString('hex'),
department: department
}
ceoDB.writeFile(newCeo);
return res.status(httpStatus.OK).json({message: 'Information modified.'});
return res.status(httpStatus.OK).json({message: 'Information modified.', data: newCeo});
});
router.get('/get_decrypt_keys', (req, res) => {