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-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-24 23:14:26 -04:00
|
|
|
router.get('/changed/:since', auth.checkApiAuth, async (req, res, next) => {
|
|
|
|
const since = parseInt(req.params.since);
|
2017-10-24 22:58:59 -04:00
|
|
|
|
2017-10-29 14:55:48 -04:00
|
|
|
const result = await sync.getChangedSince(since);
|
|
|
|
|
|
|
|
res.send(result);
|
2017-10-26 21:16:21 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
router.put('/changed', auth.checkApiAuth, async (req, res, next) => {
|
|
|
|
await sync.putChanged(req.body);
|
|
|
|
|
|
|
|
res.send({});
|
2017-10-25 22:39:21 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
router.get('/note/:noteId/:since', auth.checkApiAuth, async (req, res, next) => {
|
|
|
|
const noteId = req.params.noteId;
|
|
|
|
const since = parseInt(req.params.since);
|
|
|
|
|
2017-10-26 21:16:21 -04:00
|
|
|
res.send(await sync.getNoteSince(noteId, since));
|
|
|
|
});
|
|
|
|
|
2017-10-29 22:22:30 -04:00
|
|
|
router.put('/notes', auth.checkApiAuth, async (req, res, next) => {
|
|
|
|
await sync.updateNote(req.body);
|
|
|
|
|
|
|
|
res.send({});
|
|
|
|
});
|
|
|
|
|
|
|
|
router.put('/notes_tree', auth.checkApiAuth, async (req, res, next) => {
|
|
|
|
await sync.updateNoteTree(req.body);
|
|
|
|
|
|
|
|
res.send({});
|
|
|
|
});
|
|
|
|
|
|
|
|
router.put('/notes_history', auth.checkApiAuth, async (req, res, next) => {
|
|
|
|
await sync.updateNoteHistory(req.body);
|
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;
|