2017-10-22 09:10:33 +08:00
|
|
|
"use strict";
|
|
|
|
|
2018-04-01 23:05:09 +08:00
|
|
|
const repository = require('../../services/repository');
|
2019-09-07 16:11:59 +08:00
|
|
|
const noteCacheService = require('../../services/note_cache');
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2018-03-31 01:56:46 +08:00
|
|
|
async function getNoteRevisions(req) {
|
2017-10-15 11:31:44 +08:00
|
|
|
const noteId = req.params.noteId;
|
2019-09-08 15:17:16 +08:00
|
|
|
|
|
|
|
return await repository.getEntities(`
|
|
|
|
SELECT note_revisions.*
|
|
|
|
FROM note_revisions
|
|
|
|
WHERE noteId = ?
|
|
|
|
ORDER BY utcDateModifiedTo DESC`, [noteId]);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getNoteRevisionList(req) {
|
|
|
|
const noteId = req.params.noteId;
|
|
|
|
|
|
|
|
return await repository.getEntities(`
|
|
|
|
SELECT noteRevisionId,
|
|
|
|
noteId,
|
|
|
|
title,
|
|
|
|
isProtected,
|
|
|
|
utcDateModifiedFrom,
|
|
|
|
utcDateModifiedTo,
|
|
|
|
dateModifiedFrom,
|
|
|
|
dateModifiedTo,
|
|
|
|
type,
|
|
|
|
mime,
|
|
|
|
CASE isProtected WHEN 1 THEN null ELSE LENGTH(content) END AS contentLength
|
|
|
|
FROM note_revisions
|
|
|
|
WHERE noteId = ?
|
|
|
|
ORDER BY utcDateModifiedTo DESC`, [noteId]);
|
2018-03-31 01:56:46 +08:00
|
|
|
}
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2019-09-07 16:11:59 +08: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;
|
|
|
|
}
|
|
|
|
|
2018-03-31 01:56:46 +08:00
|
|
|
module.exports = {
|
2019-09-07 16:11:59 +08:00
|
|
|
getNoteRevisions,
|
2019-09-08 15:17:16 +08:00
|
|
|
getNoteRevisionList,
|
2019-09-07 16:11:59 +08:00
|
|
|
getEditedNotesOnDate
|
2018-03-31 01:56:46 +08:00
|
|
|
};
|