Search.../

updateResourceSchedule( )

Updates a resource's schedule.

Description

The updateResourceSchedule() function returns a Promise that resolves when a resource's schedule has been updated. Use this function to update the bookings resource's schedule. To update other resource details use updateResource().

The following schedule properties can be updated:

  • availability.start
  • availability.linkedSchedules

Update a resource's schedule to remove business hours and add custom hours.

  • Use updateResourceSchedule() to remove the business's scheduleId from the availability.linkedSchedules array.
  • Use createSession() to create a set of recurring sessions of type "WORKING_HOURS" to define the resource's new hours.

Update a resource's schedule to add default business hours, and keep or remove custom hours.

  • Use updateResourceSchedule() to add the business resource's scheduleId to the availability.linkedSchedules array.
  • If you want to remove the custom sessions, use deleteSession() to delete the resource's sessions of type "WORKING_HOURS". You do not have to delete exiting custom sessions. You can have both default working hours and custom hours for the same schedule. Custom sessions that are not deleted will continue to be included in availability calculations and can still be booked.

Notes:

  • The Wix Bookings app does not show both default business hours and custom hours on the Staff page in the dashboard. If you've set up both custom and default business hours, only the default business hours will appear in the app, although both are working.
  • A resource can have one schedule only.
  • A resource can have both default business hours and custom hours in its schedule.
  • When updating a resource's schedule you cannot change the system tags used by the Wix Bookings app. Tags used by the app have the values "INDIVIDUAL", "GROUP", and "COURSE”.
  • Only users with the Bookings Admin role can update a resource schedule. You can override the role permissions by setting the options.suppressAuth parameter to true.

Syntax

function updateResourceSchedule(resourceId: string, scheduleId: string, scheduleInfo: ResourceScheduleInfo, [options: Options]): Promise<ResourceSchedule>

updateResourceSchedule Parameters

NAME
TYPE
DESCRIPTION
resourceId
string

Resource ID to update.

scheduleId
string

Schedule ID.

scheduleInfo
ResourceScheduleInfo

Updated schedule information.

options
Optional
Options

An object representing the available options for updating a resource schedule.

Returns

Return Type:

Promise<ResourceSchedule>
NAME
TYPE
DESCRIPTION
_id
string

Schedule ID.

scheduleOwnerId
string

ID of the schedule's owner entity. This may be a resource ID or a service ID.

availability
ResourceScheduleAvailability

An object describing how to calculate the schedule's availability. An empty object indicates that the schedule is not available for booking.

Was this helpful?

Update a resource's schedule from business to custom hours

Update a resource's schedule from the business's default working hours to 2 custom days per week.

Copy Code
1
2import { Permissions, webMethod } from 'wix-web-module';
3import { resources, sessions } from 'wix-bookings-backend';
4
5export const getResourceById = webMethod(Permissions.Anyone, async (resourceId) => {
6 return resources.queryResourceCatalog()
7 .eq("_id", resourceId)
8 .find()
9 .then((results) => {
10 if (results.items.length > 0)
11 return results.items[0].resource
12 })
13});
14
15export const updateResourceToCustomHours = webMethod(Permissions.Anyone, async (resourceId) => {
16 let resource = await getResourceById(resourceId);
17 let recurrenceRules = ['FREQ=WEEKLY;INTERVAL=1;BYDAY=MO;UNTIL=20220101T000000Z'];
18 recurrenceRules.push('FREQ=WEEKLY;INTERVAL=1;BYDAY=WE;UNTIL=20220101T000000Z');
19 let recurringSession = {
20 scheduleId: resource.scheduleIds[0],
21 start: {
22 localDateTime: {
23 year: 2021,
24 monthOfYear: 3,
25 dayOfMonth: 1,
26 hourOfDay: 10,
27 minutesOfHour: 0
28 }
29 },
30 end: {
31 localDateTime: {
32 year: 2021,
33 monthOfYear: 3,
34 dayOfMonth: 1,
35 hourOfDay: 16,
36 minutesOfHour: 0
37 }
38 },
39 type: 'WORKING_HOURS',
40 recurrence: 'placeholder'
41 };
42 let updateResourceScheduleInfo = {
43 availability: {
44 linkedSchedules: []
45 }
46 };
47 try {
48 var resourceSchedule = await resources.updateResourceSchedule(resourceId, resource.scheduleIds[0], updateResourceScheduleInfo);
49 } catch (error) {
50 console.error('Failed to update resource: ', error);
51 }
52 let promiseList = [];
53 recurrenceRules.forEach(rule => {
54 try {
55 recurringSession.recurrence = rule;
56 console.log("Rec sess", rule, recurringSession)
57 promiseList.push(sessions.createSession(recurringSession, []));
58 } catch (error) {
59 console.error('Failed to create session:', error);
60 }
61 })
62 return Promise.all(promiseList)
63 .then(sessions => {
64 const resourceSessions = {
65 resource: resource,
66 schedule: resourceSchedule,
67 sessions: sessions
68 };
69 return resourceSessions;
70 })
71 .catch((error) => {
72 console.error(error);
73 })
74});
75
Update a resource's schedule from custom to business hours

Copy Code
1import { Permissions, webMethod } from "wix-web-module";
2import { resources } from "wix-bookings-backend";
3
4export const getBusinessSchedule = webMethod(Permissions.Anyone, async () => {
5 return resources
6 .queryResourceCatalog()
7 .eq("slugs.name", "business")
8 .find()
9 .then((results) => {
10 const businessResource = results.items[0].resource;
11 return businessResource;
12 });
13});
14
15export const updateResourceToBusinessHours = webMethod(
16 Permissions.Anyone,
17 async (resourceId) => {
18 const businessResource = await getBusinessSchedule();
19 const businessResourceScheduleId = businessResource.scheduleIds[0];
20
21 const result = await resources
22 .queryResourceCatalog()
23 .eq("_id", resourceId)
24 .find();
25 const resource = result.items[0].resource;
26 const scheduleId = resource.scheduleIds[0];
27
28 let updateResourceScheduleInfo = {
29 availability: {
30 linkedSchedules: [
31 {
32 scheduleId: businessResourceScheduleId,
33 },
34 ],
35 start: new Date(),
36 },
37 };
38
39 return resources
40 .updateResourceSchedule(resourceId, scheduleId, updateResourceScheduleInfo)
41 .then((schedule) => {
42 return schedule;
43 })
44 .catch((error) => {
45 console.error("Failed to update resource schedule: ", error);
46 return error;
47 });
48 }
49);
50
51/* Example returned schedule:
52 *
53 * {
54 * "_id": "9f372f46-cf75-49d2-837a-9c013525e17f",
55 * "scheduleOwnerId": "bbed138b-f7c6-497c-b5bf-0fcf9389018d",
56 * "availability": {
57 * "linkedSchedules": [
58 * {
59 * "scheduleId": "9299760d-8a4a-4f89-b348-1fc611f4be17"
60 * }
61 * ],
62 * "start": "2021-04-28T17:07:29.124Z"
63 * }
64 * }
65 */