Source: tree/treeQueue/treeAdd.js


// @ts-check
/**
 * @import {treeAction} from './../../types.js'
 */
import { errorLoggerUpdate } from '../../utils/requestLogger.js'
import { addFilterAction } from './treeAdd.filterActions.js'
import { addListMemberAction, addListVisibilityAction, addListEntryAction } from './treeAdd.listActions.js'
import { addFunctionAction, addFunctionVAction } from './treeAdd.functionActions.js'
import { addFamilyAction, addFamilySyncAction } from './treeAdd.familyActions.js'
import { addMemberAction, addPersonFilterAction } from './treeAdd.memberAction.js'

/**
 * Handles various actions related to adding objects to a tree structure, such as filters, memberships, visibility, 
 * and other hierarchical updates. This function processes different types of actions and performs corresponding 
 * database operations and updates.
 *
 * @async
 * @function addAction

 * @param {treeAction} action - The action object containing details about the operation to be performed.
 * @throws {Error} Throws an error if any database operation or action processing fails.
 */
export const addAction = async (action) => {
    try {
        if (['visible', 'changeable', 'include', 'exclude', 'intersect'].includes(action.Type)) {
            await addFilterAction(action)
        } else if (action.Type === 'listMember') {
            await addListMemberAction(action)
        } else if (action.Type === 'listVisibility') {
            await addListVisibilityAction(action)
        } else if (action.Type === 'list') {
            await addListEntryAction(action)
        } else if (action.Type === 'function') {
            await addFunctionAction(action)
        } else if (action.Type === 'functionV') {
            await addFunctionVAction(action)
        } else if (action.Type === 'family' || action.Type === 'familyB') {
            await addFamilyAction(action)
        } else if (action.Type === 'familySync') {
            await addFamilySyncAction(action)
        } else if (action.Type === 'personFilter') {
            await addPersonFilterAction(action)
        } else {
            // Tree-structural membership actions: group, person, extern, job, guest, ggroup, eventJob
            await addMemberAction(action)
        }
    }
    catch (e) {
        errorLoggerUpdate(e || new Error('treeAdd: Unknown error occurred'))
    }
}