Not really sure what is going on, have not done a commit in a while.

I assume this is all the metric tracking changes.
Looks like some script changes as well.
This commit is contained in:
Max
2023-02-12 18:41:55 +00:00
parent 48c1fa8e69
commit 39e153b8e1
15 changed files with 303 additions and 1480 deletions

View File

@@ -2,7 +2,7 @@ let db = require('@config/database')
let Note = require('@models/Note')
let MetricTracking = module.exports = {}
let MetricTracking = module.exports = {};
MetricTracking.get = (userId, masterKey) => {
@@ -23,31 +23,36 @@ MetricTracking.get = (userId, masterKey) => {
})
} else {
//Or create a new note
let finalId = null
return Note.create(userId, 'Metric Tracking', '', masterKey)
.then(insertedId => {
finalId = insertedId
db.promise().query('UPDATE note SET quick_note = 2 WHERE id = ? AND user_id = ?',[insertedId, userId])
.then((rows, fields) => {
const note = Note.get(userId, finalId, masterKey)
.then(noteData => {
return resolve(noteData)
})
})
})
return resolve('no data')
}
})
.catch(console.log)
})
}
MetricTracking.save = (userId, cycleData, masterKey) => {
MetricTracking.create = (userId, masterKey) => {
return new Promise((resolve, reject) => {
let finalId = null
return Note.create(userId, 'Metric Tracking', '', masterKey)
.then(insertedId => {
finalId = insertedId
db.promise().query('UPDATE note SET quick_note = 2 WHERE id = ? AND user_id = ?',[insertedId, userId])
.then((rows, fields) => {
const note = Note.get(userId, finalId, masterKey)
.then(noteData => {
return resolve(noteData)
})
})
})
.catch(console.log)
})
}
MetricTracking.save = (userId, metricData, masterKey) => {
return new Promise((resolve, reject) => {
let finalId = null
@@ -55,7 +60,7 @@ MetricTracking.save = (userId, cycleData, masterKey) => {
MetricTracking.get(userId, masterKey)
.then(noteObject => {
return Note.update(userId, noteObject.id, cycleData, noteObject.title, noteObject.color, noteObject.pinned, noteObject.archived, null, masterKey)
return Note.update(userId, noteObject.id, metricData, noteObject.title, noteObject.color, noteObject.pinned, noteObject.archived, null, masterKey)
})
.then( saveResults => {

View File

@@ -9,7 +9,7 @@ const speakeasy = require('speakeasy')
let User = module.exports = {}
const version = '3.6.2'
const version = '3.6.3'
//Login a user, if that user does not exist create them
//Issues login token
@@ -193,13 +193,13 @@ User.register = (username, password) => {
}
//Counts notes, pinned notes, archived notes, shared notes, unread notes, total files and types
User.getCounts = (userId) => {
User.getCounts = (userId, extendedOptions) => {
return new Promise((resolve, reject) => {
let countTotals = {
tags: {}
}
const userHash = cs.hash(String(userId)).toString('base64')
// const userHash = cs.hash(String(userId)).toString('base64')
db.promise().query(
`SELECT
@@ -279,7 +279,38 @@ User.getCounts = (userId) => {
countTotals['currentVersion'] = version
resolve(countTotals)
// Allow for extended options set on page load
if(extendedOptions){
db.promise().query(
`SELECT updated FROM note
JOIN note_raw_text ON note_raw_text.id = note.note_raw_text_id
WHERE note.quick_note = 2
AND user_id = ?`, [userId])
.then( (rows, fields) => {
if(rows[0][0] && rows[0][0].updated){
const lastOpened = rows[0][0].updated
const timeDiff = Math.round(((+new Date) - (lastOpened))/1000)
const hoursInSeconds = (12 * 60 * 60) //12 hours
// Show metric tracking button if its been 12 hours since last entry
if(lastOpened && timeDiff > hoursInSeconds){
countTotals['showTrackMetricsButton'] = true
}
}
resolve(countTotals)
})
} else {
resolve(countTotals)
}
})
})

View File

@@ -25,12 +25,16 @@ router.use(function setUserId (req, res, next) {
}
})
//Get quick note text
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)

View File

@@ -53,7 +53,7 @@ router.post('/revokesessions', function(req, res) {
// fetch counts of users notes
router.post('/totals', function (req, res) {
User.getCounts(req.headers.userId)
User.getCounts(req.headers.userId, req.body.extendedOptions)
.then( countsObject => res.send( countsObject ))
})