const {
  get,
  includes,
  castArray,
  compact,
} = require('lodash')

function filterActiveAdvisers ({ advisers = [], includeAdviser }) {
  let adviserIds = compact(castArray(includeAdviser))
  return advisers.filter(adviser => {
    // This returns all active users plus the include advisor (whether they are active or not)
    return (
      get(adviser, 'is_active', true) ||
      includes(adviserIds, adviser.id)
    )
  })
}
module.exports = {
  filterActiveAdvisers,
}

const { get, includes } = require('lodash')

function filterActiveAdvisers ({ advisers = [], includeAdviser = [] }) {
  includeAdviser = [...includeAdviser]
  return advisers.filter(adviser => {
    // This returns all active users plus the include advisor (whether they are active or not)
    return (
      get(adviser, 'is_active', true) ||
      includes(includeAdviser, adviser.id)
    )
  })
}
module.exports = {
  filterActiveAdvisers,
}

--- 
+++ 
@@ -1,12 +1,17 @@
-const { get, includes } = require('lodash')
+const {
+  get,
+  includes,
+  castArray,
+  compact,
+} = require('lodash')
 
-function filterActiveAdvisers ({ advisers = [], includeAdviser = [] }) {
-  includeAdviser = [...includeAdviser]
+function filterActiveAdvisers ({ advisers = [], includeAdviser }) {
+  let adviserIds = compact(castArray(includeAdviser))
   return advisers.filter(adviser => {
     // This returns all active users plus the include advisor (whether they are active or not)
     return (
       get(adviser, 'is_active', true) ||
-      includes(includeAdviser, adviser.id)
+      includes(adviserIds, adviser.id)
     )
   })
 }
Fix for when a user edits a Client Relationship Manager
