showing results for - "mongoose put request"
Alisha
18 May 2020
1router.put('/board/:id', (req, res) => {
2  const {id: _id} = req.params // Assigning id to _id which is a es6 feature. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
3  const {position} = req.body
4
5  const newBoard = {
6    _id,
7    position
8  }
9
10  Board.findByIdAndUpdate(
11    _id,
12    newBoard,
13    (err, updatedBoard) => {
14      if (err) {
15        res.json({
16          newBoard,
17          success: false,
18          msg: 'Failed to update board'
19        })
20      } else {
21        res.json({newBoard, success: true, msg: 'Board added'})
22      }
23    }
24  )
25})
26