I assume this is all the metric tracking changes. Looks like some script changes as well.
71 lines
1.6 KiB
JavaScript
71 lines
1.6 KiB
JavaScript
let db = require('@config/database')
|
|
|
|
let Note = require('@models/Note')
|
|
|
|
let MetricTracking = module.exports = {};
|
|
|
|
|
|
MetricTracking.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 {
|
|
return resolve('no data')
|
|
}
|
|
|
|
})
|
|
.catch(console.log)
|
|
})
|
|
}
|
|
|
|
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
|
|
|
|
MetricTracking.get(userId, masterKey)
|
|
.then(noteObject => {
|
|
|
|
return Note.update(userId, noteObject.id, metricData, noteObject.title, noteObject.color, noteObject.pinned, noteObject.archived, null, masterKey)
|
|
|
|
})
|
|
.then( saveResults => {
|
|
return resolve(saveResults)
|
|
})
|
|
})
|
|
|
|
} |