Compare commits
No commits in common. "a88d3657bfbe13e7d46f4381326618d2bd0dc56e" and "eee00f0797690ec43d24c19c184a433ade12bfd8" have entirely different histories.
a88d3657bf
...
eee00f0797
@ -91,7 +91,14 @@ router.get('/:id', (req, res) => {
|
|||||||
return res.status(404).send('Unit not found');
|
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});
|
res.send({...unit, author: user});
|
||||||
});
|
});
|
||||||
|
@ -14,9 +14,16 @@ router.post('/', (req, res) => {
|
|||||||
const updatedData = [...data, newUser];
|
const updatedData = [...data, newUser];
|
||||||
|
|
||||||
console.log(updatedData);
|
console.log(updatedData);
|
||||||
fs.writeFileSync(path.join(__dirname, 'users.json'), JSON.stringify(updatedData));
|
|
||||||
|
fs.writeFile(path.join(__dirname, 'users.json'), JSON.stringify(updatedData), (err) => {
|
||||||
res.send(updatedData);
|
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) => {
|
router.post('/login', (req, res) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user