2018-03-24 11:08:29 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const sql = require('../../services/sql');
|
2018-04-02 09:27:46 +08:00
|
|
|
const noteService = require('../../services/notes');
|
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) {
|
2018-04-01 21:59:44 +08:00
|
|
|
const {labelFilters, searchText} = parseFilters(req.params.searchString);
|
2018-03-24 11:08:29 +08:00
|
|
|
|
2018-04-01 21:59:44 +08:00
|
|
|
const {query, params} = buildSearchQuery(labelFilters, searchText);
|
2018-03-24 11:08:29 +08:00
|
|
|
|
|
|
|
const noteIds = await sql.getColumn(query, params);
|
|
|
|
|
2018-03-31 05:29:13 +08:00
|
|
|
return noteIds;
|
|
|
|
}
|
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-04-04 10:15:28 +08:00
|
|
|
const {note} = await noteService.createNote('root', 'Search note', 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
|
|
|
|
};
|