MCPcopy
hub / github.com/lfb/nodejs-koa-blog / targetComment

Method targetComment

app/dao/comment.js:202–283  ·  view source on GitHub ↗
(params = {})

Source from the content-addressed store, hash-verified

200
201 // 关联目标下的评论
202 static async targetComment(params = {}) {
203 try {
204 const {
205 article_id = 0,
206 user_id = 0,
207 is_replay = 0,
208 is_article = 0,
209 is_user = 0,
210 page_size = 10,
211 status = -1,
212 page = 1,
213 desc = 'created_at'
214 } = params;
215
216 // if (!article_id) {
217 // throw new global.errs.NotFound('必须传入article id');
218 // }
219
220 const finner = {
221 status: 1,
222 deleted_at: null
223 }
224
225 if (user_id) {
226 finner.user_id = user_id
227 }
228
229 if (article_id) {
230 finner.article_id = article_id
231 }
232
233 if (status === -1) {
234 delete finner.status
235 }
236
237 const comment = await Comment.findAndCountAll({
238 where: finner,
239 // 每页10条
240 limit: page_size,
241 offset: (page - 1) * page_size,
242 order: [
243 [desc, 'DESC']
244 ],
245 attributes: {
246 exclude: ['updated_at']
247 },
248 })
249
250 let rows = comment.rows
251 // 查询评论
252 if (parseInt(is_replay, 10) === 1) {
253 rows = await CommentDao._handleReply(rows)
254 }
255
256 // 查询文章
257 if (parseInt(is_article, 10) === 1) {
258 rows = await CommentDao._handleArticle(rows)
259 }

Callers 2

comment.jsFile · 0.80
article.jsFile · 0.80

Calls 3

_handleReplyMethod · 0.80
_handleArticleMethod · 0.45
_handleUserMethod · 0.45

Tested by

no test coverage detected