|
1 |
| -const dbConnection = require('../database/db_connection.js'); |
| 1 | +const dbConnection = require('../database/db_connection.js') |
2 | 2 |
|
3 |
| -function getData(search, cb){ |
4 |
| - if (!search){ |
5 |
| - dbConnection.query('SELECT shop_name, shop_rating, cost, address, description, tags FROM shops;', (err, res) => { |
6 |
| - if (err) cb(err); |
7 |
| - cb(null, res.rows); |
8 |
| - }); |
9 |
| - } |
10 |
| - else { |
11 |
| - // dbConnection.query(`SELECT shop_name, shop_rating, cost, address, description,tags FROM shops WHERE tags LIKE '%`+ search +`%';`, (err, res) |
12 | 3 |
|
13 |
| - dbConnection.query(`SELECT shop_name, shop_rating, cost, address, description,tags FROM shops WHERE tags ILIKE '%${search}%';`, |
14 |
| - (err, res) => { |
15 |
| - if (err) cb(err); |
16 |
| - cb(null, res.rows); |
17 |
| - }); |
18 |
| - }; |
| 4 | +function getAllData(cb){ |
| 5 | + dbConnection.query('SELECT shop_name, shop_rating, cost, address, description, tags FROM shops;', (err, res) => { |
| 6 | + if (err) return cb(err); |
| 7 | + cb(null, res.rows); |
| 8 | + }); |
19 | 9 | }
|
20 | 10 |
|
21 |
| -// function render(err, res){ |
22 |
| -// if (err) { |
23 |
| -// console.log(err); |
24 |
| -// return; |
25 |
| -// } |
26 |
| -// else { |
27 |
| -// console.log(res); |
28 |
| -// } |
29 |
| -// } |
30 |
| -// getData(render); |
31 |
| -// getData(render, 'coffee'); |
| 11 | +function getSearchData(search, cb){ |
| 12 | + dbConnection.query(`SELECT shop_name, shop_rating, cost, address, description,tags FROM shops WHERE tags ILIKE '%${search}%';`, |
| 13 | + (err, res) => { |
| 14 | + if (err) return cb(err); |
| 15 | + cb(null, res.rows); |
| 16 | + }); |
| 17 | +} |
32 | 18 |
|
33 | 19 | module.exports = {
|
34 |
| - getData: getData |
| 20 | + getAllData: getAllData, |
| 21 | + getSearchData: getSearchData |
35 | 22 | }
|
0 commit comments