2019-07-19 13:51:57 -07:00
|
|
|
var express = require('express')
|
|
|
|
var router = express.Router()
|
|
|
|
|
2020-07-22 22:00:20 -07:00
|
|
|
let Tags = require('@models/Tag')
|
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
let userId = null
|
2020-07-22 22:00:20 -07:00
|
|
|
let masterKey = null
|
2019-07-19 13:51:57 -07:00
|
|
|
|
|
|
|
// middleware that is specific to this router
|
|
|
|
router.use(function setUserId (req, res, next) {
|
2020-07-22 22:00:20 -07:00
|
|
|
|
|
|
|
//Session key is required to continue
|
|
|
|
if(!req.headers.sessionId){
|
|
|
|
next('Unauthorized')
|
|
|
|
}
|
|
|
|
|
|
|
|
if(req.headers.userId){
|
2019-07-19 13:51:57 -07:00
|
|
|
userId = req.headers.userId
|
2020-07-22 22:00:20 -07:00
|
|
|
masterKey = req.headers.masterKey
|
|
|
|
next()
|
2019-07-19 13:51:57 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-07-21 09:28:07 -07:00
|
|
|
//Get the latest notes the user has created
|
|
|
|
router.post('/suggest', function (req, res) {
|
|
|
|
Tags.suggest(userId, req.body.noteId, req.body.tagText)
|
|
|
|
.then( data => res.send(data) )
|
|
|
|
})
|
|
|
|
|
2019-07-30 13:27:26 -07:00
|
|
|
//Get latest tags based on when it was put on a note
|
|
|
|
router.post('/latest', function (req, res) {
|
|
|
|
Tags.latest(userId, req.body.noteId)
|
|
|
|
.then( data => res.send(data) )
|
|
|
|
})
|
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
//Get the latest notes the user has created
|
|
|
|
router.post('/addtonote', function (req, res) {
|
|
|
|
Tags.addToNote(userId, req.body.noteId, req.body.tagText.toLowerCase())
|
|
|
|
.then( data => res.send(data) )
|
|
|
|
})
|
|
|
|
|
|
|
|
router.post('/removefromnote', function (req, res) {
|
|
|
|
Tags.removeTagFromNote(userId, req.body.tagId)
|
|
|
|
.then( data => res.send(data) )
|
|
|
|
})
|
|
|
|
|
|
|
|
//Get the latest notes the user has created
|
|
|
|
router.post('/get', function (req, res) {
|
|
|
|
Tags.get(userId, req.body.noteId)
|
|
|
|
.then( data => res.send(data) )
|
|
|
|
})
|
|
|
|
|
2022-01-26 20:48:19 -08:00
|
|
|
//Get the latest notes the user has created
|
|
|
|
router.post('/fornote', function (req, res) {
|
|
|
|
Tags.fornote(userId, req.body.noteId)
|
|
|
|
.then( data => res.send(data) )
|
|
|
|
})
|
|
|
|
|
2020-01-02 17:26:55 -08:00
|
|
|
//Get all the tags for this user in order of usage
|
|
|
|
router.post('/usertags', function (req, res) {
|
2020-02-11 21:29:56 -08:00
|
|
|
Tags.userTags(userId, req.body.searchQuery, req.body.searchTags, req.body.fastFilters)
|
2020-01-02 17:26:55 -08:00
|
|
|
.then( data => res.send(data) )
|
|
|
|
})
|
|
|
|
|
2019-07-19 13:51:57 -07:00
|
|
|
module.exports = router
|