qmacro / qmacro.github.io

MIT License
4 stars 4 forks source link

Turning an OData expand into a cds.ql CQL query with a projection function in CAP | DJ Adams #68

Open utterances-bot opened 4 months ago

utterances-bot commented 4 months ago

Turning an OData expand into a cds.ql CQL query with a projection function in CAP | DJ Adams

Turning an OData expand into a cds.ql CQL query with a projection function in CAP 12 Jul 2024 | 5 min read If, while serving a call to your...

https://qmacro.org/blog/posts/2024/07/12/turning-an-odata-expand-into-a-cds.ql-cql-query-with-a-projection-function-in-cap/

Chemacas commented 4 months ago

Hi DJ, this is the bit I wanted to double check with you. Using query API to do the $expand together with programmatic alias. Reason behind that is aliasing Standard and Custom APIs so a common naming is used

    //Using CQN format to allow translations using obdmap for property names               
    const obdelivery = await obdapi.send({
        query: SELECT.one.from(xBASFxOM_GET_DELIVERY, (delHeader) => {
            delHeader({ ref: ['delivery_number'], as: obdmap.get('delivery_number') }),
                delHeader({ ref: ['shipping_condition'], as: obdmap.get('shipping_condition') }),
                delHeader({ ref: ['delivery_date'], as: obdmap.get('delivery_date') }),
                delHeader({ ref: ['goodsissue_date'], as: obdmap.get('goodsissue_date') }),
                delHeader({ ref: ['delivery_actgi'], as: obdmap.get('delivery_actgi') }),
                delHeader.to_item((delItem) => {
                    delItem({ ref: ['delivery_number'], as: obdmap.get('delivery_number') }),
                        delItem({ ref: ['item_number'], as: obdmap.get('item_number') }),
                        delItem({ ref: ['material'], as: obdmap.get('material') }),
                        delItem({ ref: ['customer_material'], as: obdmap.get('customer_material') }),
                        delItem({ ref: ['delivery_qty'], as: obdmap.get('delivery_qty') }),
                        delItem({ ref: ['uom'], as: obdmap.get('uom') }),
                        delItem({ ref: ['batch_number'], as: obdmap.get('batch_number') }),
                        delItem({ ref: ['batch_proddate'], as: obdmap.get('batch_proddate') }),
                        delItem({ ref: ['batch_main_item'], as: obdmap.get('batch_main_item') }),
                        delItem({ ref: ['expiry_date'], as: obdmap.get('expiry_date') }),
                        delItem({ ref: ['Interco_po'], as: obdmap.get('Interco_po') }),
                        delItem({ ref: ['interco_poitem'], as: obdmap.get('interco_poitem') })
                })
        }).where({ delivery_number: this.req.data.deliveryDocument })
    }); 

Am I overdoing the implementation or is this the right approach to include coded aliases?

Many thanks, and as always, keep it coming!

ceedee666 commented 1 month ago

Hi DJ, once again I find the answer to my questions in one of your blog post. 👏 Christian