Adding everything to get started on cycle tracking and maybe avid habit clone
This commit is contained in:
@@ -46,14 +46,17 @@ Attachment.textSearch = (userId, searchTerm) => {
|
||||
})
|
||||
}
|
||||
|
||||
Attachment.search = (userId, noteId, attachmentType, offset, setSize) => {
|
||||
Attachment.search = (userId, noteId, attachmentType, offset, setSize, includeShared) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
let params = [userId]
|
||||
let query = 'SELECT * FROM attachment WHERE user_id = ? AND visible = 1 '
|
||||
let query = `
|
||||
SELECT attachment.*, note.share_user_id FROM attachment
|
||||
JOIN note ON (attachment.note_id = note.id)
|
||||
WHERE attachment.user_id = ? AND visible = 1 `
|
||||
|
||||
if(noteId && noteId > 0){
|
||||
query += 'AND note_id = ? '
|
||||
query += 'AND attachment.note_id = ? '
|
||||
params.push(noteId)
|
||||
}
|
||||
|
||||
@@ -64,11 +67,16 @@ Attachment.search = (userId, noteId, attachmentType, offset, setSize) => {
|
||||
query += 'AND attachment_type > 1 '
|
||||
}
|
||||
|
||||
if(!noteId){
|
||||
const sharedOrNot = includeShared ? ' NOT ':' '
|
||||
query += `AND note.share_user_id IS${sharedOrNot}NULL `
|
||||
}
|
||||
|
||||
|
||||
query += 'ORDER BY last_indexed DESC '
|
||||
|
||||
const limitOffset = parseInt(offset, 10) || 0 //Either parse int, or use zero
|
||||
const parsedSetSize = parseInt(setSize, 10) || 20 //Either parse int, or use zero
|
||||
const parsedSetSize = parseInt(setSize, 10) || 20
|
||||
query += ` LIMIT ${limitOffset}, ${parsedSetSize}`
|
||||
|
||||
db.promise()
|
||||
|
@@ -9,7 +9,7 @@ const speakeasy = require('speakeasy')
|
||||
|
||||
let User = module.exports = {}
|
||||
|
||||
const version = '3.4.3'
|
||||
const version = '3.5.0'
|
||||
|
||||
//Login a user, if that user does not exist create them
|
||||
//Issues login token
|
||||
@@ -35,7 +35,7 @@ User.login = (username, password, authToken = null) => {
|
||||
//
|
||||
if(rows[0].length == 1){
|
||||
|
||||
//Pull out user data from database results
|
||||
//Pull out user data from database results
|
||||
const lookedUpUser = rows[0][0]
|
||||
|
||||
//Verify Token if set
|
||||
@@ -255,7 +255,7 @@ User.getCounts = (userId) => {
|
||||
WHERE user_id = ?
|
||||
GROUP BY tag_id
|
||||
ORDER BY uses DESC
|
||||
LIMIT 5
|
||||
LIMIT 16
|
||||
`, [userId])
|
||||
|
||||
}).then( (rows, fields) => {
|
||||
|
@@ -26,7 +26,7 @@ router.use(function setUserId (req, res, next) {
|
||||
})
|
||||
|
||||
router.post('/search', function (req, res) {
|
||||
Attachment.search(userId, req.body.noteId, req.body.attachmentType, req.body.offset, req.body.setSize)
|
||||
Attachment.search(userId, req.body.noteId, req.body.attachmentType, req.body.offset, req.body.setSize, req.body.includeShared)
|
||||
.then( data => res.send(data) )
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user