favorite.js 830 Bytes
/**
 * Created by TaoHuang on 2016/6/13.
 */
'use strict';

const helpers = require(`${library}/helpers`);

const mRoot = '../models';
const service = require(`${mRoot}/favorite-service`);

/**
 * 收藏品牌ajax请求
 */
module.exports.changeFavoriteBrand = (req, res, next) => {
    // TODO: uid get
    let uid = '';
    let brandId = req.body.brandId;

    if (uid && brandId) {
        service.changeFavoriteBrandAsync(uid, brandId).then(result => {
            res.json(result)
        }).catch(next);
    } else if (!uid) {
        res.json({
            code: 403,
            message: '用户ID不存在',
            data: {
                url: helpers.urlFormat('/signin.html')
            }
        });
    } else {
        res.json({
            code: 400,
            message: '操作失败'
        });
    }
};