Skip to main content

Sorting and Filtering

NestJSX/Crud is a robust library designed for creating high-performance and scalable APIs. With NestJSX/Crud, API consumers can take advantage of a flexible and intuitive approach to querying data.

This library streamlines the process of searching, sorting, and paginating data to cater to the exact requirements of the API consumer. This feature saves valuable time by allowing the API consumer to bypass irrelevant data, ensuring only the necessary data is obtained.

note

We encourage use of the search parameter (s=...), and do not allow use of the deprecated filter parameter.

Search Examples

Find all active Appointments created or updated since March 15th, 2023 at 8am MST (since created appts also have updated lastChangeDateTime)

s={"lastChangedDateTime":{"$gt":"2023-03-15T08:00:00.000-07:00"}}

Find all soft-deleted (inActive) appointments updated since a date/time (isActive:false indicates soft-deleted)

s={"$and":[{"lastChangedDateTime": {"$gt":"2023-07-7T00:00:00.000Z"}},{"isActive":false}]}

Find all appointments changed since a date time (both active and inactive). This is useful for integration partners with recurring series who need to know future appointments in the series have been removed

s={"$and":[{"lastChangedDateTime": {"$gt":"2023-07-7T00:00:00.000Z"}},{"$or":[{"isActive":true},{"isActive":false}]}]}

Find all Appointment where the tags are empty

s={"tags": {"$or": {"$isnull": true, "$eq": "{}"}}}

Find all Appointments where it includes a tag of Late

s={"tags":{"$contL":"Late"}}

Find all appointments in Scheduled status set to start after March 15th, 2023 at 8am MST

s={"$and":[{"status":"Scheduled"},{"start":{"$gt":"2023-03-15T08:00:00.000-07:00"}}]}

Join Examples

To return data from other tables without the need to make a secondary query, the API consumer can join specific tables together and request only the fields necessary.

Get the appointment with the carrier and company. This will return a nested User with a nested Company in the result for each appointment. Order matters here. You must first include user to get to user.company.

join=user&join=user.company

To get just the user's email and company's name, you can use the || operator. Because user.companyId = company.id you must at least include companyId on user

join=user||email,companyId&join=user.company||name

Other Examples

To get an appointment's refNumber (PO), start, lastChangedDateTime, and carrier company name

s={"start": {"$gt":"2023-03-15T00:00:00.000Z"}}&join=user||companyId&join=user.company||name&fields=refNumber,lastChangedDateTime,start