2019-07-19 13:51:57 -07:00
|
|
|
var express = require('express')
|
|
|
|
var router = express.Router()
|
|
|
|
|
2019-07-30 12:21:12 -07:00
|
|
|
let Notes = require('@models/Note');
|
2019-07-19 13:51:57 -07:00
|
|
|
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()
|
|
|
|
})
|
|
|
|
|
|
|
|
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-12-19 21:50:50 -08:00
|
|
|
Notes.update(userId, req.body.noteId, req.body.text, req.body.color, req.body.pinned, req.body.archived)
|
2019-07-19 13:51:57 -07:00
|
|
|
.then( id => res.send({id}) )
|
|
|
|
})
|
|
|
|
|
|
|
|
router.post('/search', function (req, res) {
|
2019-09-10 11:10:11 -07:00
|
|
|
Notes.search(userId, req.body.searchQuery, req.body.searchTags, req.body.fastFilters)
|
2019-07-19 13:51:57 -07:00
|
|
|
.then( notesAndTags => res.send(notesAndTags))
|
|
|
|
})
|
|
|
|
|
2020-01-02 17:26:55 -08:00
|
|
|
router.post('/difftext', function (req, res) {
|
|
|
|
|
|
|
|
Notes.getDiffText(userId, req.body.noteId, req.body.text, req.body.updated)
|
|
|
|
.then( fullDiffText => {
|
|
|
|
//Response should be full diff text
|
|
|
|
res.send(fullDiffText)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-12-19 21:50:50 -08:00
|
|
|
//Reindex all notes. Not a very good function, not public
|
|
|
|
router.get('/reindex5yu43prchuj903mrc', function (req, res) {
|
|
|
|
|
|
|
|
// Notes.stressTest().then( i => {
|
|
|
|
// // Notes.reindexAll().then( result => res.send('Welcome to reindex...oh god'))
|
|
|
|
// })
|
|
|
|
})
|
2019-07-19 13:51:57 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = router
|