Converting ODATA url to sequelize selector

Viewed 45

My node.js application (getting requests with express, stores data with sequelize and proxies to a sap odata api) gets odata requests. As sequelize can't handle the odata scheme, I have to create a parser by myself.

For example the odata URI could be: $expand=Car($expand=Brand($expand=Type)),Person($expand=Gender)&$filter=id eq 1 As you can see, there are some nested expands.

The parsed data should look like that:

{
    include: [
        {
           association: "Car",
           include: [
              {
                  association: "Brand"
                  include: [
                     {
                        association: "Type"
                     }
              }
           ]

        },
        {
            association: "Person",
            include: [
                {
                    association: "Gender"
                }
            ]
        }
    ],
    where: {
        id: 1
    }
}

I already had a look at some npm packages, but none of them does support the expand of entities/entitysets.

Any idea how to recursively convert that odata scheme to the sequelize selectors?

I'm pretty sure that would be interesting for many api developers using node.

0 Answers
Related