diegomvh / angular-odata

Client side OData typescript library for Angular
https://www.npmjs.com/package/angular-odata
MIT License
46 stars 14 forks source link

Resource transformation #88

Open diegomvh opened 3 weeks ago

diegomvh commented 3 weeks ago

Can you tell me how can I migrate the following code:

// ODataEntitySetService<OrderSummaryItem>
this.orderService
    .entities()
    .query(q => {
        q.apply({
            transform: {
                // filters: string
                filter: filters,
                groupBy: {
                    properties: ['status'],
                    transform: {
                        aggregate: {
                            orderProductValue: {
                                with: StandardAggregateMethods.sum,
                                as: 'totalOrderValue'
                            },
                            ID: {
                                with: StandardAggregateMethods.countdistinct,
                                as: 'totalOrders'
                            }
                        }
                    }
                }
            }
        });
    })
    .fetch();

It seems the new apply() method version only accepts function or string.

EDIT: Should I use restore() instead of apply()? Would be nice to have some kind of Changelog with the new release to see at least any breaking changes.

Originally posted by @hakimio in https://github.com/diegomvh/angular-odata/issues/86#issuecomment-2126617551

diegomvh commented 3 weeks ago

WIP

const transform = recs.transform<{ directory: string, total: number, count: number, average: number }>(({ e, t }) => e()
  .filter(({ e, t }) => e().lt(t.fecha, new Date()))
  .groupBy(() => [t.directory],
    f => f.sum(t.size, 'total')
      .countdistinct(t.contentType, 'count')
      .average(t.size, 'average')
  ));
transform.query(q => {
  q.orderBy(({ e, t }) => e().descending(t.total));
})
console.log(recs.toString());
console.log(transform.toString());
transform.fetchCollection().subscribe((col) => {
  console.log(col);
});