|
|
@@ -6,7 +6,7 @@ const express = require('express');
|
|
|
|
|
|
const router = express.Router();
|
|
|
|
|
|
-const { body } = require('express-validator/check');
|
|
|
+const { body, query } = require('express-validator/check');
|
|
|
const { isEmail } = require('validator');
|
|
|
|
|
|
const ErrorV3 = require('../../models/vo/error-apiv3');
|
|
|
@@ -118,6 +118,52 @@ module.exports = (crowi) => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ const statusNo = {
|
|
|
+ registered: User.STATUS_REGISTERED,
|
|
|
+ active: User.STATUS_ACTIVE,
|
|
|
+ suspended: User.STATUS_SUSPENDED,
|
|
|
+ invited: User.STATUS_INVITED,
|
|
|
+ };
|
|
|
+
|
|
|
+ validator.statusList = [
|
|
|
+ body('statusList').custom((value) => {
|
|
|
+ const error = [];
|
|
|
+ value.forEach((status) => {
|
|
|
+ if (!Object.keys(statusNo)) {
|
|
|
+ error.push(status);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return (error.length === 0);
|
|
|
+ }),
|
|
|
+
|
|
|
+ query('page').isInt({ min: 1 }),
|
|
|
+ ];
|
|
|
+
|
|
|
+ router.get('/search-user-status/', validator.statusList, ApiV3FormValidator, async(req, res) => {
|
|
|
+
|
|
|
+ const page = parseInt(req.query.page) || 1;
|
|
|
+ const { statusList } = req.body;
|
|
|
+
|
|
|
+ const statusNoList = statusList.map(element => statusNo[element]);
|
|
|
+
|
|
|
+ try {
|
|
|
+ const paginateResult = await User.paginate(
|
|
|
+ { status: { $in: statusNoList } },
|
|
|
+ {
|
|
|
+ sort: { status: 1, username: 1, createdAt: 1 },
|
|
|
+ page,
|
|
|
+ limit: PAGE_ITEMS,
|
|
|
+ },
|
|
|
+ );
|
|
|
+ return res.apiv3({ paginateResult });
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ const msg = 'Error occurred in fetching user group list';
|
|
|
+ logger.error('Error', err);
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'user-group-list-fetch-failed'), 500);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
validator.inviteEmail = [
|
|
|
// isEmail prevents line breaks, so use isString
|
|
|
body('shapedEmailList').custom((value) => {
|
|
|
@@ -424,50 +470,6 @@ module.exports = (crowi) => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- const statusNo = {
|
|
|
- registered: User.STATUS_REGISTERED,
|
|
|
- active: User.STATUS_ACTIVE,
|
|
|
- suspended: User.STATUS_SUSPENDED,
|
|
|
- invited: User.STATUS_INVITED,
|
|
|
- };
|
|
|
-
|
|
|
- validator.statusList = [
|
|
|
- body('statusList').custom((value) => {
|
|
|
- const error = [];
|
|
|
- value.forEach((status) => {
|
|
|
- if (!Object.keys(statusNo)) {
|
|
|
- error.push(status);
|
|
|
- }
|
|
|
- });
|
|
|
- return (error.length === 0);
|
|
|
- }),
|
|
|
- ];
|
|
|
-
|
|
|
- router.get('/selected-status-users/', validator.statusList, ApiV3FormValidator, async(req, res) => {
|
|
|
-
|
|
|
- const page = parseInt(req.query.page) || 1;
|
|
|
- const { statusList } = req.body;
|
|
|
-
|
|
|
- const statusNoList = statusList.map(element => statusNo[element]);
|
|
|
-
|
|
|
- try {
|
|
|
- const paginateResult = await User.paginate(
|
|
|
- { status: { $in: statusNoList } },
|
|
|
- {
|
|
|
- sort: { status: 1, username: 1, createdAt: 1 },
|
|
|
- page,
|
|
|
- limit: PAGE_ITEMS,
|
|
|
- },
|
|
|
- );
|
|
|
- return res.apiv3({ paginateResult });
|
|
|
- }
|
|
|
- catch (err) {
|
|
|
- const msg = 'Error occurred in fetching user group list';
|
|
|
- logger.error('Error', err);
|
|
|
- return res.apiv3Err(new ErrorV3(msg, 'user-group-list-fetch-failed'), 500);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
/**
|
|
|
* @swagger
|
|
|
*
|