updateBusinessSchedule( )
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.
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
The site's business schedule in the site time zone.
Returns
Return Type:
Was this helpful?
This example useselevate()
, which enables site visitors to call functions without the required permissions. Exercise caution when usingelevate()
to prevent security vulnerabilities.
1import { siteProperties } from 'wix-business-tools.v2';2import { elevate } from 'wix-auth';34/* 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 */4849export async function myUpdateBusinessScheduleFunction(businessSchedule) {50 try {51 const elevatedUpdateBusinessSchedule = elevate(siteProperties.updateBusinessSchedule);52 await elevatedUpdateBusinessSchedule(businessSchedule);5354 console.log('Success! Updated schedule');55 return true;56 } catch (error) {57 console.error(error);58 // Handle the error59 }60}6162/* Promise resolves to void */63
This example useselevate()
, which enables site visitors to call functions without the required permissions. Exercise caution when usingelevate()
to prevent security vulnerabilities.
1import { Permissions, webMethod } from 'wix-web-module';2import { siteProperties } from 'wix-business-tools.v2';3import { elevate } from 'wix-auth';45/* 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 */4950export const myUpdateBusinessScheduleFunction = webMethod(Permissions.Anyone, async (businessSchedule) => {51 try {52 const elevatedUpdateBusinessSchedule = elevate(siteProperties.updateBusinessSchedule);53 await elevatedUpdateBusinessSchedule(businessSchedule);5455 console.log('Success! Updated schedule');56 return true;57 } catch (error) {58 console.error(error);59 // Handle the error60 }61});6263/* Promise resolves to void */64
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').
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';78export const scheduleUpdate = webMethod(Permissions.Anyone, async (businessSchedule) => {9 try {10 const elevatedUpdateBusinessSchedule = elevate(siteProperties.updateBusinessSchedule);11 await elevatedUpdateBusinessSchedule(businessSchedule);1213 console.log('Success! Schedule Updated');14 return true;15 } catch (error) {16 console.error(error);17 throw new Error(error);18 }19});202122/*************23 * Page code *24 ************/2526import { scheduleUpdate } from 'backend/update-business-schedule.web';2728$w.onReady(() => {29 $w('#submit').onClick(async () => {30 const newSchedule = newScheduleAsArrays();31 const isUpdated = await scheduleUpdate(newSchedule);3233 if (isUpdated) {34 console.log('Schedule successfully updated');35 $w('#successfulUpdateMsg').show();36 setTimeout(() => {37 $w('#successfulUpdateMsg').hide();38 }, 10000);39 }40 });41});4243function 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').value51 })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').value59 })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').value67 })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').value75 })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').value83 })84 };8586 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').value93 })94 };9596 return {periods: newPeriods, specialHourPeriod: newSpecialHour};97}98