SolidScribe/server/routes/noteController.js
Max G abb4e20ec3 I swear, I'm going to start doing regular commits
+ Added a ton of shit
+ About to add socket.io oh god.
2020-01-03 01:26:55 +00:00

60 lines
1.5 KiB
JavaScript

var express = require('express')
var router = express.Router()
let Notes = require('@models/Note');
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) )
})
router.post('/delete', function (req, res) {
Notes.delete(userId, req.body.noteId)
.then( data => res.send(data) )
})
router.post('/create', function (req, res) {
Notes.create(userId, req.body.title)
.then( id => res.send({id}) )
})
router.post('/update', function (req, res) {
Notes.update(userId, req.body.noteId, req.body.text, req.body.color, req.body.pinned, req.body.archived)
.then( id => res.send({id}) )
})
router.post('/search', function (req, res) {
Notes.search(userId, req.body.searchQuery, req.body.searchTags, req.body.fastFilters)
.then( notesAndTags => res.send(notesAndTags))
})
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)
})
})
//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'))
// })
})
module.exports = router