Search.../

updatePolicy( )

Updates a policy.

Description

The updatePolicy() function returns a Promise that resolves to the newly-updated policy.

Each time the policy is updated, revision increments by 1. The existing revision must be included when updating the policy. This ensures you're working with the latest policy and prevents unintended overwrites.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function updatePolicy(_id: string, policy: UpdatePolicy): Promise<Policy>

updatePolicy Parameters

NAME
TYPE
DESCRIPTION
_id
string

Policy ID.

policy
UpdatePolicy

Policy to update.

Returns

The updated policy.

Return Type:

Promise<
Policy
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date and time when the policy was created.

_id
string

Policy ID.

_updatedDate
Date

Date and time of the policy's latest update in.

body
string

Policy body, usually containing various terms and conditions.

Min: 1 character

Max: 50000 characters.

Note: You can format text using various HTML tags such as <p>, <b>, <ul>, etc.

eventId
string

ID of the event to which the policy belongs.

name
string

Policy name that is visible in the dashboard and checkout form.

Min: 1 character

Max: 40 characters

revision
string

Revision number, which increments by 1 each time the policy is updated. The existing revision must be used when updating a policy to prevent conflicting changes. You'll get an error if you try to use the previous revision.

Was this helpful?

Update Policy (dashboard page code)

Copy Code
1import { policies } from 'wix-events.v2';
2
3// define policy ID and policy object to update
4const id = '52f15c5c-ea06-44f4-866a-b1cfa6f4f790';
5const policy = {
6 name: 'Terms and Conditions Event 1',
7 body: 'If the Event is rescheduled, changed, moved or cancelled the Organiser cannot be held responsible for any resulting costs you may incur for travel, accommodation and other related goods, services or compensation.',
8 revision: '2',
9 eventId: '3d3d5c04-ece0-45a8-85f0-11a58edaa192'
10 };
11
12// update policy
13async function elevatedUpdatePolicyFunction(){
14 const elevatedUpdatePolicy = wixAuth.elevate(policies.updatePolicy);
15 try {
16 const result = await elevatedUpdatePolicy(id, policy);
17 return result;
18 }
19 catch (error) {
20 console.error(error);
21 // Handle the error
22 }
23 };
24
25/* Returns a promise that resolves to
26 the updated policy.
27{
28 "_id": "52f15c5c-ea06-44f4-866a-b1cfa6f4f790",
29 "revision": "3",
30 "_createdDate": "2023-03-07T14:15:44.312Z",
31 "_updatedDate": "2023-03-07T14:51:52.994Z",
32 "name": "Terms and Conditions Event 1",
33 "body": "If the Event is rescheduled, changed, moved or cancelled the Organiser cannot be held responsible for any resulting costs you may incur for travel, accommodation and other related goods, services or compensation.",
34 "eventId": "3d3d5c04-ece0-45a8-85f0-11a58edaa192"
35}
36*/
Update Policy (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { policies } from 'wix-events.v2';
3import { elevate } from 'wix-auth';
4
5// define policy ID and policy object to update
6const id = '52f15c5c-ea06-44f4-866a-b1cfa6f4f790';
7const policy = {
8 name: 'Terms and Conditions Event 1',
9 body: 'If the Event is rescheduled, changed, moved or cancelled the Organiser cannot be held responsible for any resulting costs you may incur for travel, accommodation and other related goods, services or compensation.',
10 revision: '2',
11 eventId: '3d3d5c04-ece0-45a8-85f0-11a58edaa192'
12 };
13
14// update policy
15export const elevatedUpdatePolicyFunction = webMethod(Permissions.Anyone, async () => {
16 const elevatedUpdatePolicy = elevate(policies.updatePolicy);
17 try {
18 const result = await elevatedUpdatePolicy(id, policy);
19 return result;
20 }
21 catch (error) {
22 console.error(error);
23 // Handle the error
24 }
25 });
26
27/* Promise resolves to:
28 * {
29 * "_id": "52f15c5c-ea06-44f4-866a-b1cfa6f4f790",
30 * "revision": "3",
31 * "_createdDate": "2023-03-07T14:15:44.312Z",
32 * "_updatedDate": "2023-03-07T14:51:52.994Z",
33 * "name": "Terms and Conditions Event 1",
34 * "body": "If the Event is rescheduled, changed, moved or cancelled the Organiser cannot be held responsible for any resulting costs you may incur for travel, accommodation and other related goods, services or compensation.",
35 * "eventId": "3d3d5c04-ece0-45a8-85f0-11a58edaa192"
36 * }
37 */
38