Notes/routes/api/sync.js

33 lines
859 B
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-24 22:58:59 -04:00
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-26 21:16:21 -04:00
res.send(await sync.getChangedSince(since));
});
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));
});
router.put('/note', auth.checkApiAuth, async (req, res, next) => {
await sync.putNote(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;