Skip to content

Can't seem to manipulate data inside an 'in' statement #134

@fridaystreet

Description

@fridaystreet

Maybe I'm going about this the wrong way, but I'm trying to essentially do a reverse comaprison. I have a data object with tags and I want to know if all the tags entered into the rule exist in the data

So I'm mapping the data out to it's singular value from the object and trying to compare all values passed by the user to be compared to make sure all the tags exist. It doesn't matter if the data has more tags, but as long as it has all the tags in the query

So I first filter out the data tags to leave only the tags the user is looking for, then my thought was, do an 'all' on the output of the filter to see if the output of the filter contiaisn all the tags.

Trying to get the follwing to work, but it just returns false

const data =  {
  tags: [
    {a: 1},
    {a: 2},
    {a: 3},
    {a: 4},
    {a: 5}
  ]
}

const  findTags = [1,2,3]

const rules = {

  all: [
    findTags,
    {
      in: [
        {var: ""},
        {
          map: [
            {
              filter: [
                { var: 'tags' },
                { in: [{ var: "a" }, findTags] }
              ]
            },
            { var: "a"}
          ]
        }
      ]
    }
  ]
}

console.log(jsonlogic.apply(rules, data))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions