Started to build out the app. Its got a basic set of features and it should really be in VC

This commit is contained in:
Max G
2019-07-19 20:51:57 +00:00
parent dbc3e5428c
commit 61754fe290
513 changed files with 81139 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
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) )
})
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)
.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

View File

@@ -0,0 +1,33 @@
var express = require('express')
var router = express.Router()
let Tags = require('@models/Tags');
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('/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) )
})
module.exports = router

46
server/routes/user.js Normal file
View File

@@ -0,0 +1,46 @@
var express = require('express')
var router = express.Router()
let User = require('@models/Users');
// middleware that is specific to this router
router.use(function timeLog (req, res, next) {
// console.log('Time: ', Date.now())
next()
})
// define the home page route
router.get('/', function (req, res) {
res.send('User Home Page ' + User.getUsername())
})
// define the about route
router.get('/about', function (req, res) {
User.getUsername(req.headers.userId)
.then( data => res.send(data) )
})
// define the about route
router.post('/login', function (req, res) {
//Pull out variables we want
const username = req.body.username
const password = req.body.password
let returnData = {
success: false,
token: ''
}
User.login(username, password)
.then(function(loginToken){
//Return json web token to user
returnData['success'] = true
returnData['token'] = loginToken
res.send(returnData)
})
.catch(e => {
console.log(e)
res.send(returnData)
})
})
module.exports = router