Authored by 李奇

文章模块添加

/**
* 文章controller
* @author: leo <qi.li@yoho.cn>
* @date: 23/06/2017
*/
const mysqlCli = global.yoho.utils.mysqlCli;
const TABLE_ACT_ARTICLE = 'act_article';
function all(req, res) {
mysqlCli.changeDatabase(mysqlCli.database).then(() => {
mysqlCli.query(`select * from ${TABLE_ACT_ARTICLE}`)
.then(result => {
res.json({
code: 200,
data: {
total: result.length
}
});
});
});
}
module.exports = {
all
};
... ...
/**
* index.js
* @author: leo
* 文章app
* @author: leo <qi.li@yoho.cn>
* @date: 23/06/2017
*/
const express = require('express');
... ...
/**
* index.js
* @author: leo
* 文章router
* @author: leo <qi.li@yoho.cn>
* @date: 23/06/2017
*/
const express = require('express');
const router = express.Router(); // eslint-disable-line
const vote = require('./controllers/vote');
const article = require('./controllers/article');
router.get('/', vote.getAll);
router.post('/', vote.addOne);
// router.get('/:vote_id', vote.getOne);
// router.put('/:vote_id', vote.putOne);
// router.delete('/:vote_id', vote.deleteOne);
router.get('/all', article.all);
module.exports = router;
... ...
/**
* 投票
* @author: leo
* @date: 23/06/2017
*/
const mysqlCli = global.yoho.utils.mysqlCli;
function getAll(req, res) {
mysqlCli.query('select * from vote')
.then(result => {
res.end(JSON.stringify(result));
});
}
function addOne(req, res) {
mysqlCli.insert(`insert vote (name) values ('${req.query.name}');`)
.then(insertId => {
res.end(insertId.toString());
});
}
module.exports = {
getAll,
addOne
};
... ... @@ -3,13 +3,13 @@
* @author: Leo<qi.li@yoho.cn>
* @date: 2017/6/23
*/
const vote = require('./apps/vote');
const article = require('./apps/article');
const passport = require('./apps/passport');
module.exports = app => {
// 短信
// 验证
app.use('/passport', passport);
// 投票
app.use('/votes', vote);
// 文章
app.use('/article', article);
};
... ...
... ... @@ -5,7 +5,7 @@
*/
const logger = global.yoho.logger;
module.exports = (err, req, res) => { // eslint-disable-line
module.exports = (err, req, res, next) => { // eslint-disable-line
logger.error(err);
if (err.code === 401) {
return res.status(401).json({
... ...