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.
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
Policy ID.
Policy to update.
Returns
The updated policy.
Return Type:
NAME
TYPE
DESCRIPTION
Date and time when the policy was created.
Policy ID.
Date and time of the policy's latest update in.
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.
ID of the event to which the policy belongs.
Policy name that is visible in the dashboard and checkout form.
Min: 1 character
Max: 40 characters
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?
1import { policies } from 'wix-events.v2';23// define policy ID and policy object to update4const 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 };1112// update policy13async 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 error22 }23 };2425/* Returns a promise that resolves to26 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*/
1import { Permissions, webMethod } from 'wix-web-module';2import { policies } from 'wix-events.v2';3import { elevate } from 'wix-auth';45// define policy ID and policy object to update6const 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 };1314// update policy15export 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 error24 }25 });2627/* 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