index.js 811 Bytes
var msgModel = require('../../models/message');
var errUtil = require('../../util/error');

/**
 * 发送站内信
 */
exports.sendSingleMessage = (req, res) => {
    var uid = req.body.uid,
        title = req.body.title,
        content = req.body.content;

    // 校验浏览器传来的参数
    if (!uid || !title || !content) {
        return res.json({
            code: 400,
            message: '参数不全, 需要uid, title, content',
            data: ''
        });
    }

    // TODO: 校验参数有效

    // 传入参数给 model
    return msgModel.sendSingleMessage({
        uid: uid,
        title: title,
        content: content
    }).then(function(data) {
        res.send(data);
    }).catch((err) => {
        errUtil.webError(err, res); // 抓取 Promise 链的错误
    });
};