new-user.js 891 Bytes
/**
 * Created by TaoHuang on 2017/2/17.
 */

'use strict';

const _ = require('lodash');
const config = global.yoho.config;
const newUserService = require('../models/new-user-service');

const check = (req, res, next) => {
    let uid = req.user.uid;

    if (_.has(req.cookies, '__NEW_USER')) {
        return res.json({
            code: 200,
            message: '已设置过新客'
        });
    }

    newUserService.check(uid).then((result) => {
        if (_.isEmpty(result)) {
            return res.json({
                code: 500,
                message: '服务器错误'
            });
        }

        res.cookie('__NEW_USER', (result.isNew ? 1 : 0), {domain: config.cookieDomain});

        return res.json({
            code: 200,
            data: result,
            message: '设置成功新客'
        });
    }).catch(next);
};

module.exports = {
    check
};