Incremental Commit to see WTF I was doing.

This commit is contained in:
max committed 2025-09-14 19:13:47 +00:00
1 parent 276a72b4ce
commit 0b77b0516d
35 files changed
+774 -47

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
let db = require('@config/database')
let Note = require('@models/Note')
let CycleTracking = module.exports = {}
CycleTracking.get = (userId, masterKey) => {
return new Promise((resolve, reject) => {
db.promise()
.query(`
SELECT note.id FROM note WHERE quick_note = 2 AND user_id = ? LIMIT 1`, [userId])
.then((rows, fields) => {
//Quick Note is set, return note object
if(rows[0][0] != undefined){
let noteId = rows[0][0].id
const note = Note.get(userId, noteId, masterKey)
.then(noteData => {
return resolve(noteData)
})
} else {
//Or create a new note
let finalId = null
return Note.create(userId, 'Cycle 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)
})
}
CycleTracking.save = (userId, cycleData, masterKey) => {
return new Promise((resolve, reject) => {
let finalId = null
CycleTracking.get(userId, masterKey)
.then(noteObject => {
return Note.update(userId, noteObject.id, cycleData, noteObject.title, noteObject.color, noteObject.pinned, noteObject.archived, null, masterKey)
})
.then( saveResults => {
return resolve(saveResults)
})
})
}
+41
View File
@@ -0,0 +1,41 @@
//
// /api/cycle-tracking
//
var express = require('express')
var router = express.Router()
let CycleTracking = require('@models/CycleTracking');
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()
}
})
//Get quick note text
router.post('/get', function (req, res) {
CycleTracking.get(userId, masterKey)
.then( data => res.send(data) )
})
//Push text to quick note
router.post('/save', function (req, res) {
CycleTracking.save(userId, req.body.cycleData, masterKey)
.then( data => res.send(data) )
})
module.exports = router