|
|
@@ -42,7 +42,7 @@ module.exports = (crowi) => {
|
|
|
} = crowi.models;
|
|
|
|
|
|
validator.listChildren = [
|
|
|
- query('parentIdsJoinedByComma', 'parentIds must be an string').optional().isString(),
|
|
|
+ query('parentIds', 'parentIds must be an array').optional().isArray(),
|
|
|
query('includeGrandChildren', 'parentIds must be boolean').optional().isBoolean(),
|
|
|
];
|
|
|
|
|
|
@@ -93,22 +93,18 @@ module.exports = (crowi) => {
|
|
|
// TODO 85062: improve sort
|
|
|
router.get('/children', loginRequiredStrictly, adminRequired, validator.listChildren, async(req, res) => {
|
|
|
try {
|
|
|
- const { parentIdsJoinedByComma, includeGrandChildren = false } = req.query;
|
|
|
+ const { parentIds, includeGrandChildren = false } = req.query;
|
|
|
|
|
|
- let parentIdList = [];
|
|
|
- if (parentIdsJoinedByComma != null && parentIdsJoinedByComma !== '') { // null check & trim empty string
|
|
|
- parentIdList = parentIdsJoinedByComma.split(',');
|
|
|
+ if (parentIds == null || parentIds.length < 0) {
|
|
|
+ return res.apiv3Err(new ErrorV3('parentId is required', 'child-user-group-list-fetch-failed'));
|
|
|
}
|
|
|
|
|
|
- let childUserGroups = [];
|
|
|
- let grandChildUserGroups = [];
|
|
|
- if (parentIdList.length > 0) {
|
|
|
- const userGroupsResult = await UserGroup.findChildUserGroupsByParentIds(parentIdList, includeGrandChildren);
|
|
|
- childUserGroups = userGroupsResult.childUserGroups;
|
|
|
- grandChildUserGroups = userGroupsResult.grandChildUserGroups;
|
|
|
- }
|
|
|
+ const userGroupsResult = await UserGroup.findChildUserGroupsByParentIds(parentIds, includeGrandChildren);
|
|
|
|
|
|
- return res.apiv3({ childUserGroups, grandChildUserGroups });
|
|
|
+ return res.apiv3({
|
|
|
+ childUserGroups: userGroupsResult.childUserGroups,
|
|
|
+ grandChildUserGroups: userGroupsResult.grandChildUserGroups,
|
|
|
+ });
|
|
|
}
|
|
|
catch (err) {
|
|
|
const msg = 'Error occurred in fetching child user group list';
|