|
@@ -140,24 +140,36 @@ module.exports = (crowi) => {
|
|
|
|
|
|
|
|
router.get('/search-user-status/', validator.statusList, ApiV3FormValidator, async(req, res) => {
|
|
router.get('/search-user-status/', validator.statusList, ApiV3FormValidator, async(req, res) => {
|
|
|
|
|
|
|
|
- // status
|
|
|
|
|
const page = parseInt(req.query.page) || 1;
|
|
const page = parseInt(req.query.page) || 1;
|
|
|
|
|
+ // status
|
|
|
const { statusList } = req.body;
|
|
const { statusList } = req.body;
|
|
|
const statusNoList = statusList.map(element => statusNo[element]);
|
|
const statusNoList = statusList.map(element => statusNo[element]);
|
|
|
// Search from input
|
|
// Search from input
|
|
|
- const inputWord = req.body.inputWord || 1;
|
|
|
|
|
|
|
+ const inputWord = req.body.inputWord || '';
|
|
|
const searchWord = new RegExp(`${inputWord}`);
|
|
const searchWord = new RegExp(`${inputWord}`);
|
|
|
|
|
+ const orColumns = ['name', 'username', 'email'];
|
|
|
|
|
+ const orOutput = {};
|
|
|
|
|
+ orColumns.forEach((element) => {
|
|
|
|
|
+ orOutput[element] = { $in: searchWord };
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // Sort
|
|
|
|
|
+ const { descColumns } = req.body;
|
|
|
|
|
+ const sortOutput = {};
|
|
|
|
|
+ descColumns.forEach((element) => {
|
|
|
|
|
+ sortOutput[element] = -1;
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
const paginateResult = await User.paginate(
|
|
const paginateResult = await User.paginate(
|
|
|
{
|
|
{
|
|
|
$and: [
|
|
$and: [
|
|
|
{ status: { $in: statusNoList } },
|
|
{ status: { $in: statusNoList } },
|
|
|
- { $or: [{ name: { $in: searchWord } }, { username: { $in: searchWord } }, { email: { $in: searchWord } }] },
|
|
|
|
|
|
|
+ { $or: [orOutput] },
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- sort: { status: 1, username: 1, createdAt: 1 },
|
|
|
|
|
|
|
+ sort: sortOutput,
|
|
|
page,
|
|
page,
|
|
|
limit: PAGE_ITEMS,
|
|
limit: PAGE_ITEMS,
|
|
|
},
|
|
},
|