|
|
@@ -669,41 +669,27 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- pageSchema.statics.findListByCreator = function(user, option, currentUser) {
|
|
|
- var Page = this;
|
|
|
- var User = crowi.model('User');
|
|
|
- var limit = option.limit || 50;
|
|
|
- var offset = option.offset || 0;
|
|
|
- var conditions = setPageListConditions(user);
|
|
|
-
|
|
|
- return new Promise(function(resolve, reject) {
|
|
|
- Page
|
|
|
- .find(conditions)
|
|
|
- .sort({createdAt: -1})
|
|
|
- .skip(offset)
|
|
|
- .limit(limit)
|
|
|
- .populate('revision')
|
|
|
- .exec()
|
|
|
- .then(function(pages) {
|
|
|
- return Page.populate(pages, {path: 'lastUpdateUser', model: 'User', select: User.USER_PUBLIC_FIELDS}).then(function(pagesData){
|
|
|
- let countFetcher;
|
|
|
- countFetcher = Page.countListByCreator(user,option,currentUser);
|
|
|
- countFetcher.then(function(count){
|
|
|
- pagesArray = [
|
|
|
- {totalCount: count}
|
|
|
- ];
|
|
|
- pagesArray.push(pagesData);
|
|
|
- resolve(pagesArray);
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
+ pageSchema.statics.findListByCreator = async function(user, option, currentUser) {
|
|
|
+ let Page = this;
|
|
|
+ let User = crowi.model('User');
|
|
|
+ let limit = option.limit || 50;
|
|
|
+ let offset = option.offset || 0;
|
|
|
+ let conditions = setPageListConditions(user);
|
|
|
+
|
|
|
+ let pages = await Page.find(conditions).sort({createdAt: -1}).skip(offset).limit(limit).populate('revision').exec();
|
|
|
+ let PagesList = await Page.populate(pages, {path: 'lastUpdateUser', model: 'User', select: User.USER_PUBLIC_FIELDS});
|
|
|
+ let totalCount = await Page.countListByCreator(user);
|
|
|
+ let PagesArray = [
|
|
|
+ {totalCount: totalCount}
|
|
|
+ ];
|
|
|
+ PagesArray.push(PagesList);
|
|
|
+ return PagesArray;
|
|
|
};
|
|
|
function setPageListConditions(user) {
|
|
|
const conditions = {
|
|
|
creator: user._id,
|
|
|
redirectTo: null,
|
|
|
- $and : [
|
|
|
+ $and: [
|
|
|
{$or: [
|
|
|
{status: null},
|
|
|
{status: STATUS_PUBLISHED},
|
|
|
@@ -717,10 +703,9 @@ module.exports = function(crowi) {
|
|
|
return conditions;
|
|
|
}
|
|
|
|
|
|
- pageSchema.statics.countListByCreator = function(user, option, currentUser) {
|
|
|
- var Page = this;
|
|
|
- var User = crowi.model('User');
|
|
|
- var conditions = setPageListConditions(user);
|
|
|
+ pageSchema.statics.countListByCreator = function(user) {
|
|
|
+ let Page = this;
|
|
|
+ let conditions = setPageListConditions(user);
|
|
|
|
|
|
return Page.find(conditions).count();
|
|
|
};
|