...
|
...
|
@@ -7,15 +7,9 @@ const _ = require('lodash'); |
|
|
const camelcase = require('camelcase');
|
|
|
const ArticleModel = require('../models/article');
|
|
|
|
|
|
const ADD_ARTICLE_SUCCESS = '文章发表成功';
|
|
|
const GET_ARTICLES_SUCCESS = '获取文章列表成功';
|
|
|
const GET_ARTICLE_SUCCESS = '获取文章详情成功';
|
|
|
const INVALID_ACTIVITY_ID = '活动ID[actId]不能为空';
|
|
|
const INVALID_IMG = '图片[imgUrl]不能为空';
|
|
|
const INVALID_CONTENT = '内容[content]都不能为空';
|
|
|
const MISS_PARAMS = '缺少参数';
|
|
|
const INVALID_ORDER = '排序[order]值为asc或desc';
|
|
|
const INVALID_ORDER_BY = '排序字段[orderBy]非法';
|
|
|
const POST_SUCCESS = '操作成功';
|
|
|
const GET_SUCCESS = '获取成功';
|
|
|
const INVALID_PARAMS = '参数错误';
|
|
|
|
|
|
const article = {
|
|
|
/**
|
...
|
...
|
@@ -42,14 +36,14 @@ const article = { |
|
|
if (order !== 'asc' && order !== 'desc') {
|
|
|
return res.json({
|
|
|
code: 400,
|
|
|
message: INVALID_ORDER
|
|
|
message: INVALID_PARAMS
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (orderByFields.indexOf(orderBy) === -1) {
|
|
|
return res.json({
|
|
|
code: 400,
|
|
|
message: INVALID_ORDER_BY
|
|
|
message: INVALID_PARAMS
|
|
|
});
|
|
|
}
|
|
|
|
...
|
...
|
@@ -81,7 +75,7 @@ const article = { |
|
|
pageSize,
|
|
|
totalCount,
|
|
|
totalPage: Math.ceil(totalCount / pageSize),
|
|
|
message: GET_ARTICLES_SUCCESS
|
|
|
message: GET_SUCCESS
|
|
|
});
|
|
|
});
|
|
|
});
|
...
|
...
|
@@ -99,9 +93,9 @@ const article = { |
|
|
const imgUrl = req.body.imgUrl;
|
|
|
const content = req.body.content;
|
|
|
|
|
|
!imgUrl && (errorMsg = INVALID_IMG);
|
|
|
!content && (errorMsg = INVALID_CONTENT);
|
|
|
!actId && (errorMsg = INVALID_ACTIVITY_ID);
|
|
|
if (!imgUrl || !content || !actId) {
|
|
|
errorMsg = INVALID_PARAMS;
|
|
|
}
|
|
|
|
|
|
if (errorMsg) {
|
|
|
return res.json({
|
...
|
...
|
@@ -123,7 +117,7 @@ const article = { |
|
|
res.json({
|
|
|
code: 200,
|
|
|
data: {id},
|
|
|
message: ADD_ARTICLE_SUCCESS
|
|
|
message: POST_SUCCESS
|
|
|
});
|
|
|
});
|
|
|
});
|
...
|
...
|
@@ -139,8 +133,9 @@ const article = { |
|
|
const actId = req.query.actId;
|
|
|
const articleId = req.query.articleId;
|
|
|
|
|
|
!actId && (errorMsg = MISS_PARAMS);
|
|
|
!articleId && (errorMsg = MISS_PARAMS);
|
|
|
if (!actId || !articleId) {
|
|
|
errorMsg = INVALID_PARAMS;
|
|
|
}
|
|
|
|
|
|
if (errorMsg) {
|
|
|
return res.json({
|
...
|
...
|
@@ -172,7 +167,35 @@ const article = { |
|
|
res.json({
|
|
|
code: 200,
|
|
|
data: final_result,
|
|
|
message: GET_ARTICLE_SUCCESS
|
|
|
message: GET_SUCCESS
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 文章点赞
|
|
|
* @param req
|
|
|
* @param res
|
|
|
*/
|
|
|
like(req, res) {
|
|
|
const actId = req.body.actId;
|
|
|
const articleId = req.body.articleId;
|
|
|
|
|
|
if (!actId || !articleId) {
|
|
|
return res.json({
|
|
|
code: 400,
|
|
|
message: INVALID_PARAMS
|
|
|
});
|
|
|
}
|
|
|
|
|
|
req.ctx(ArticleModel).likeArticle(actId, articleId)
|
|
|
.then(() => {
|
|
|
req.ctx(ArticleModel).insertLikeDetail(actId, articleId)
|
|
|
.then(() => {
|
|
|
res.json({
|
|
|
code: 200,
|
|
|
message: POST_SUCCESS
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
}
|
...
|
...
|
|