|
|
@@ -38,32 +38,18 @@ class PageTagRelation {
|
|
|
}
|
|
|
|
|
|
static async createTagListWithCount(opt) {
|
|
|
- const Tag = PageTagRelation.crowi.model('Tag');
|
|
|
-
|
|
|
- // get objects contain id and count
|
|
|
const list = await this.aggregate()
|
|
|
.group({ _id: '$relatedTag', count: { $sum: 1 } })
|
|
|
.sort(opt.sortOpt)
|
|
|
.skip(opt.offset)
|
|
|
.limit(opt.limit);
|
|
|
|
|
|
- // get tag document for add name data to the list
|
|
|
- const tags = await Tag.find({ _id: { $in: list.map((elm) => { return elm._id }) } });
|
|
|
-
|
|
|
- // add name data
|
|
|
- const result = list.map((elm) => {
|
|
|
- const tag = tags.find((tag) => { return (tag.id === String(elm._id)) });
|
|
|
- elm.name = tag.name;
|
|
|
- return elm;
|
|
|
- });
|
|
|
-
|
|
|
- return result;
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
-module.exports = function(crowi) {
|
|
|
- PageTagRelation.crowi = crowi;
|
|
|
+module.exports = function() {
|
|
|
schema.loadClass(PageTagRelation);
|
|
|
const model = mongoose.model('PageTagRelation', schema);
|
|
|
return model;
|