saved search can now be created from the search dialog

This commit is contained in:
azivner
2018-03-23 23:08:29 -04:00
parent ac978c3fa7
commit f8649feea4
8 changed files with 142 additions and 113 deletions

35
src/routes/api/search.js Normal file
View File

@@ -0,0 +1,35 @@
"use strict";
const express = require('express');
const router = express.Router();
const auth = require('../../services/auth');
const sql = require('../../services/sql');
const notes = require('../../services/notes');
const wrap = require('express-promise-wrap').wrap;
const parseFilters = require('../../services/parse_filters');
const buildSearchQuery = require('../../services/build_search_query');
router.get('/:searchString', auth.checkApiAuth, wrap(async (req, res, next) => {
const {attrFilters, searchText} = parseFilters(req.params.searchString);
const {query, params} = buildSearchQuery(attrFilters, searchText);
const noteIds = await sql.getColumn(query, params);
res.send(noteIds);
}));
router.post('/:searchString', auth.checkApiAuth, wrap(async (req, res, next) => {
const noteContent = {
searchString: req.params.searchString
};
const noteId = await notes.createNote('root', 'Search note', noteContent, {
json: true,
type: 'search'
});
res.send({ noteId });
}));
module.exports = router;