Search.../

updateBusinessSchedule( )

Developer Preview

Updates the default location's business schedule.

Description

The updateBusinessSchedule() function returns a Promise that resolves when the site's business schedule is updated.

Note:

  • The updateBusinessSchedule() function overwrites the current business schedule. businessSchedule is an array, so it must be written in its entirety. Therefore, you must modify the existing array and pass it in the function call.
Admin Method

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

Syntax

function updateBusinessSchedule(businessSchedule: BusinessSchedule): Promise<void>

updateBusinessSchedule Parameters

NAME
TYPE
DESCRIPTION
businessSchedule
BusinessSchedule

The site's business schedule in the site time zone.

Returns

Return Type:

Promise<
void
>

Was this helpful?

Update Business Schedule (dashboard page code)
This example uses elevate(), which enables site visitors to call functions without the required permissions. Exercise caution when using elevate() to prevent security vulnerabilities.

Copy Code
1import { siteProperties } from 'wix-business-tools.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample businessSchedule value:
5 * {
6 * "periods": [
7 * {
8 * "closeDay": "MONDAY",
9 * "closeTime": "13:00",
10 * "openDay": "MONDAY",
11 * "openTime": "08:00"
12 * },
13 * {
14 * "closeDay": "TUESDAY",
15 * "closeTime": "13:00",
16 * "openDay": "TUESDAY",
17 * "openTime": "08:00"
18 * },
19 * {
20 * "closeDay": "WEDNESDAY",
21 * "closeTime": "18:00",
22 * "openDay": "WEDNESDAY",
23 * "openTime": "08:00"
24 * },
25 * {
26 * "closeDay": "THURSDAY",
27 * "closeTime": "13:00",
28 * "openDay": "THURSDAY",
29 * "openTime": "08:00"
30 * },
31 * {
32 * "closeDay": "FRIDAY",
33 * "closeTime": "18:00",
34 * "openDay": "FRIDAY",
35 * "openTime": "08:00"
36 * }
37 * ],
38 * "specialHourPeriod": [
39 * {
40 * "comment": "Closed between Christmas and New Year",
41 * "endDate": "2023-12-31T23:59:00Z",
42 * "isClosed": true,
43 * "startDate": "2023-12-25T00:00:00Z"
44 * }
45 * ]
46 * }
47 */
48
49export async function myUpdateBusinessScheduleFunction(businessSchedule) {
50 try {
51 const elevatedUpdateBusinessSchedule = elevate(siteProperties.updateBusinessSchedule);
52 await elevatedUpdateBusinessSchedule(businessSchedule);
53
54 console.log('Success! Updated schedule');
55 return true;
56 } catch (error) {
57 console.error(error);
58 // Handle the error
59 }
60}
61
62/* Promise resolves to void */
63
Update Business Schedule (export from backend code)
This example uses elevate(), which enables site visitors to call functions without the required permissions. Exercise caution when using elevate() to prevent security vulnerabilities.

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { siteProperties } from 'wix-business-tools.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample businessSchedule value:
6 * {
7 * "periods": [
8 * {
9 * "closeDay": "MONDAY",
10 * "closeTime": "13:00",
11 * "openDay": "MONDAY",
12 * "openTime": "08:00"
13 * },
14 * {
15 * "closeDay": "TUESDAY",
16 * "closeTime": "13:00",
17 * "openDay": "TUESDAY",
18 * "openTime": "08:00"
19 * },
20 * {
21 * "closeDay": "WEDNESDAY",
22 * "closeTime": "18:00",
23 * "openDay": "WEDNESDAY",
24 * "openTime": "08:00"
25 * },
26 * {
27 * "closeDay": "THURSDAY",
28 * "closeTime": "13:00",
29 * "openDay": "THURSDAY",
30 * "openTime": "08:00"
31 * },
32 * {
33 * "closeDay": "FRIDAY",
34 * "closeTime": "18:00",
35 * "openDay": "FRIDAY",
36 * "openTime": "08:00"
37 * }
38 * ],
39 * "specialHourPeriod": [
40 * {
41 * "comment": "Closed between Christmas and New Year",
42 * "endDate": "2023-12-31T23:59:00Z",
43 * "isClosed": true,
44 * "startDate": "2023-12-25T00:00:00Z"
45 * }
46 * ]
47 * }
48 */
49
50export const myUpdateBusinessScheduleFunction = webMethod(Permissions.Anyone, async (businessSchedule) => {
51 try {
52 const elevatedUpdateBusinessSchedule = elevate(siteProperties.updateBusinessSchedule);
53 await elevatedUpdateBusinessSchedule(businessSchedule);
54
55 console.log('Success! Updated schedule');
56 return true;
57 } catch (error) {
58 console.error(error);
59 // Handle the error
60 }
61});
62
63/* Promise resolves to void */
64
updateBusinessSchedule() based on user input

This code is an example of a webpage for users with manager-level access to update the business' schedule. There is a form with checkboxes to indicate addition of another set of opening times (up to a maximum of 5) or the addition of a special hour. If the checkbox is checked, another form will appear with relevant dropdown choices - the values of the options are compatible with the required input (e.g. for 'Monday' option, value is 'MONDAY').

Copy Code
1/**************************************************
2 * Backend code - update-business-schedule.web.js *
3 *************************************************/
4import { Permissions, webMethod } from 'wix-web-module';
5import { siteProperties } from 'wix-business-tools.v2';
6import { elevate } from 'wix-auth';
7
8export const scheduleUpdate = webMethod(Permissions.Anyone, async (businessSchedule) => {
9 try {
10 const elevatedUpdateBusinessSchedule = elevate(siteProperties.updateBusinessSchedule);
11 await elevatedUpdateBusinessSchedule(businessSchedule);
12
13 console.log('Success! Schedule Updated');
14 return true;
15 } catch (error) {
16 console.error(error);
17 throw new Error(error);
18 }
19});
20
21
22/*************
23 * Page code *
24 ************/
25
26import { scheduleUpdate } from 'backend/update-business-schedule.web';
27
28$w.onReady(() => {
29 $w('#submit').onClick(async () => {
30 const newSchedule = newScheduleAsArrays();
31 const isUpdated = await scheduleUpdate(newSchedule);
32
33 if (isUpdated) {
34 console.log('Schedule successfully updated');
35 $w('#successfulUpdateMsg').show();
36 setTimeout(() => {
37 $w('#successfulUpdateMsg').hide();
38 }, 10000);
39 }
40 });
41});
42
43function newScheduleAsArrays() {
44 const newPeriods = [];
45 if ($w('#addSchedule1').checked) {
46 newPeriods.push({
47 openDay: $w('#openDay1').value,
48 openTime: $w('#openTime1').value,
49 closeDay: $w('#closeDay1').value,
50 closeTime: $w('#closeTime1').value
51 })
52 };
53 if ($w('#addSchedule2').checked) {
54 newPeriods.push({
55 openDay: $w('#openDay2').value,
56 openTime: $w('#openTime2').value,
57 closeDay: $w('#closeDay2').value,
58 closeTime: $w('#closeTime2').value
59 })
60 };
61 if ($w('#addSchedule3').checked) {
62 newPeriods.push({
63 openDay: $w('#openDay3').value,
64 openTime: $w('#openTime3').value,
65 closeDay: $w('#closeDay3').value,
66 closeTime: $w('#closeTime3').value
67 })
68 };
69 if ($w('#addSchedule4').checked) {
70 newPeriods.push({
71 openDay: $w('#openDay4').value,
72 openTime: $w('#openTime4').value,
73 closeDay: $w('#closeDay4').value,
74 closeTime: $w('#closeTime4').value
75 })
76 };
77 if ($w('#addSchedule5').checked) {
78 newPeriods.push({
79 openDay: $w('#openDay5').value,
80 openTime: $w('#openTime5').value,
81 closeDay: $w('#closeDay5').value,
82 closeTime: $w('#closeTime5').value
83 })
84 };
85
86 const newSpecialHour = [];
87 if ($w('#addSpecialHour').checked) {
88 newSpecialHour.push({
89 startDate: $w('#specialDateStart').value,
90 endDate: $w('#specialDateEnd').value,
91 isClosed: $w('#specialDateIsClosed').checked,
92 comment: $w('#specialDateComment').value
93 })
94 };
95
96 return {periods: newPeriods, specialHourPeriod: newSpecialHour};
97}
98