-
Notifications
You must be signed in to change notification settings - Fork 2
/
categoryService.js
48 lines (46 loc) · 1.04 KB
/
categoryService.js
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
/**
* Query tag list
*
* @param {Object} res
* @param {Object} hexo
*/
function queryCategoryList(res, hexo) {
const categories = hexo.model('Category');
const total = categories.count();
res.ok({
total: total,
data: categories
.map((c) => {
return {
_id: c._id,
name: c.name,
};
})
.sort((a, b) => {
const x = a.name.toLowerCase();
const y = b.name.toLowerCase();
if (x < y) {
return -1;
}
if (x > y) {
return 1;
}
return 0;
}),
});
}
/**
* Provider tag operation service
*
* @param {*} req
* @param {*} res
* @param {*} hexo
*/
function categoryService(req, res, hexo) {
if (req.method === 'GET') {
queryCategoryList(res, hexo);
} else {
res.badRequest('Not support this method');
}
}
module.exports = categoryService;