small fixes in kfu-m-24-1/eng-it-lean #88
@ -3,7 +3,7 @@ const fs = require('fs');
|
|||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
||||||
const data = require('./users.json');
|
let data = require('./users.json');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
router.get('/', (req, res) => {
|
router.get('/', (req, res) => {
|
||||||
res.send(data);
|
res.send(data);
|
||||||
@ -11,20 +11,15 @@ router.get('/', (req, res) => {
|
|||||||
|
|
||||||
router.post('/', (req, res) => {
|
router.post('/', (req, res) => {
|
||||||
const newUser = req.body;
|
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) => {
|
router.post('/login', (req, res) => {
|
||||||
const { email, password } = req.body;
|
const { email, password } = req.body;
|
||||||
console.log(email);
|
|
||||||
console.log(req.body);
|
|
||||||
const user = data.find((user) => user.email === email && user.password === password);
|
const user = data.find((user) => user.email === email && user.password === password);
|
||||||
console.log(user);
|
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
res.status(404).send('Пользователь не найден');
|
res.status(404).send('Пользователь не найден');
|
||||||
@ -34,13 +29,11 @@ router.post('/login', (req, res) => {
|
|||||||
|
|
||||||
router.get('/account', (req, res) => {
|
router.get('/account', (req, res) => {
|
||||||
const { public_id } = req.query;
|
const { public_id } = req.query;
|
||||||
console.log(public_id);
|
|
||||||
const user = data.find((user) => user.public_id == public_id);
|
const user = data.find((user) => user.public_id == public_id);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
res.status(404).send('Пользователь не найден');
|
res.status(404).send('Пользователь не найден');
|
||||||
}
|
}
|
||||||
console.log(user);
|
|
||||||
res.send({ ...user, id: -1 });
|
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 };
|
data[index] = { ...data[index], ...updatedUser, id: data[index].id, password: data[index].password };
|
||||||
|
|
||||||
fs.writeFileSync(path.join(__dirname, 'users.json'), JSON.stringify(data));
|
fs.writeFileSync(path.join(__dirname, 'users.json'), JSON.stringify(data));
|
||||||
|
|
||||||
res.status(200);
|
res.status(200);
|
||||||
|
Loading…
Reference in New Issue
Block a user