queryBookings( )
Creates a query to retrieve a list of bookings.
Description
The queryBookings()
function builds a query to retrieve a list of bookings and returns a BookingsQueryBuilder object.
The returned object contains the query definition which is typically used to run the query using the find()
function.
You can refine the query by chaining BookingsQueryBuilder
functions onto the query. BookingsQueryBuilder
functions enable you to sort, filter, and control the results that queryBookings()
returns.
The query runs with the following BookingsQueryBuilder
defaults that you can override:
eq
:"status": "CONFIRMED"
skip
:0
limit
:50
descending
:_createdDate
The functions that are chained to queryBookings()
are applied in the order they are called. For example, if you sort on the _createdDate
property in ascending order and then on the status
property in descending order, the results are sorted first by the created date of the items and then, if there are multiple results with the same date, the items are sorted by status in descending order, per created date value.
The following BookingsQueryBuilder
functions are supported for queryBookings()
.
For a full description of the Booking object, see the object returned for the items
property in BookingsQueryResult
.
Property | Filters | Description |
---|---|---|
_id | eq() | Query for a specific booking. eq("_id","46ce4cd4-46ff-4aa7-9cc0-02fd4f0f3209") |
contactId | eq() | Bookings made by the specified contact ID. eq("contactId","8711a950-74cc-4608-80fb-8f09df9cbbf4") |
sessionId | eq() , hasSome() | Bookings made to a given session or a list of sessions. hasSome("sessionId","[193ZPR9ppP9emJUCLevcLf6orynNE45", "c8UhG9ppABemJUCLevcLf6orynNE98"] ) |
startTime | ge() , lt() , ascending() , descending() | Bookings with a schedule or session start time (UTC) earlier than a given time, or at a given time or later. ge("startTime", "2020-04-27T10:00:00.000Z") |
endTime | gt() , le() | Bookings with a schedule or session end time (UTC) later than a given time, or at a given time or earlier. gt("endTime", "2020-04-27T10:00:00.000Z") |
status | eq() , hasSome() | Bookings with a given status or a status that is in a given list of statuses. hasSome("status", ["CONFIRMED", "PENDING_APPROVAL","CANCELED"]) |
_createdDate | ge() , lt() , ascending() , descending() | Bookings created at a given date or later, or earlier than a given date. lt("_createdDate", "2020-04-27T10:00:00.000Z") |
You can only use one filter function for each property. If a property is used in more than one filter, only the first filter will work.
Notes:
- By default,
queryBookings()
retrieves only statuses of"CONFIRMED"
. To retrieve all booking statuses use ahasSome()
filter with all of the statuses.- When using the
queryBookings()
function immediately following a change to your bookings, the data retrieved may not contain your most recent changes. See Wix-data and Eventual Consistency for more information. To solve this problem, you can use thesetTimeout()
function to delay querying for a number of seconds, following any changes to your bookings data.- Only users with Bookings Admin permissions can retrieve other customers' bookings. You can override the permissions by setting the
suppressAuth
options totrue
.
Syntax
function queryBookings(): BookingsQueryBuilder
queryBookings Parameters
This function does not take any parameters.
Returns
Return Type:
Was this helpful?
Use a hasSome()
filter to override the default and retrieve all booking statuses.
1import { Permissions, webMethod } from 'wix-web-module';2import { bookings } from 'wix-bookings-backend';34export const queryBookings = webMethod(Permissions.Anyone, () => {5 return bookings6 .queryBookings()7 .hasSome("status", ["PENDING_CHECKOUT", "CONFIRMED", "CANCELED", "PENDING", "PENDING_APPROVAL", "DECLINED"])8 .find()9 .then((queryResult) => {10 return queryResult.items;11 })12 .catch((error) => {13 return error;14 });15});
1import { Permissions, webMethod } from 'wix-web-module';2import { bookings } from 'wix-bookings-backend';34export const queryBookings = webMethod(Permissions.Anyone, () => {5 return bookings6 .queryBookings()7 .eq("status", "PENDING_APPROVAL")8 .ge("_createdDate", "2020-12-20T10:00:00.000Z")9 .lt("startTime", "2021-01-07T17:00:00.000Z")10 .find()11 .then((queryResult) => {12 return queryResult.items;13 })14 .catch((error) => {15 return error;16 });17});