WESEEK Kaito 6 лет назад
Родитель
Сommit
518a99ebb0
2 измененных файлов с 36 добавлено и 1 удалено
  1. 26 0
      src/server/models/external-account.js
  2. 10 1
      src/server/routes/admin.js

+ 26 - 0
src/server/models/external-account.js

@@ -149,6 +149,32 @@ class ExternalAccount {
     return this.create({ providerType, accountId, user: user._id });
   }
 
+  /**
+   * find all entities with pagination
+   *
+   * @see https://github.com/edwardhotchkiss/mongoose-paginate
+   *
+   * @static
+   * @param {any} opts mongoose-paginate options object
+   * @returns {Promise<any>} mongoose-paginate result object
+   * @memberof ExternalAccount
+   */
+  static findAllWithPagination(opts) {
+    const query = {};
+    const options = Object.assign({ populate: 'user' }, opts);
+    if (options.sort == null) {
+      options.sort = { accountId: 1, createdAt: 1 };
+    }
+    if (options.limit == null) {
+      options.limit = ExternalAccount.DEFAULT_LIMIT;
+    }
+
+    return this.paginate(query, options)
+      .catch((err) => {
+        debug('Error on pagination:', err);
+      });
+  }
+
 }
 
 module.exports = function(crowi) {

+ 10 - 1
src/server/routes/admin.js

@@ -486,7 +486,16 @@ module.exports = function(crowi, app) {
 
   actions.externalAccount = {};
   actions.externalAccount.index = function(req, res) {
-    return res.render('admin/users/external-accounts');
+    const page = parseInt(req.query.page) || 1;
+
+    ExternalAccount.findALLWithPagination({ page })
+      .then((result) => {
+        const pager = createPager(result.total, result.limit, result.page, MAX_PAGE_LIST);
+        return res.render('admin/users/external-accounts', {
+          accounts: result.docs,
+          pager,
+        });
+      });
   };
 
   actions.externalAccount.remove = async function(req, res) {