Recepie Sort by Name if no Option

This commit is contained in:
Thomas Mack 2019-01-07 20:25:43 +01:00
parent f4efbbc975
commit 531da9aee7
2 changed files with 9 additions and 2 deletions

View File

@ -65,12 +65,16 @@ router.get('/', function(req, res, next) {
" LEFT JOIN rezept_kategorie ON rezept.id = rezept" + " LEFT JOIN rezept_kategorie ON rezept.id = rezept" +
" LEFT JOIN kategorie on kategorie.id = kategorie "; " LEFT JOIN kategorie on kategorie.id = kategorie ";
if(req.query.term) query += " WHERE rezept.name ilike '%"+req.query.term+"%' " if(req.query.term) query += " WHERE rezept.name ilike '%"+req.query.term+"%' "
if(req.query.hashtag) query += " WHERE rezept.schluessel ilike '"+req.query.hashtag+"' "
query += " GROUP BY 1,2,3,4,5,6,7" query += " GROUP BY 1,2,3,4,5,6,7"
if(req.query['sort_by']) { if(req.query['sort_by']) {
if(req.query['sort_by'] === 'creation') query += " ORDER BY rezept.id desc"; if(req.query['sort_by'] === 'creation') query += " ORDER BY rezept.id desc";
if(req.query['sort_by'] === 'best_match') query += " ORDER BY rezept.name "; if(req.query['sort_by'] === 'best_match') query += " ORDER BY rezept.name ";
if(req.query['sort_by'] === 'rating') query += " ORDER BY rating "; if(req.query['sort_by'] === 'rating') query += " ORDER BY rating ";
} else {
query += " ORDER BY rezept.name "
} }

View File

@ -8,10 +8,11 @@ const DEBUG = false;
router.param('ingredientId', function(req, res, next, id) { router.param('ingredientId', function(req, res, next, id) {
req.ingredientId = id; req.ingredientId = id;
let query = " Select rezept_zutat.id, rezept, einheit, einheit.name as einheitname, einheit.schluessel as einheitschluessel , zutat, zutat.name as zutatname, menge, rezept_zutat.beschreibung "+ let query = " Select rezept_zutat.id, rezept, einheit, einheit.name as einheitname, einheit.schluessel as einheitschluessel , zutat, zutat.name as zutatname, menge, rezept_zutat.beschreibung, rezept.id as linkid"+
" FROM rezept_zutat "+ " FROM rezept_zutat "+
" JOIN zutat on zutat.id = zutat "+ " JOIN zutat on zutat.id = zutat "+
" JOIN einheit on einheit.id = einheit "+ " JOIN einheit on einheit.id = einheit "+
" LEFT JOIN rezept ON '#'||rezept.schluessel = zutat.name " +
" WHERE rezept =$1 AND rezept_zutat.id = $2"; " WHERE rezept =$1 AND rezept_zutat.id = $2";
if(DEBUG) console.log(query); if(DEBUG) console.log(query);
req.db.query(query, [req.recepieId, req.ingredientId], (err, rs) => { req.db.query(query, [req.recepieId, req.ingredientId], (err, rs) => {
@ -25,10 +26,12 @@ router.param('ingredientId', function(req, res, next, id) {
/* GET recepieIngredients listing. */ /* GET recepieIngredients listing. */
router.get('/', function(req, res, next) { router.get('/', function(req, res, next) {
let query = " Select rezept_zutat.id, rezept, einheit, einheit.name as einheitname, einheit.schluessel as einheitschluessel , zutat, zutat.name as zutatname, menge , rezept_zutat.beschreibung"+ let query = " Select rezept_zutat.id, rezept, einheit, einheit.name as einheitname, einheit.schluessel as einheitschluessel , zutat, zutat.name as zutatname, menge , rezept_zutat.beschreibung, rezept.id as linkid"+
" FROM rezept_zutat "+ " FROM rezept_zutat "+
" JOIN zutat on zutat.id = zutat "+ " JOIN zutat on zutat.id = zutat "+
" JOIN einheit on einheit.id = einheit "+ " JOIN einheit on einheit.id = einheit "+
" LEFT JOIN rezept ON '#'||rezept.schluessel = zutat.name " +
" WHERE rezept =$1 order by 1"; " WHERE rezept =$1 order by 1";
if(DEBUG) console.log(query); if(DEBUG) console.log(query);
req.db.query(query,[req.recepieId], (err, rs) => { req.db.query(query,[req.recepieId], (err, rs) => {