diff options
Diffstat (limited to 'app/assets/javascripts/vue_shared/components/user_deletion_obstacles/utils.js')
-rw-r--r-- | app/assets/javascripts/vue_shared/components/user_deletion_obstacles/utils.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/assets/javascripts/vue_shared/components/user_deletion_obstacles/utils.js b/app/assets/javascripts/vue_shared/components/user_deletion_obstacles/utils.js new file mode 100644 index 00000000000..502302a1ef2 --- /dev/null +++ b/app/assets/javascripts/vue_shared/components/user_deletion_obstacles/utils.js @@ -0,0 +1,19 @@ +import { OBSTACLE_TYPES } from './constants'; + +const addTypeToObstacles = (obstacles, type) => { + if (!obstacles) return []; + + return obstacles?.map((obstacle) => ({ type, ...obstacle })); +}; + +// For use with user objects formatted via internal REST API. +// If the removal/deletion of a user could cause critical +// problems, return a single array containing all affected +// associations including their type. +export const parseUserDeletionObstacles = (user) => { + if (!user) return []; + + return Object.keys(OBSTACLE_TYPES).flatMap((type) => { + return addTypeToObstacles(user[type], OBSTACLE_TYPES[type]); + }); +}; |