Customize default sort behaviour
chapran opened this issue · 0 comments
Using postgres 12, @nestjsx/crud 5.0.0-alpha.3, is there any better way of overriding default NULL values sorting behaviour?
There is a need to put all entries with null field values at the end of the order. So far I've made a workaround with overwriting req.parsed.sort param directly with NULLS LAST
postfix, like this:
@Override()
getMany(@ParsedRequest() req: CrudRequest) {
const dateSortParam = req.parsed.sort.find(
(param) => param.field === 'date',
);
if (dateSortParam) {
// @ts-expect-error Enforce null date values to be the last
dateSortParam.order = `${dateSortParam.order} NULLS LAST`;
}
return this.base.getManyBase!(req);
}
It works, but looks a bit cumbersome since you need to override the controller method, and suppress the typescript error for the order
value not being one of 'ASC' | 'DESC'. I know not all the relational dbs support options like 'NULLS LAST | FIRST', but I didn't find any info related to this kind of customisations in the documentation.
Is there any way to make it nice and smooth using the library's API?