Yes, the documentation is incomplete but seems like they are working on it.
Meanwhile, you can try find()
on a repository
with where
and or
parameters together. For pagination, offset
and limit
parameters work fine. More details on filter available here on their docs. Details on CrudConnector.find()
method is available here.
For your reference, I'll attach my piece of code and use it as you wish.
/**
* customer.repository.ts
* mongodb datasource
* @param [searchKey] Search in `firstName`, `lastName`, or `email`
* @param [pageIndex] page number. If provided, `pageSize` is required
* @param [pageSize] records per page. If provided, `pageIndex` is required
* @returns {CustomerInfoInterface[]} List of customers sorted by `firstName`
*/
async getCustomerList(searchKey?: string, pageIndex?: number, pageSize?: number): Promise<CustomerInfoInterface[]> {
const searchParam = searchKey || '';
const searchParams = [
{firstName: {like: searchParam, options: 'i'}},
{lastName: {like: searchParam, options: 'i'}},
{email: {like: searchParam, options: 'i'}},
];
var filterObject = {where: {or: searchParams}, order: ['firstName ASC']};
if (pageIndex && pageSize) {
const offset = (pageIndex - 1) * pageSize;
const limit = pageSize;
filterObject = Object.assign(filterObject, {limit, offset});
}
logger.debug('search user list with search query');
logger.debug(filterObject);
const customerList = await this.find(filterObject);
return customerList.map(i => ({
customerId: i.customerId,
firstName: i.firstName,
lastName: i.lastName,
phone: i.phone,
address: i.address,
id: i.customerId,
}));
}