notes_tree now has note_tree_id so we stricly distinguish between working on notes or note trees

This commit is contained in:
azivner
2017-11-18 17:05:50 -05:00
parent dec9cad106
commit 5fb94fcbbd
17 changed files with 203 additions and 129 deletions

View File

@@ -6,27 +6,32 @@ const sql = require('../../services/sql');
const auth = require('../../services/auth');
const utils = require('../../services/utils');
const sync_table = require('../../services/sync_table');
const options = require('../../services/options');
router.get('', auth.checkApiAuth, async (req, res, next) => {
res.send(await getRecentNotes());
});
router.put('/:noteId', auth.checkApiAuth, async (req, res, next) => {
router.put('/:noteTreeId', auth.checkApiAuth, async (req, res, next) => {
const noteTreeId = req.params.noteTreeId;
await sql.replace('recent_notes', {
note_id: req.params.noteId,
note_tree_id: noteTreeId,
date_accessed: utils.nowTimestamp(),
is_deleted: 0
});
await sync_table.addRecentNoteSync(req.params.noteId);
await sync_table.addRecentNoteSync(noteTreeId);
await options.setOption('start_note_tree_id', noteTreeId);
res.send(await getRecentNotes());
});
router.delete('/:noteId', auth.checkApiAuth, async (req, res, next) => {
await sql.execute('UPDATE recent_notes SET is_deleted = 1 WHERE note_id = ?', [req.params.noteId]);
router.delete('/:noteTreeId', auth.checkApiAuth, async (req, res, next) => {
await sql.execute('UPDATE recent_notes SET is_deleted = 1 WHERE note_tree_id = ?', [req.params.noteTreeId]);
await sync_table.addRecentNoteSync(req.params.noteId);
await sync_table.addRecentNoteSync(req.params.noteTreeId);
res.send(await getRecentNotes());
});