Compare commits

..

No commits in common. "a88d3657bfbe13e7d46f4381326618d2bd0dc56e" and "eee00f0797690ec43d24c19c184a433ade12bfd8" have entirely different histories.

2 changed files with 18 additions and 4 deletions

View File

@ -91,7 +91,14 @@ router.get('/:id', (req, res) => {
return res.status(404).send('Unit not found');
}
const user = users.find((user) => user.public_id == unit.author);
const user = users.find((user) => {
if (user.public_id == unit.author) {
return user;
}
});
if (!user) {
return res.status(404).send('User not found');
}
res.send({...unit, author: user});
});

View File

@ -14,9 +14,16 @@ router.post('/', (req, res) => {
const updatedData = [...data, newUser];
console.log(updatedData);
fs.writeFileSync(path.join(__dirname, 'users.json'), JSON.stringify(updatedData));
res.send(updatedData);
fs.writeFile(path.join(__dirname, 'users.json'), JSON.stringify(updatedData), (err) => {
if (err) {
console.error('Ошибка при записи данных в файл users.json', err);
res.status(500).send('Ошибка при записи данных в файл users.json');
} else {
console.log('Данные успешно записаны в файл users.json');
res.status(200).send('Данные успешно записаны в файл users.json');
}
});
});
router.post('/login', (req, res) => {