small fixes in kfu-m-24-1/eng-it-lean #88
@ -1,25 +1,24 @@
|
||||
[
|
||||
{ "id": 1, "description": "1000 часто используемых", "imageFilename": "kart1.jpg", "words": [0, 1] },
|
||||
{
|
||||
"id": 2,
|
||||
"id": 1,
|
||||
"description": "10 слов в Data Science",
|
||||
"imageFilename": "kart1.jpg",
|
||||
"words": [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"id": 2,
|
||||
"description": "Job Interview",
|
||||
"imageFilename": "kart1.jpg",
|
||||
"words": [13, 14, 15, 16, 17, 18, 19, 20, 21, 22]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"id": 3,
|
||||
"description": "ReactJS",
|
||||
"imageFilename": "kart1.jpg",
|
||||
"words": [23, 24, 25, 26, 27, 28, 29, 30, 31, 32]
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"id": 4,
|
||||
"description": "NodeJS",
|
||||
"imageFilename": "kart1.jpg",
|
||||
"words": [33, 34, 35, 36, 37, 38, 39, 40, 41, 42]
|
||||
|
@ -5,15 +5,16 @@ const router = require('express').Router();
|
||||
module.exports = router;
|
||||
|
||||
const data = require('./units.json');
|
||||
const users = require('../users/users.json');
|
||||
router.get('/', (req, res) => {
|
||||
// for every data set author from users and save it to authoredData variable
|
||||
const users = require('../users/users.json');
|
||||
const authoredData = data.map((unit) => {
|
||||
const user = users.find((user) => user.public_id == unit.author);
|
||||
let authoredUnit = undefined;
|
||||
if (user) {
|
||||
unit.author = user;
|
||||
authoredUnit = { ...unit, author: user };
|
||||
}
|
||||
return unit;
|
||||
return authoredUnit;
|
||||
});
|
||||
|
||||
res.send(authoredData);
|
||||
@ -39,9 +40,8 @@ router.post('/:id', (req, res) => {
|
||||
|
||||
data.splice(index, 1);
|
||||
|
||||
data.push(updatedUnit);
|
||||
data.push({...updatedUnit, author: updatedUnit.author.public_id});
|
||||
|
||||
fs.writeFileSync(path.join(__dirname, 'units.json'), JSON.stringify(data));
|
||||
res.status(200).send(data);
|
||||
});
|
||||
|
||||
@ -61,12 +61,8 @@ router.put('/', (req, res) => {
|
||||
}
|
||||
|
||||
const newId = data.length + 1;
|
||||
// const filename = newUnit.name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
||||
// fs.writeFileSync(path.join(__dirname, 'data', `${filename}.md`), newUnit.content);
|
||||
data.push({ ...newUnit, id: newId });
|
||||
|
||||
data.push({ ...unit, id: newId });
|
||||
|
||||
fs.writeFileSync(path.join(__dirname, 'units.json'), JSON.stringify(data));
|
||||
res.status(200).send(data);
|
||||
});
|
||||
|
||||
@ -79,11 +75,11 @@ router.delete('/:id', (req, res) => {
|
||||
}
|
||||
|
||||
data.splice(index, 1);
|
||||
fs.writeFileSync(path.join(__dirname, 'units.json'), JSON.stringify(data));
|
||||
res.send({ message: `Unit with ID ${id} deleted` });
|
||||
});
|
||||
|
||||
router.get('/:id', (req, res) => {
|
||||
const users = require('../users/users.json');
|
||||
const id = parseInt(req.params.id);
|
||||
const unit = data.find((unit) => unit.id === id);
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user