2017-10-21 21:10:33 -04:00
|
|
|
"use strict";
|
|
|
|
|
2017-10-14 23:31:44 -04:00
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
2017-10-15 19:47:05 -04:00
|
|
|
const sql = require('../../services/sql');
|
|
|
|
const auth = require('../../services/auth');
|
2017-11-14 22:21:56 -05:00
|
|
|
const protected_session = require('../../services/protected_session');
|
2017-11-16 21:50:00 -05:00
|
|
|
const sync_table = require('../../services/sync_table');
|
2018-01-07 09:35:44 -05:00
|
|
|
const wrap = require('express-promise-wrap').wrap;
|
2017-10-14 23:31:44 -04:00
|
|
|
|
2018-01-07 09:35:44 -05:00
|
|
|
router.get('/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
2017-10-14 23:31:44 -04:00
|
|
|
const noteId = req.params.noteId;
|
2018-03-25 20:52:38 -04:00
|
|
|
const revisions = await sql.getRows("SELECT * FROM note_revisions WHERE noteId = ? order by dateModifiedTo desc", [noteId]);
|
|
|
|
protected_session.decryptNoteRevisions(req, revisions);
|
2017-10-14 23:31:44 -04:00
|
|
|
|
2018-03-25 20:52:38 -04:00
|
|
|
res.send(revisions);
|
2018-01-07 09:35:44 -05:00
|
|
|
}));
|
2017-10-14 23:31:44 -04:00
|
|
|
|
2018-01-07 09:35:44 -05:00
|
|
|
router.put('', auth.checkApiAuth, wrap(async (req, res, next) => {
|
2018-01-28 21:57:46 -05:00
|
|
|
const sourceId = req.headers.source_id;
|
2017-12-16 20:48:34 -05:00
|
|
|
|
2017-11-28 17:24:08 -05:00
|
|
|
await sql.doInTransaction(async () => {
|
2018-01-28 19:38:05 -05:00
|
|
|
await sql.replace("note_revisions", req.body);
|
2017-11-02 23:36:58 -04:00
|
|
|
|
2018-03-25 20:52:38 -04:00
|
|
|
await sync_table.addNoteRevisionSync(req.body.noteRevisionId, sourceId);
|
2017-11-02 23:36:58 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
res.send();
|
2018-01-07 09:35:44 -05:00
|
|
|
}));
|
2017-11-02 23:36:58 -04:00
|
|
|
|
2017-10-14 23:31:44 -04:00
|
|
|
module.exports = router;
|