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