2022-10-13 12:28:35 -07:00
|
|
|
//
|
2022-10-23 12:14:31 -07:00
|
|
|
// /api/metric-tracking
|
2022-10-13 12:28:35 -07:00
|
|
|
//
|
|
|
|
|
|
|
|
var express = require('express')
|
|
|
|
var router = express.Router()
|
|
|
|
|
2022-10-23 12:14:31 -07:00
|
|
|
let MetricTracking = require('@models/MetricTracking');
|
2022-10-13 12:28:35 -07:00
|
|
|
|
|
|
|
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) {
|
2022-10-23 12:14:31 -07:00
|
|
|
MetricTracking.get(userId, masterKey)
|
2022-10-13 12:28:35 -07:00
|
|
|
.then( data => res.send(data) )
|
|
|
|
})
|
|
|
|
|
2023-02-12 10:41:55 -08:00
|
|
|
router.post('/create', function (req, res) {
|
|
|
|
MetricTracking.create(userId, masterKey)
|
|
|
|
.then( data => res.send(data) )
|
|
|
|
})
|
|
|
|
|
2022-10-13 12:28:35 -07:00
|
|
|
//Push text to quick note
|
|
|
|
router.post('/save', function (req, res) {
|
2022-10-23 12:14:31 -07:00
|
|
|
MetricTracking.save(userId, req.body.cycleData, masterKey)
|
2022-10-13 12:28:35 -07:00
|
|
|
.then( data => res.send(data) )
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = router
|