message.js
1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import messageModel from '../../models/message';
module.exports = {
async list(ctx, next) {
console.log(
'----------------获取留言列表 admin_api/message/list-----------------------'
);
let { keyword, pageindex = 1, pagesize = 10 } = ctx.request.query;
let reg = new RegExp(keyword, 'i');
let conditions = {
$or: [{ nickname: { $regex: reg } }, { content: { $regex: reg } }],
};
// 排序参数
let sortParams = {
createTime: -1,
};
let options = {
limit: pagesize * 1,
skip: (pageindex - 1) * pagesize,
sort: sortParams,
};
try {
let data = await ctx.find(messageModel, conditions, null, options);
return ctx.send(data);
} catch (e) {
console.log(e);
return ctx.sendError(e);
}
},
async del(ctx, next) {
console.log(
'----------------删除留言 admin_api/message/del-----------------------'
);
let id = ctx.request.query.id;
try {
ctx.remove(messageModel, { _id: id });
ctx.send();
} catch (e) {
ctx.sendError(e);
}
},
async delReply(ctx, next) {
console.log(
'----------------删除回复 admin_api/message/delReply-----------------------'
);
let { _id } = ctx.request.body;
let options = {
$pull: { replyList: { _id } },
};
try {
let data = await ctx.update(messageModel, { _id }, options);
ctx.send();
} catch (e) {
ctx.sendError(e);
}
},
};