search.js 1013 Bytes
/**
 * 商品搜索controller
 * @author: sefon
 * @date: 2016-7-12 10:09:25
 */

'use strict';
const mRoot = '../models';
const search = require(`${mRoot}/search`);

/**
 * search 首页
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.index = (req, res, next) => {
    let resData = {};

    search.getSearchData(req.query).then(result => {
        Object.assign(resData, result);
        res.render('search/index', resData);
    }).catch(next);

};

/**
 * search 提示
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.suggest = (req, res, next) => {
    search.getSuggest(req.query).then(result => {
        let dest = {
            code: 200,
            message: 'suggest',
            data: result || ''
        };

        res.type('text/javascript');
        res.send(req.query.callback + '(' + JSON.stringify(dest) + ')');

    }).catch(next);
};