user.js 2.64 KB
/**
 * 个人中心---编辑个人资料
 * @author gaohongwei <hongwei.gao@yoho.cn>
 * @date: 2016/8/16
 */
'use strict';

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

/**
 * 个人中心
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.index = (req, res, next) => {

    let uid = req.user.uid;

    let responseData = {
        module: 'home',
        page: 'user'
    };

    // 真实数据输出
    req.ctx(userModel).getUserInfo(uid).then(result => {
        responseData.user = result;
        res.render('home/user/index', responseData);
    }).catch(next);

};

/**
 * 编辑会员信息
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.editUserInfo = (req, res, next) => {

    let uid = req.user.uid;

    // 真实数据输出
    req.ctx(userModel).editUserInfo(req, uid).then(result => {
        res.json(result);
    }).catch(next);

};

/**
 * 编辑联系信息
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.editUserContactInfo = (req, res, next) => {

    let uid = req.user.uid;

    // 真实数据输出
    req.ctx(userModel).editUserContactInfo(req, uid).then(result => {
        res.json(result);
    }).catch(next);

};

/**
 * 编辑购物着装、习惯
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.editUserHabitsInfo = (req, res, next) => {

    let uid = req.user.uid;

    // 真实数据输出
    req.ctx(userModel).editUserHabitsInfo(req, uid).then(result => {
        res.json(result);
    }).catch(next);

};


/**
 * 编辑喜爱品牌
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.editUserLikeBrand = (req, res, next) => {

    let uid = req.user.uid;

    // 真实数据输出
    req.ctx(userModel).editUserLikeBrand(req, uid).then(result => {
        res.json(result);
    }).catch(next);

};

/**
 * 是否在品牌库
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.isBrandName = (req, res, next) => {
    // 真实数据输出
    req.ctx(userModel).isBrandName(req).then(result => {
        res.json(result);
    }).catch(next);

};

exports.getProviceList = (req, res, next) => {
    // 真实数据输出
    req.ctx(userModel).getProviceList(req.query.id).then(result => {
        res.json(result);
    }).catch(next);

};