Search.../

queryPolicies( )

Creates a query to retrieve a list of policies, given the provided paging and filter.

Description

The queryPolicies() function builds a query to retrieve a list of policies and returns a PoliciesQueryBuilder 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 PoliciesQueryBuilder functions onto the query. PoliciesQueryBuilder functions enable you to sort, filter and control the results that PoliciesQueryBuilder.find() returns.

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

limit: 50
descending: _createdDate

The functions that are chained to queryPolicies() are applied in the order they are called. For example, if you sort on the _createdDate property in ascending order and then on the id property in descending order, the results are sorted by the created date and then, if there are multiple results with the same date, the items are sorted by the id.

The table below shows which PoliciesQueryBuilder functions are supported for queryPoliciesGuests(). 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.

PROPERTYSUPPORTED FILTERS & SORTING
_ideq(),ne(),in(),exists(),ascending(),descending()
revisioneq(),ne(),in(),lt(),le(),gt(),ge(),exists(),ascending(),descending()
_createdDateeq(),ne(),in(),lt(),le(),gt(),ge(),exists(),ascending(),descending()
_updatedDateeq(),ne(),in(),lt(),le(),gt(),ge(),exists(),ascending(),descending()
nameeq(),ne(),in(),exists(),ascending(),descending()
bodyeq(),ne(),in(),exists(),ascending(),descending()
eventIdeq(),ne(),in(),exists(),ascending(),descending()

Syntax

function queryPolicies(): PoliciesQueryBuilder

queryPolicies Parameters

This function does not take any parameters.

Returns

Was this helpful?

Query Policies by name and sort by _createdDate in descending order

Copy Code
1import { policies } from 'wix-events.v2';
2
3//query policies
4async function queryPolicies() {
5 try {
6 const items = await policies.queryPolicies()
7 .eq('eventId', '3d3d5c04-ece0-45a8-85f0-11a58edaa192')
8 .ascending('_createdDate')
9 .find();
10 return items;
11 }
12 catch (error) {
13 console.error(error);
14 // Handle the error
15 }
16 };
17
18/* Returns all found policies
19{
20 "_items": [
21 {
22 "_id": "96b39980-e4e1-44e3-9ef0-9bec41d1cc10",
23 "revision": "6",
24 "_createdDate": "2023-03-08T13:55:18.057Z",
25 "_updatedDate": "2023-03-15T13:43:11.794Z",
26 "name": "Terms and Conditions Event 2",
27 "body": "<p>Nobody will be allowed admission to the Event without a valid ticket or pass.</p>",
28 "eventId": "3d3d5c04-ece0-45a8-85f0-11a58edaa192"
29 },
30 {
31 "_id": "850beadf-f367-4197-a0c8-6624cb3bcef9",
32 "revision": "1",
33 "_createdDate": "2023-03-15T13:49:27.023Z",
34 "_updatedDate": "2023-03-15T13:49:27.023Z",
35 "name": "Terms and Conditions Event 1",
36 "body": "<p>Tickets to this Event are issued on behalf of the Organiser and are subject to the following terms and conditions.</p>",
37 "eventId": "3d3d5c04-ece0-45a8-85f0-11a58edaa192"
38 }
39 ],
40 "_originQuery": {
41 "filterTree": {
42 "$and": [
43 {
44 "eventId": "3d3d5c04-ece0-45a8-85f0-11a58edaa192"
45 }
46 ]
47 },
48 "invalidArguments": [],
49 "encoder": {},
50 "transformationPaths": {},
51 "sort": [
52 {
53 "fieldName": "createdDate",
54 "order": "ASC"
55 }
56 ],
57 "paging": {},
58 "pagingMethod": "CURSOR",
59 "builderOptions": {
60 "cursorWithEmptyFilterAndSort": true
61 }
62 },
63 "_limit": 50,
64 "_nextCursor": "",
65 "_prevCursor": "",
66 "cursors": {
67 "next": "",
68 "prev": ""
69 }
70}
71*/
Query Policies by name and sort by _createdDate in descending order (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { policies } from 'wix-events.v2';
3
4export const queryPolicies = webMethod(Permissions.Anyone, async () => {
5 try {
6 const items = await policies.queryPolicies()
7 .eq('eventId', '3d3d5c04-ece0-45a8-85f0-11a58edaa192')
8 .ascending('_createdDate')
9 .find();
10 return items;
11 } catch (error) {
12 console.error(error);
13 // Handle the error
14 }
15});
16
17/* Promise resolves to:
18 * {
19 * "_items": [
20 * {
21 * "_id": "96b39980-e4e1-44e3-9ef0-9bec41d1cc10",
22 * "revision": "6",
23 * "_createdDate": "2023-03-08T13:55:18.057Z",
24 * "_updatedDate": "2023-03-15T13:43:11.794Z",
25 * "name": "Terms and Conditions Event 2",
26 * "body": "<p>Nobody will be allowed admission to the Event without a valid ticket or pass.</p>",
27 * "eventId": "3d3d5c04-ece0-45a8-85f0-11a58edaa192"
28 * },
29 * {
30 * "_id": "850beadf-f367-4197-a0c8-6624cb3bcef9",
31 * "revision": "1",
32 * "_createdDate": "2023-03-15T13:49:27.023Z",
33 * "_updatedDate": "2023-03-15T13:49:27.023Z",
34 * "name": "Terms and Conditions Event 1",
35 * "body": "<p>Tickets to this Event are issued on behalf of the Organiser and are subject to the following terms and conditions.</p>",
36 * "eventId": "3d3d5c04-ece0-45a8-85f0-11a58edaa192"
37 * }
38 * ],
39 * "_originQuery": {
40 * "filterTree": {
41 * "$and": [
42 * {
43 * "eventId": "3d3d5c04-ece0-45a8-85f0-11a58edaa192"
44 * }
45 * ]
46 * },
47 * "invalidArguments": [],
48 * "encoder": {},
49 * "transformationPaths": {},
50 * "sort": [
51 * {
52 * "fieldName": "createdDate",
53 * "order": "ASC"
54 * }
55 * ],
56 * "paging": {},
57 * "pagingMethod": "CURSOR",
58 * "builderOptions": {
59 * "cursorWithEmptyFilterAndSort": true
60 * }
61 * },
62 * "_limit": 50,
63 * "_nextCursor": "",
64 * "_prevCursor": "",
65 * "cursors": {
66 * "next": "",
67 * "prev": ""
68 * }
69 * }
70 */
71