...
|
...
|
@@ -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({
|
...
|
...
|
@@ -154,7 +149,7 @@ const article = { |
|
|
res.json({
|
|
|
code: 200,
|
|
|
data: ret,
|
|
|
message: GET_ARTICLE_SUCCESS
|
|
|
message: GET_SUCCESS
|
|
|
});
|
|
|
});
|
|
|
},
|
...
|
...
|
@@ -171,7 +166,7 @@ const article = { |
|
|
if (!actId || !articleId) {
|
|
|
return res.json({
|
|
|
code: 400,
|
|
|
message: MISS_PARAMS
|
|
|
message: INVALID_PARAMS
|
|
|
});
|
|
|
}
|
|
|
|
...
|
...
|
@@ -181,7 +176,7 @@ const article = { |
|
|
.then(() => {
|
|
|
res.json({
|
|
|
code: 200,
|
|
|
message: '点赞成功'
|
|
|
message: POST_SUCCESS
|
|
|
});
|
|
|
});
|
|
|
});
|
...
|
...
|
|