Js circular Filter json object array

1. First of all, there is a list of objects with the following structure

objectList=[
    {
        objectId:"object1",   // Id
        objectName: "1",  // 
        parentId:"parent1",  // Id
        childId: "child1"    // Id
    },
    {
        objectId:"object2",
        objectName: "2", 
        parentId:"parent1", 
        childId: "child1"   
    },
    {
        objectId:"object3",
        objectName: "3",
        parentId:"parent1",
        childId: "child2"
    },
    {
        objectId:"object4",
        objectName: "4",
        parentId:"parent1",
        childId: "child3"
    }]
The purpose of

is to give a childId, to return all eligible objects in the objectList table.

this is not only as simple as filter, but also has an authList array to restrict:
the restriction rule is as follows (suppose the object whose childId="child1" is to be fetched from objectList and the value of type contains" seach""):
1. If the authList array is empty, ignore type, and directly get the result on Filter objectList,.
the result should be two objects, object1 and object2.

2. If the authList is not empty and the array structure is as follows, then you should do something on top of step 1:

authList=[
        {
            objectId:"object1",
            childId: "child1",
            type:"add,delete"
        },
        {
            objectId:"object3",
            childId: "child1",
            type:"seach"
        },
 ]

then the judgment should be based on the type field of the authList table at this time. The result should be object2 and object3. (it is not eligible that there is no seach, in the type of the first record of authList; the type of the second record has search, so the object3 is also added to the result);

could you tell me how to realize the above functions gracefully? I tried to write it for a while, and I felt that the code was quite complicated and made myself dizzy for a while. Ask the great god for advice.

Apr.28,2021

the search in authList in the data you gave is misspelled.


~~

 var childId = 'child1';
    var type = 'search';
    let _list = [];
    objectList.forEach(object => {
        if(object.childId == childId){
            let flag = false;
            authList.forEach(auth => {
                if(auth.objectId==object.objectId){
                    flag = true;
                    if(auth.type.indexOf(type)>-1){
                        _list.push(object);
                    }
                }
            })
            if(!flag){
                _list.push(object);
            }
        }else{
            authList.forEach(auth => {
                if(auth.objectId==object.objectId && auth.type.indexOf(type)>-1){
                    _list.push(object);
                }
            })
        }
        
    })
    console.log("", _list);
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3cbd3-4d9d7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3cbd3-4d9d7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?