Notes/src/routes/api/note_revisions.js

34 lines
1.0 KiB
JavaScript
Raw Normal View History

2017-10-21 21:10:33 -04:00
"use strict";
const repository = require('../../services/repository');
2019-09-07 10:11:59 +02:00
const noteCacheService = require('../../services/note_cache');
async function getNoteRevisions(req) {
const noteId = req.params.noteId;
2019-03-12 20:58:31 +01:00
return await repository.getEntities("SELECT * FROM note_revisions WHERE noteId = ? order by utcDateModifiedTo desc", [noteId]);
}
2019-09-07 10:11:59 +02:00
async function getEditedNotesOnDate(req) {
const date = req.params.date;
const notes = await repository.getEntities(`
select distinct notes.*
from notes
left join note_revisions using (noteId)
where substr(notes.dateCreated, 0, 11) = ?
or substr(notes.dateModified, 0, 11) = ?
or substr(note_revisions.dateModifiedFrom, 0, 11) = ?`, [date, date, date]);
for (const note of notes) {
const notePath = noteCacheService.getNotePath(note.noteId);
note.notePath = notePath ? notePath.notePath : null;
}
return notes;
}
module.exports = {
2019-09-07 10:11:59 +02:00
getNoteRevisions,
getEditedNotesOnDate
};