Notes/routes/api/sync.js

66 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-10-24 22:58:59 -04:00
"use strict";
const express = require('express');
const router = express.Router();
const auth = require('../../services/auth');
2017-10-26 21:16:21 -04:00
const sync = require('../../services/sync');
2017-10-31 19:34:58 -04:00
const sql = require('../../services/sql');
2017-10-24 22:58:59 -04:00
2017-10-29 11:22:41 -04:00
router.post('/now', auth.checkApiAuth, async (req, res, next) => {
const log = await sync.sync();
res.send({
success: true,
log: log
});
});
2017-10-31 19:34:58 -04:00
router.get('/changed', auth.checkApiAuth, async (req, res, next) => {
const lastSyncId = parseInt(req.query.lastSyncId);
2017-10-31 20:09:07 -04:00
const sourceId = req.query.sourceId;
2017-10-24 22:58:59 -04:00
2017-10-31 19:34:58 -04:00
const result = await sync.getChanged(lastSyncId, sourceId);
2017-10-29 14:55:48 -04:00
res.send(result);
2017-10-26 21:16:21 -04:00
});
2017-10-31 19:34:58 -04:00
router.get('/notes/:noteId', auth.checkApiAuth, async (req, res, next) => {
const noteId = req.params.noteId;
2017-10-26 21:16:21 -04:00
2017-10-31 19:34:58 -04:00
res.send({
entity: await sql.getSingleResult("SELECT * FROM notes WHERE note_id = ?", [noteId]),
links: await sql.getResults("SELECT * FROM links WHERE note_id = ?", [noteId])
});
2017-10-25 22:39:21 -04:00
});
2017-10-31 19:34:58 -04:00
router.get('/notes_tree/:noteId', auth.checkApiAuth, async (req, res, next) => {
2017-10-25 22:39:21 -04:00
const noteId = req.params.noteId;
2017-10-31 19:34:58 -04:00
res.send(await sql.getSingleResult("SELECT * FROM notes_tree WHERE note_id = ?", [noteId]));
});
router.get('/notes_history/:noteHistoryId', auth.checkApiAuth, async (req, res, next) => {
const noteHistoryId = req.params.noteHistoryId;
res.send(await sql.getSingleResult("SELECT * FROM notes_history WHERE note_history_id = ?", [noteHistoryId]));
2017-10-26 21:16:21 -04:00
});
2017-10-29 22:22:30 -04:00
router.put('/notes', auth.checkApiAuth, async (req, res, next) => {
2017-10-31 19:34:58 -04:00
await sync.updateNote(req.body.entity, req.body.links, req.body.source_id);
2017-10-29 22:22:30 -04:00
res.send({});
});
router.put('/notes_tree', auth.checkApiAuth, async (req, res, next) => {
2017-10-31 19:34:58 -04:00
await sync.updateNoteTree(req.body.entity, req.body.source_id);
2017-10-29 22:22:30 -04:00
res.send({});
});
router.put('/notes_history', auth.checkApiAuth, async (req, res, next) => {
2017-10-31 19:34:58 -04:00
await sync.updateNoteHistory(req.body.entity, req.body.source_id);
2017-10-25 22:39:21 -04:00
2017-10-26 21:16:21 -04:00
res.send({});
2017-10-24 22:58:59 -04:00
});
module.exports = router;