SolidScribe/server/routes/metrictrackingController.js

45 lines
966 B
JavaScript
Raw Permalink Normal View History

//
// /api/metric-tracking
//
var express = require('express')
var router = express.Router()
let MetricTracking = require('@models/MetricTracking');
let userId = null
let masterKey = null
// middleware that is specific to this router
router.use(function setUserId (req, res, next) {
//Session key is required to continue
if(!req.headers.sessionId){
next('Unauthorized')
}
if(req.headers.userId){
userId = req.headers.userId
masterKey = req.headers.masterKey
next()
}
})
router.post('/get', function (req, res) {
MetricTracking.get(userId, masterKey)
.then( data => res.send(data) )
})
router.post('/create', function (req, res) {
MetricTracking.create(userId, masterKey)
.then( data => res.send(data) )
})
//Push text to quick note
router.post('/save', function (req, res) {
MetricTracking.save(userId, req.body.cycleData, masterKey)
.then( data => res.send(data) )
})
module.exports = router