SolidScribe/server/routes/userController.js
Max G 05152cd5a4 Added counts to each category
Counts update on certain events and show or hide various elements
Fixed various little ui element issues

fixes #6
2020-02-11 21:11:14 +00:00

56 lines
1.2 KiB
JavaScript

var express = require('express')
var router = express.Router()
let User = require('@models/User');
// 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 login 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: '',
username: ''
}
User.login(username, password)
.then(function(loginToken){
//Return json web token to user
returnData['success'] = true
returnData['token'] = loginToken
returnData['username'] = username
res.send(returnData)
})
.catch(e => {
console.log(e)
res.send(returnData)
})
})
// fetch counts of users notes
router.post('/totals', function (req, res) {
User.getCounts(req.headers.userId)
.then( countsObject => res.send( countsObject ))
})
module.exports = router