Blame view

apps/home/controllers/complaints.js 1.3 KB
yyq authored
1 2 3 4 5 6 7 8 9
/**
 * 我的投诉controller
 * @author: yyq<yanqing.yang@yoho.cn>
 * @date: 2016/8/18
 */
'use strict';

const complaints = require('../models/complaints');
yyq authored
10 11 12 13 14 15
/**
 * 我的投诉页
 * @function index
 * @param { String } page 页码
 * @return { Object } 投诉列表数据
 */
yyq authored
16 17 18 19 20 21 22 23 24
const index = (req, res, next) => {
    let uid = req.user.uid;
    let page = req.query.page || 1;

    complaints.getComplaintsList(uid, page).then(result => {
        res.render('complaints', result);
    }).catch(next);
};
yyq authored
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
/**
 * 添加投诉接口
 * @function submit
 * @param { String } url 图片路径
 * @return { Object } 原图片路径
 */
const submit = (req, res, next) => {
    let uid = req.user.uid;
    let params = req.body;

    if (!req.xhr || !uid) {
        return next();
    }

    complaints.addComplaints(uid, params).then(result => {
        res.json(result);
    }).catch(next);
};

/**
 * 取消投诉接口
 * @function submit
 * @param { String } url 图片路径
 * @return { Object } 原图片路径
 */
const cancel = (req, res, next) => {
    let uid = req.user.uid;
    let id = req.body.id;

    if (!req.xhr || !uid) {
        return next();
    }

    complaints.cancelComplaints(uid, id).then(result => {
        res.json(result);
    }).catch(next);
};
yyq authored
63
module.exports = {
yyq authored
64 65 66
    index,
    submit,
    cancel
yyq authored
67
};