|
|
@@ -27,14 +27,6 @@ schema.plugin(mongoosePaginate);
|
|
|
*/
|
|
|
class PageTagRelation {
|
|
|
|
|
|
- static set crowi(crowi) {
|
|
|
- this._crowi = crowi;
|
|
|
- }
|
|
|
-
|
|
|
- static get crowi() {
|
|
|
- return this._crowi;
|
|
|
- }
|
|
|
-
|
|
|
static init() {
|
|
|
this.removeAllInvalidRelations();
|
|
|
}
|
|
|
@@ -59,82 +51,9 @@ class PageTagRelation {
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * find all tag related to the page
|
|
|
- *
|
|
|
- * @static
|
|
|
- * @param {ObjectId} pageId
|
|
|
- * @returns {Promise<ObjectId[]>}
|
|
|
- * @memberof PageTagRelation
|
|
|
- */
|
|
|
- static findAllTagIdForPage(pageId) {
|
|
|
- return this
|
|
|
- .find({
|
|
|
- relatedPage: pageId
|
|
|
- })
|
|
|
- .select('-_id relatedTag');
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * find all page related to the tag
|
|
|
- *
|
|
|
- * @static
|
|
|
- * @param {tag} tag
|
|
|
- * @returns {Promise<ObjectId[]>}
|
|
|
- * @memberof PageTagRelation
|
|
|
- */
|
|
|
- static findAllPageIdForTag(tag) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- this.find({
|
|
|
- relatedTag: tag._id
|
|
|
- }, function(err, relations) {
|
|
|
- if (err) {
|
|
|
- reject(err);
|
|
|
- }
|
|
|
- resolve(relations.map(rel => rel.relatedPage));
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * create a page tag relation
|
|
|
- *
|
|
|
- * @static
|
|
|
- * @param {Page} page
|
|
|
- * @param {Tag} tag
|
|
|
- * @returns {Promise<PageTagRelation>} created relation
|
|
|
- * @memberof PageTagRelation
|
|
|
- */
|
|
|
- static createRelation(page, tag) {
|
|
|
- return this.create({
|
|
|
- relatedPage: page._id,
|
|
|
- relatedTag: tag._id
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * remove relation by id
|
|
|
- *
|
|
|
- * @static
|
|
|
- * @param {ObjectId} id
|
|
|
- * @returns {Promise<PageTagRelation>}
|
|
|
- * @memberof PageTagRelation
|
|
|
- */
|
|
|
- static removeByEachId(pageId, tagId) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- this.remove({relatedPage: pageId, relatedTag: tagId}, function(err, removedData) {
|
|
|
- if (err) {
|
|
|
- reject(err);
|
|
|
- }
|
|
|
- resolve(removedData);
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
-module.exports = function(crowi) {
|
|
|
- PageTagRelation.crowi = crowi;
|
|
|
+module.exports = function() {
|
|
|
schema.loadClass(PageTagRelation);
|
|
|
const model = mongoose.model('PageTagRelation', schema);
|
|
|
model.init();
|