@@ -272,8 +272,12 @@ class UserGroupRelation {
});
}
- static async findWithUserByGroupIds(groupIds = null) {
- return this.find(Array.isArray(groupIds) ? { relatedGroup: { $in: groupIds } } : {})
+ static async findWithUserByGroupIds(groupIds) {
+ if (!Array.isArray(groupIds)) {
+ throw Error('groupIds must be an array');
+ }
+
+ return this.find({ relatedGroup: { $in: groupIds } })
.populate('relatedUser');
@@ -79,8 +79,8 @@ class UserGroup {
static async findChildUserGroupsByParentIds(parentIds, includeGrandChildren = false) {
- if (parentIds == null) {
- throw Error('parentIds must not be null.');
+ if (!Array.isArray(parentIds)) {
+ throw Error('parentIds must be an array.');
const childUserGroups = await this.find({ parent: { $in: parentIds } });
@@ -25,7 +25,7 @@ module.exports = (crowi) => {
const { UserGroupRelation } = crowi.models;
validator.list = [
- query('groupIds', 'groupIds must be an array').optional().isArray(),
+ query('groupIds', 'groupIds is required and must be an array').isArray(),
query('childGroupIds', 'childGroupIds must be an array').optional().isArray(),
];
@@ -66,7 +66,7 @@ module.exports = (crowi) => {
* type: object
* description: a result of `UserGroup.find`
*/
- router.get('/', loginRequiredStrictly, adminRequired, async(req, res) => {
+ router.get('/', loginRequiredStrictly, adminRequired, async(req, res) => { // TODO 85062: userGroups with no parent
const { query } = req;
// TODO 85062: improve sort