Hello everyone, currently I'm trying to perform find all methods with query params that included sortBy in the endpoint like this GET localhost:3000/api/v1/contacts?page=1&size=10&sortBy=asc
But the input cannot process to the query, because it's diferent type.
This is my query look like:
import { QueryOrder } from '@mikro-orm/core';
const sorting: Record<QueryOrder> = {};
if (searchReq.sortBy) {
const [field, direction] = searchReq.sortBy.split(':');
sorting[field] = direction === 'asc' ? QueryOrder.ASC : QueryOrder.DESC;
}
const [contacts, totalContacts] = await this.contactRepository.findAndCount(
{
user: user.id,
$and: filters,
},
{
limit: searchReq.size,
offset: (searchReq.page - 1) * searchReq.size,
orderBy: { id: sorting },
},
)
the id in orderBy have type QueryOrderKeys<number> and must filled with QueryOrder.ASC that have type enum like this:
export enum QueryOrder {
ASC = "ASC",
ASC_NULLS_LAST = "ASC NULLS LAST",
ASC_NULLS_FIRST = "ASC NULLS FIRST",
DESC = "DESC",
}```
all of that imported from @mikro-orm/ core
if I make variabel like this and replace it on `sorting `variable:
```ts
const asc = searchReq.sortBy === 'asc' ? QueryOrder.DESC : QueryOrder.ASC;
false expresstion will always that got read, even thought my input is asc or desc in sortBy query param.
Anyone know how to handle this problem?