mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added updateTodo endpoint
This commit is contained in:
parent
86f1fff804
commit
677c320e90
1 changed files with 42 additions and 32 deletions
|
@ -216,45 +216,55 @@ function GetApp() {
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
|
|
||||||
app.get('/todos', (req, res) => {
|
app.get('/updateTodo', (req, res) => {
|
||||||
logger.LogReq(req)
|
|
||||||
const userId = req.session.user.id
|
const userId = req.session.user.id
|
||||||
const id = req.query.id
|
const id = req.query.id
|
||||||
const todos = utils.ReadJSON(todosFile)
|
const todos = utils.ReadJSON(todosFile)
|
||||||
|
|
||||||
if (id) {
|
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)
|
|
||||||
res.json({
|
res.json({
|
||||||
todos: todos,
|
msg: 'id query undefined',
|
||||||
userId: userId,
|
result: 'not ok',
|
||||||
msg: 'updated',
|
|
||||||
result: 'ok',
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
res.json({
|
|
||||||
todos: todos,
|
|
||||||
userId: userId,
|
|
||||||
result: '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) => {
|
app.get('/ranklist', (req, res) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue