Search.../

queryResourceCatalog( )

Creates a query to retrieve extended resource information.

Description

The queryResourceCatalog() function builds a query to retrieve a catalog of resources, including resources' related schedules and slugs, and returns a ResourceCatalogQueryBuilder object. The returned object contains the query definition, which is typically used to run the query using the find() function.

The ResourceCatalogQueryBuilder functions enable you to run, filter, and control which results a query returns.

Typically, you build a query using the resource catalog query function, refine the query by chaining ResourceCatalogQueryBuilder functions, and then execute the query by chaining the find() function.

The query runs with the following ResourceCatalogQueryBuilder defaults that you can override:

The following query builder functions are supported for queryResourceCatalog().

PropertySupported Filters                                                           
_ideq()
slugs.nameeq(), hasSome()

For a full description of the Resources object, see the object returned for the items array in ResourceCatalogQueryResult.

Note: Only users with the Bookings Admin role can query resources.

Syntax

function queryResourceCatalog(): ResourceCatalogQueryBuilder

queryResourceCatalog Parameters

This function does not take any parameters.

Returns

A ResourceCatalogQueryBuilder object that contains the refined query

Was this helpful?

Create a query, add an eq filter, and run it

Copy Code
1import { resources } from "wix-bookings-backend";
2
3// ...
4
5return resources.queryResourceCatalog()
6 .eq("_id","290113d8-e525-4619-a154-b0c45110348f")
7 .find()
8 .then((results) => {
9 if (results.items.length > 0) {
10 const items = results.items;
11 const firstItem = items[0];
12 const totalCount = results.totalCount;
13 const pageSize = results.pageSize;
14 const currentPage = results.currentPage;
15 const totalPages = results.totalPages;
16 const hasNext = results.hasNext();
17 const hasPrev = results.hasPrev();
18 const length = results.length;
19 const query = results.query;
20 return results.items;
21 } else {
22 // handle case where no matching items found
23 }
24 })
25 .catch((error) => {
26 console.error(error);
27 });
28
29 /* Returns a promise that resolves to an array of resourceCatalog objects:
30 *
31 * [
32 * {
33 * "resource": {
34 * "_id": "290113d8-e525-4619-a154-b0c45110348f",
35 * "name": "Jack Brown",
36 * "email": "jbrown@test.com",
37 * "phone": "555 4321",
38 * "description": "Instructor",
39 * "tags": [
40 * "staff"
41 * ],
42 * "scheduleIds": [
43 * "95d8769e-ce74-4fe2-ab79-ab24e5c14e0e"
44 * ],
45 * "status": "UPDATED"
46 * },
47 * "schedules": [
48 * {
49 * "availability": {
50 * "linkedSchedules": [
51 * {
52 * "scheduleId": "9299760d-8a4a-4f89-b348-1fc611f4be17"
53 * }
54 * ],
55 * "start": "2021-04-18T07:22:42.274Z"
56 * },
57 * "_id": "95d8769e-ce74-4fe2-ab79-ab24e5c14e0e",
58 * "scheduleOwnerId": "290113d8-e525-4619-a154-b0c45110348f"
59 * }
60 * ],
61 * "slugs": [
62 * {
63 * "_createdDate": "2021-04-18T07:22:43.392Z",
64 * "name": "jack-brown"
65 * }
66 * ]
67 */