2019-07-19 13:51:57 -07:00
|
|
|
var express = require('express')
|
|
|
|
var router = express.Router()
|
|
|
|
|
|
|
|
let Notes = require('@models/Notes');
|
|
|
|
let userId = null
|
|
|
|
|
|
|
|
// middleware that is specific to this router
|
|
|
|
router.use(function setUserId (req, res, next) {
|
|
|
|
if(userId = req.headers.userId){
|
|
|
|
userId = req.headers.userId
|
|
|
|
}
|
|
|
|
|
|
|
|
next()
|
|
|
|
})
|
|
|
|
|
|
|
|
//Get the latest notes the user has created
|
|
|
|
router.post('/latest', function (req, res) {
|
|
|
|
Notes.getLatest(userId)
|
|
|
|
.then( data => res.send(data) )
|
|
|
|
})
|
|
|
|
|
|
|
|
router.post('/get', function (req, res) {
|
|
|
|
Notes.get(userId, req.body.noteId)
|
|
|
|
.then( data => res.send(data) )
|
|
|
|
})
|
|
|
|
|
2019-07-29 00:22:47 -07:00
|
|
|
router.post('/delete', function (req, res) {
|
|
|
|
Notes.delete(userId, req.body.noteId)
|
|
|
|
.then( data => res.send(data) )
|
|
|
|
})
|
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
router.post('/create', function (req, res) {
|
|
|
|
Notes.create(userId, req.body.title)
|
|
|
|
.then( id => res.send({id}) )
|
|
|
|
})
|
|
|
|
|
|
|
|
router.post('/update', function (req, res) {
|
2019-07-21 09:28:07 -07:00
|
|
|
Notes.update(userId, req.body.noteId, req.body.text, req.body.fancyInput, req.body.color)
|
2019-07-19 13:51:57 -07:00
|
|
|
.then( id => res.send({id}) )
|
|
|
|
})
|
|
|
|
|
|
|
|
router.post('/search', function (req, res) {
|
|
|
|
Notes.search(userId, req.body.searchQuery, req.body.searchTags)
|
|
|
|
.then( notesAndTags => res.send(notesAndTags))
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = router
|