Commit e4a0e52fa70101821f119d38ae16ec48ef810c28
1 parent
01545d1930
Exists in
master
JSON product hanya produk utama
Showing 1 changed file with 3 additions and 0 deletions Inline Diff
lib/webservice/router/product.js
1 | const express = require('express'); | 1 | const express = require('express'); |
2 | const logger = require('komodo-sdk/logger'); | 2 | const logger = require('komodo-sdk/logger'); |
3 | const dbEvo = require('../../db-evo'); | 3 | const dbEvo = require('../../db-evo'); |
4 | 4 | ||
5 | const router = express.Router(); | 5 | const router = express.Router(); |
6 | module.exports = router; | 6 | module.exports = router; |
7 | 7 | ||
8 | function pageJson(req, res) { | 8 | function pageJson(req, res) { |
9 | const query = ` | 9 | const query = ` |
10 | SELECT | 10 | SELECT |
11 | UPPER(service.keyword) AS name | 11 | UPPER(service.keyword) AS name |
12 | FROM product | 12 | FROM product |
13 | LEFT JOIN service ON service.svc_id = product.svc_id | 13 | LEFT JOIN service ON service.svc_id = product.svc_id |
14 | WHERE | 14 | WHERE |
15 | service.svc_cat IN (1, 6) | 15 | service.svc_cat IN (1, 6) |
16 | AND product.site_id IS NULL -- produk utama | ||
17 | AND product.area_gid IS NULL -- produk utama | ||
18 | AND product.route IS NULL -- produk utama | ||
16 | ORDER BY SOUNDEX(service.keyword), LENGTH(service.keyword), service.keyword; | 19 | ORDER BY SOUNDEX(service.keyword), LENGTH(service.keyword), service.keyword; |
17 | `.trim(); | 20 | `.trim(); |
18 | 21 | ||
19 | dbEvo.query(query, [], (err, result) => { | 22 | dbEvo.query(query, [], (err, result) => { |
20 | if (err) { | 23 | if (err) { |
21 | logger.warn(`ROUTER-PRODUCTS: DB error. ${err.toString()}`); | 24 | logger.warn(`ROUTER-PRODUCTS: DB error. ${err.toString()}`); |
22 | } | 25 | } |
23 | 26 | ||
24 | const products = (result || []).map((item) => item.name); | 27 | const products = (result || []).map((item) => item.name); |
25 | 28 | ||
26 | res.json(products); | 29 | res.json(products); |
27 | }); | 30 | }); |
28 | } | 31 | } |
29 | 32 | ||
30 | router.get('/json', pageJson); | 33 | router.get('/json', pageJson); |
31 | 34 |