2018-03-23 23:08:29 -04:00
|
|
|
"use strict";
|
|
|
|
|
2018-04-01 21:27:46 -04:00
|
|
|
const noteService = require('../../services/notes');
|
2018-06-05 19:12:52 -04:00
|
|
|
const noteCacheService = require('../../services/note_cache');
|
2019-03-16 22:19:01 +01:00
|
|
|
const searchService = require('../../services/search');
|
2018-03-23 23:08:29 -04:00
|
|
|
|
2018-03-30 17:29:13 -04:00
|
|
|
async function searchNotes(req) {
|
2019-03-16 22:19:01 +01:00
|
|
|
const noteIds = await searchService.searchForNoteIds(req.params.searchString);
|
2018-03-23 23:08:29 -04:00
|
|
|
|
2019-03-16 22:19:01 +01:00
|
|
|
return noteIds.map(noteCacheService.getNotePath).filter(res => !!res);
|
2018-03-30 17:29:13 -04:00
|
|
|
}
|
2018-03-23 23:08:29 -04:00
|
|
|
|
2018-03-30 17:29:13 -04:00
|
|
|
async function saveSearchToNote(req) {
|
2018-03-23 23:08:29 -04:00
|
|
|
const noteContent = {
|
|
|
|
searchString: req.params.searchString
|
|
|
|
};
|
|
|
|
|
2018-06-05 19:12:52 -04:00
|
|
|
const {note} = await noteService.createNote('root', req.params.searchString, noteContent, {
|
2018-03-23 23:08:29 -04:00
|
|
|
json: true,
|
2018-03-25 23:25:17 -04:00
|
|
|
type: 'search',
|
|
|
|
mime: "application/json"
|
2018-03-23 23:08:29 -04:00
|
|
|
});
|
|
|
|
|
2018-04-03 22:15:28 -04:00
|
|
|
return { noteId: note.noteId };
|
2018-03-30 17:29:13 -04:00
|
|
|
}
|
2018-03-23 23:08:29 -04:00
|
|
|
|
2018-03-30 17:29:13 -04:00
|
|
|
module.exports = {
|
|
|
|
searchNotes,
|
|
|
|
saveSearchToNote
|
|
|
|
};
|