small fixes in kfu-m-24-1/eng-it-lean #88

Merged
nekitboy1998 merged 3 commits from kfu-m-24-1/eng-it-lean into master 2025-02-07 12:26:57 +03:00
Showing only changes of commit ea80304c21 - Show all commits

View File

@ -3,7 +3,7 @@ const fs = require('fs');
module.exports = router;
const data = require('./users.json');
let data = require('./users.json');
const path = require('path');
router.get('/', (req, res) => {
res.send(data);
@ -11,20 +11,15 @@ router.get('/', (req, res) => {
router.post('/', (req, res) => {
const newUser = req.body;
const updatedData = [...data, newUser];
console.log(updatedData);
fs.writeFileSync(path.join(__dirname, 'users.json'), JSON.stringify(updatedData));
res.send(updatedData);
data.push(newUser);
fs.writeFileSync(path.join(__dirname, 'users.json'), JSON.stringify(data));
res.send(data);
});
router.post('/login', (req, res) => {
const { email, password } = req.body;
console.log(email);
console.log(req.body);
const user = data.find((user) => user.email === email && user.password === password);
console.log(user);
if (!user) {
res.status(404).send('Пользователь не найден');
@ -34,13 +29,11 @@ router.post('/login', (req, res) => {
router.get('/account', (req, res) => {
const { public_id } = req.query;
console.log(public_id);
const user = data.find((user) => user.public_id == public_id);
if (!user) {
res.status(404).send('Пользователь не найден');
}
console.log(user);
res.send({ ...user, id: -1 });
});
@ -54,7 +47,6 @@ router.post('/account/save', (req, res) => {
}
data[index] = { ...data[index], ...updatedUser, id: data[index].id, password: data[index].password };
fs.writeFileSync(path.join(__dirname, 'users.json'), JSON.stringify(data));
res.status(200);