|
|
@ -61,16 +61,18 @@ router.post('/load-bin', (req, res)=>{
|
|
|
|
|
|
|
|
|
|
|
|
const search_stmt =
|
|
|
|
const search_stmt =
|
|
|
|
"SELECT n.id, n.text, n.modified FROM note AS n"
|
|
|
|
"SELECT n.id, n.text, n.modified FROM note AS n"
|
|
|
|
+" WHERE n.text LIKE '%' || $1 || '%'" // need to use string concat otherwise the `$1` is viewed as part of the string instead of a placeholder
|
|
|
|
+" INNER JOIN bin_note AS bn"
|
|
|
|
+" ORDER BY n.modified DESC";
|
|
|
|
+" ON bn.note_id = n.id AND bn.bin_id = $2"
|
|
|
|
|
|
|
|
+" WHERE n.text LIKE '%' || $1 || '%'"; // need to use string concat otherwise the `$1` is viewed as part of the string instead of a placeholder
|
|
|
|
|
|
|
|
const order_desc_stmt = " ORDER BY n.modified DESC";
|
|
|
|
|
|
|
|
const order_asc_stmt = " ORDER BY n.modified ASC";
|
|
|
|
// {search_term, sorting, bin_id}
|
|
|
|
// {search_term, sorting, bin_id}
|
|
|
|
router.post('/search', (req, res)=>{
|
|
|
|
router.post('/search', (req, res)=>{
|
|
|
|
const search_term = req.body.search_term;
|
|
|
|
const {search_term, bin_id, sorting} = req.body;
|
|
|
|
db.query(search_stmt, [search_term])
|
|
|
|
db.query(search_stmt+(sorting==='old->new'?order_asc_stmt:order_desc_stmt), [search_term, bin_id])
|
|
|
|
.then(result => {
|
|
|
|
.then(result => {
|
|
|
|
res.json({status:'ok', notes:result.rows});
|
|
|
|
res.json({success:true, notes:result.rows});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// {status: 'ok', notes}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const upsert_note_stmt =
|
|
|
|
const upsert_note_stmt =
|
|
|
|