|
@@ -7,15 +7,9 @@ const _ = require('lodash'); |
|
@@ -7,15 +7,9 @@ const _ = require('lodash'); |
7
|
const camelcase = require('camelcase');
|
7
|
const camelcase = require('camelcase');
|
8
|
const ArticleModel = require('../models/article');
|
8
|
const ArticleModel = require('../models/article');
|
9
|
|
9
|
|
10
|
-const ADD_ARTICLE_SUCCESS = '文章发表成功';
|
|
|
11
|
-const GET_ARTICLES_SUCCESS = '获取文章列表成功';
|
|
|
12
|
-const GET_ARTICLE_SUCCESS = '获取文章详情成功';
|
|
|
13
|
-const INVALID_ACTIVITY_ID = '活动ID[actId]不能为空';
|
|
|
14
|
-const INVALID_IMG = '图片[imgUrl]不能为空';
|
|
|
15
|
-const INVALID_CONTENT = '内容[content]都不能为空';
|
|
|
16
|
-const MISS_PARAMS = '缺少参数';
|
|
|
17
|
-const INVALID_ORDER = '排序[order]值为asc或desc';
|
|
|
18
|
-const INVALID_ORDER_BY = '排序字段[orderBy]非法';
|
10
|
+const POST_SUCCESS = '操作成功';
|
|
|
11
|
+const GET_SUCCESS = '获取成功';
|
|
|
12
|
+const INVALID_PARAMS = '参数错误';
|
19
|
|
13
|
|
20
|
const article = {
|
14
|
const article = {
|
21
|
/**
|
15
|
/**
|
|
@@ -42,14 +36,14 @@ const article = { |
|
@@ -42,14 +36,14 @@ const article = { |
42
|
if (order !== 'asc' && order !== 'desc') {
|
36
|
if (order !== 'asc' && order !== 'desc') {
|
43
|
return res.json({
|
37
|
return res.json({
|
44
|
code: 400,
|
38
|
code: 400,
|
45
|
- message: INVALID_ORDER
|
39
|
+ message: INVALID_PARAMS
|
46
|
});
|
40
|
});
|
47
|
}
|
41
|
}
|
48
|
|
42
|
|
49
|
if (orderByFields.indexOf(orderBy) === -1) {
|
43
|
if (orderByFields.indexOf(orderBy) === -1) {
|
50
|
return res.json({
|
44
|
return res.json({
|
51
|
code: 400,
|
45
|
code: 400,
|
52
|
- message: INVALID_ORDER_BY
|
46
|
+ message: INVALID_PARAMS
|
53
|
});
|
47
|
});
|
54
|
}
|
48
|
}
|
55
|
|
49
|
|
|
@@ -81,7 +75,7 @@ const article = { |
|
@@ -81,7 +75,7 @@ const article = { |
81
|
pageSize,
|
75
|
pageSize,
|
82
|
totalCount,
|
76
|
totalCount,
|
83
|
totalPage: Math.ceil(totalCount / pageSize),
|
77
|
totalPage: Math.ceil(totalCount / pageSize),
|
84
|
- message: GET_ARTICLES_SUCCESS
|
78
|
+ message: GET_SUCCESS
|
85
|
});
|
79
|
});
|
86
|
});
|
80
|
});
|
87
|
});
|
81
|
});
|
|
@@ -99,9 +93,9 @@ const article = { |
|
@@ -99,9 +93,9 @@ const article = { |
99
|
const imgUrl = req.body.imgUrl;
|
93
|
const imgUrl = req.body.imgUrl;
|
100
|
const content = req.body.content;
|
94
|
const content = req.body.content;
|
101
|
|
95
|
|
102
|
- !imgUrl && (errorMsg = INVALID_IMG);
|
|
|
103
|
- !content && (errorMsg = INVALID_CONTENT);
|
|
|
104
|
- !actId && (errorMsg = INVALID_ACTIVITY_ID);
|
96
|
+ if (!imgUrl || !content || !actId) {
|
|
|
97
|
+ errorMsg = INVALID_PARAMS;
|
|
|
98
|
+ }
|
105
|
|
99
|
|
106
|
if (errorMsg) {
|
100
|
if (errorMsg) {
|
107
|
return res.json({
|
101
|
return res.json({
|
|
@@ -123,7 +117,7 @@ const article = { |
|
@@ -123,7 +117,7 @@ const article = { |
123
|
res.json({
|
117
|
res.json({
|
124
|
code: 200,
|
118
|
code: 200,
|
125
|
data: {id},
|
119
|
data: {id},
|
126
|
- message: ADD_ARTICLE_SUCCESS
|
120
|
+ message: POST_SUCCESS
|
127
|
});
|
121
|
});
|
128
|
});
|
122
|
});
|
129
|
});
|
123
|
});
|
|
@@ -139,8 +133,9 @@ const article = { |
|
@@ -139,8 +133,9 @@ const article = { |
139
|
const actId = req.query.actId;
|
133
|
const actId = req.query.actId;
|
140
|
const articleId = req.query.articleId;
|
134
|
const articleId = req.query.articleId;
|
141
|
|
135
|
|
142
|
- !actId && (errorMsg = MISS_PARAMS);
|
|
|
143
|
- !articleId && (errorMsg = MISS_PARAMS);
|
136
|
+ if (!actId || !articleId) {
|
|
|
137
|
+ errorMsg = INVALID_PARAMS;
|
|
|
138
|
+ }
|
144
|
|
139
|
|
145
|
if (errorMsg) {
|
140
|
if (errorMsg) {
|
146
|
return res.json({
|
141
|
return res.json({
|
|
@@ -154,7 +149,7 @@ const article = { |
|
@@ -154,7 +149,7 @@ const article = { |
154
|
res.json({
|
149
|
res.json({
|
155
|
code: 200,
|
150
|
code: 200,
|
156
|
data: ret,
|
151
|
data: ret,
|
157
|
- message: GET_ARTICLE_SUCCESS
|
152
|
+ message: GET_SUCCESS
|
158
|
});
|
153
|
});
|
159
|
});
|
154
|
});
|
160
|
},
|
155
|
},
|
|
@@ -171,7 +166,7 @@ const article = { |
|
@@ -171,7 +166,7 @@ const article = { |
171
|
if (!actId || !articleId) {
|
166
|
if (!actId || !articleId) {
|
172
|
return res.json({
|
167
|
return res.json({
|
173
|
code: 400,
|
168
|
code: 400,
|
174
|
- message: MISS_PARAMS
|
169
|
+ message: INVALID_PARAMS
|
175
|
});
|
170
|
});
|
176
|
}
|
171
|
}
|
177
|
|
172
|
|
|
@@ -181,7 +176,7 @@ const article = { |
|
@@ -181,7 +176,7 @@ const article = { |
181
|
.then(() => {
|
176
|
.then(() => {
|
182
|
res.json({
|
177
|
res.json({
|
183
|
code: 200,
|
178
|
code: 200,
|
184
|
- message: '点赞成功'
|
179
|
+ message: POST_SUCCESS
|
185
|
});
|
180
|
});
|
186
|
});
|
181
|
});
|
187
|
});
|
182
|
});
|