Shun Miyazawa 3 лет назад
Родитель
Сommit
ea0469b9f6

+ 0 - 26
packages/app/src/server/routes/apiv3/activity.ts

@@ -1,5 +1,4 @@
 import { parse, addMinutes, isValid } from 'date-fns';
-import escapeStringRegexp from 'escape-string-regexp';
 import express, { Request, Router } from 'express';
 import rateLimit from 'express-rate-limit';
 import { query } from 'express-validator';
@@ -99,30 +98,5 @@ module.exports = (crowi: Crowi): Router => {
     }
   });
 
-  router.get('/usernames', loginRequiredStrictly, adminRequired, async(req: Request, res: ApiV3Response) => {
-    const q = req.query.q as string;
-    const escapedString = escapeStringRegexp(q);
-
-    try {
-      const undeletedUsernames = await User.find({
-        status: { $ne: User.STATUS_DELETED },
-        username: new RegExp(`^${escapedString}`, 'i'),
-      }).distinct('username');
-
-      const activitySnapshotUsernames = await Activity.find({
-        $and: [
-          { 'snapshot.username': { $nin: undeletedUsernames } },
-          { 'snapshot.username': new RegExp(`^${escapedString}`, 'i') },
-        ],
-      }).distinct('snapshot.username');
-
-      return res.apiv3({ usernames: [...undeletedUsernames, ...activitySnapshotUsernames] });
-    }
-    catch (err) {
-      logger.error('failed to get usernames', err);
-      return res.apiv3Err(err);
-    }
-  });
-
   return router;
 };

+ 28 - 0
packages/app/src/server/routes/apiv3/users.js

@@ -1,3 +1,6 @@
+import escapeStringRegexp from 'escape-string-regexp';
+
+import Activity from '~/server/models/activity';
 import loggerFactory from '~/utils/logger';
 
 import { apiV3FormValidator } from '../../middlewares/apiv3-form-validator';
@@ -932,5 +935,30 @@ module.exports = (crowi) => {
     return res.apiv3(data);
   });
 
+  router.get('/usernames', loginRequiredStrictly, adminRequired, async(req, res) => {
+    const q = req.query.q;
+    const escapedString = escapeStringRegexp(q);
+
+    try {
+      const undeletedUsernames = await User.find({
+        status: { $ne: User.STATUS_DELETED },
+        username: new RegExp(`^${escapedString}`, 'i'),
+      }).distinct('username');
+
+      const activitySnapshotUsernames = await Activity.find({
+        $and: [
+          { 'snapshot.username': { $nin: undeletedUsernames } },
+          { 'snapshot.username': new RegExp(`^${escapedString}`, 'i') },
+        ],
+      }).distinct('snapshot.username');
+
+      return res.apiv3({ usernames: [...undeletedUsernames, ...activitySnapshotUsernames] });
+    }
+    catch (err) {
+      logger.error('failed to get usernames', err);
+      return res.apiv3Err(err);
+    }
+  });
+
   return router;
 };