2018-03-24 11:08:29 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const sql = require('../../services/sql');
|
2019-02-16 04:21:26 +08:00
|
|
|
const utils = require('../../services/utils');
|
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');
|
2018-03-24 11:08:29 +08:00
|
|
|
const parseFilters = require('../../services/parse_filters');
|
|
|
|
const buildSearchQuery = require('../../services/build_search_query');
|
|
|
|
|
2018-03-31 05:29:13 +08:00
|
|
|
async function searchNotes(req) {
|
2019-03-16 23:52:58 +08:00
|
|
|
const filters = parseFilters(req.params.searchString);
|
2018-03-24 11:08:29 +08:00
|
|
|
|
2019-03-16 23:52:58 +08:00
|
|
|
const {query, params} = buildSearchQuery(filters);
|
2018-03-24 11:08:29 +08:00
|
|
|
|
2019-03-16 23:52:58 +08:00
|
|
|
const labelFiltersNoteIds = await sql.getColumn(query, params);
|
2018-06-04 08:42:25 +08:00
|
|
|
|
2019-03-16 23:52:58 +08:00
|
|
|
return labelFiltersNoteIds.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
|
|
|
|
};
|