diff --git a/src/flags.js b/src/flags.js index 00bce1d9bd..ecffff76ff 100644 --- a/src/flags.js +++ b/src/flags.js @@ -134,6 +134,14 @@ Flags.getCount = async function ({ uid, filters, query }) { return flagIds.length; }; +function applyFlagFilters(type, sets, orSets, filters, uid) { + if (Flags._filters.hasOwnProperty(type)) { + Flags._filters[type](sets, orSets, filters[type], uid); + } else { + winston.warn(`[flags/list] No flag filter type found: ${type}`); + } +} + Flags.getFlagIdsWithFilters = async function ({ filters, uid, query }) { let sets = []; const orSets = []; @@ -143,11 +151,7 @@ Flags.getFlagIdsWithFilters = async function ({ filters, uid, query }) { filters.perPage = filters.hasOwnProperty('perPage') ? Math.abs(parseInt(filters.perPage, 10) || 20) : 20; for (const type of Object.keys(filters)) { - if (Flags._filters.hasOwnProperty(type)) { - Flags._filters[type](sets, orSets, filters[type], uid); - } else { - winston.warn(`[flags/list] No flag filter type found: ${type}`); - } + applyFlagFilters(type, sets, orSets, filters, uid); } sets = (sets.length || orSets.length) ? sets : ['flags:datetime']; // No filter default