product.js 983 Bytes
const express = require('express');
const logger = require('komodo-sdk/logger');
const dbEvo = require('../../db-evo');

const router = express.Router();
module.exports = router;

function pageJson(req, res) {
    const query = `
        SELECT
            UPPER(service.keyword) AS name
        FROM product
        LEFT JOIN service ON service.svc_id = product.svc_id
        WHERE
            service.svc_cat IN (1, 6)
            AND product.site_id IS NULL -- produk utama
            AND product.area_gid IS NULL -- produk utama
            AND product.route IS NULL -- produk utama        
        ORDER BY SOUNDEX(service.keyword), LENGTH(service.keyword), service.keyword;
    `.trim();

    dbEvo.query(query, [], (err, result) => {
        if (err) {
            logger.warn(`ROUTER-PRODUCTS: DB error. ${err.toString()}`);
        }

        const products = (result || []).map((item) => item.name);

        res.json(products);
    });
}

router.get('/json', pageJson);