diff --git a/src/modules/api/api.js b/src/modules/api/api.js index 1390b46..7581bda 100644 --- a/src/modules/api/api.js +++ b/src/modules/api/api.js @@ -216,45 +216,55 @@ function GetApp() { // ------------------------------------------------------------- - app.get('/todos', (req, res) => { - logger.LogReq(req) + app.get('/updateTodo', (req, res) => { const userId = req.session.user.id const id = req.query.id const todos = utils.ReadJSON(todosFile) - if (id) { - const cardIndex = todos.cards.findIndex((currcard) => { - return currcard.id === parseInt(id) - }) - if (cardIndex === -1) { - res.json({ - msg: 'card not found', - result: 'not ok', - }) - return - } - - const ind = todos.cards[cardIndex].votes.indexOf(userId) - if (ind === -1) { - todos.cards[cardIndex].votes.push(userId) - } else { - todos.cards[cardIndex].votes.splice(ind, 1) - } - - utils.WriteFile(JSON.stringify(todos, null, 2), todosFile) + if (!id) { res.json({ - todos: todos, - userId: userId, - msg: 'updated', - result: 'ok', - }) - } else { - res.json({ - todos: todos, - userId: userId, - result: 'ok', + msg: 'id query undefined', + result: 'not ok', }) } + + const cardIndex = todos.cards.findIndex((currcard) => { + return currcard.id === parseInt(id) + }) + if (cardIndex === -1) { + res.json({ + msg: 'card not found', + result: 'not ok', + }) + return + } + + const ind = todos.cards[cardIndex].votes.indexOf(userId) + if (ind === -1) { + todos.cards[cardIndex].votes.push(userId) + } else { + todos.cards[cardIndex].votes.splice(ind, 1) + } + + utils.WriteFile(JSON.stringify(todos, null, 2), todosFile) + res.json({ + todos: todos, + userId: userId, + msg: 'updated', + result: 'ok', + }) + }) + + app.get('/todos', (req, res) => { + logger.LogReq(req) + const userId = req.session.user.id + const todos = utils.ReadJSON(todosFile) + + res.json({ + todos: todos, + userId: userId, + result: 'ok', + }) }) app.get('/ranklist', (req, res) => {