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
1import { resources, sessions } from "wix-bookings-backend";
2
3export
4 function getResourceById(resourceId) {
5 return resources.queryResourceCatalog()
6 .eq("_id", resourceId)
7 .find()
8 .then((results) => {
9 if (results.items.length > 0)
10 return results.items[0].resource
11 })
12}
13export async function updateResourceToCustomHours(resourceId) {
14 let resource = await getResourceById(resourceId);
15 let recurrenceRules = ['FREQ=WEEKLY;INTERVAL=1;BYDAY=MO;UNTIL=20220101T000000Z'];
16 recurrenceRules.push('FREQ=WEEKLY;INTERVAL=1;BYDAY=WE;UNTIL=20220101T000000Z');
17 let recurringSession = {
18 scheduleId: resource.scheduleIds[0],
19 start: {
20 localDateTime: {
21 year: 2021,
22 monthOfYear: 3,
23 dayOfMonth: 1,
24 hourOfDay: 10,
25 minutesOfHour: 0
26 }
27 },
28 end: {
29 localDateTime: {
30 year: 2021,
31 monthOfYear: 3,
32 dayOfMonth: 1,
33 hourOfDay: 16,
34 minutesOfHour: 0
35 }
36 },
37 type: 'WORKING_HOURS',
38 recurrence: 'placeholder'
39 };
40 let updateResourceScheduleInfo = {
41 availability: {
42 linkedSchedules: []
43 }
44 };
45 try {
46 var resourceSchedule = await resources.updateResourceSchedule(resourceId, resource.scheduleIds[0], updateResourceScheduleInfo);
47 } catch (error) {
48 console.error('Failed to update resource: ', error);
49 }
50 let promiseList = [];
51 recurrenceRules.forEach(rule => {
52 try {
53 recurringSession.recurrence = rule;
54 console.log("Rec sess", rule, recurringSession)
55 promiseList.push(sessions.createSession(recurringSession, []));
56 } catch (error) {
57 console.error('Failed to create session:', error);
58 }
59 })
60 return Promise.all(promiseList)
61 .then(sessions => {
62 const resourceSessions = {
63 resource: resource,
64 schedule: resourceSchedule,
65 sessions: sessions
66 };
67 return resourceSessions;
68 })
69 .catch((error) => {
70 console.error(error);
71 })
72}
73 /* Example of a returned resource, schedule, and sessions array:
74 *
75 * {
76 * "resource": {
77 * "_id": "2a843db6-cb3f-4c96-90b8-f2f6e0055cae",
78 * "name": "Kitty Corner",
79 * "email": "kc@tets.com",
80 * "phone": "5558566",
81 * "description": "Yoga Guru",
82 * "tags": [
83 * "staff"
84 * ],
85 * "scheduleIds": [
86 * "aec380c0-ca2c-43c2-98f4-9aebbd3276f3"
87 * ],
88 * "status": "UPDATED"
89 * },
90 * "schedule": {
91 * "availability": {
92 * "linkedSchedules": [],
93 * "start": "2021-04-25T04:00:00.000Z"
94 * },
95 * "_id": "aec380c0-ca2c-43c2-98f4-9aebbd3276f3",
96 * "scheduleOwnerId": "2a843db6-cb3f-4c96-90b8-f2f6e0055cae"
97 * },
98 * "sessions": [
99 * {
100 * "end": {
101 * "localDateTime": {
102 * "year": 2021,
103 * "monthOfYear": 3,
104 * "dayOfMonth": 1,
105 * "hourOfDay": 16,
106 * "minutesOfHour": 0
107 * }
108 * },
109 * "_id": "aec380c0ca2c43c298f49aebbd3276f3-d93af6386f854cf7946927ac68813e7e",
110 * "notes": "",
111 * "recurrence": "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO;UNTIL=20220101T000000Z",
112 * "scheduleId": "aec380c0-ca2c-43c2-98f4-9aebbd3276f3",
113 * "scheduleOwnerId": "2a843db6-cb3f-4c96-90b8-f2f6e0055cae",
114 * "start": {
115 * "localDateTime": {
116 * "year": 2021,
117 * "monthOfYear": 3,
118 * "dayOfMonth": 1,
119 * "hourOfDay": 10,
120 * "minutesOfHour": 0
121 * }
122 * },
123 * "status": "UPDATED",
124 * "tags": [],
125 * "type": "WORKING_HOURS"
126 * },
127 * {
128 * "end": {
129 * "localDateTime": {
130 * "year": 2021,
131 * "monthOfYear": 3,
132 * "dayOfMonth": 1,
133 * "hourOfDay": 16,
134 * "minutesOfHour": 0
135 * }
136 * },
137 * "_id": "aec380c0ca2c43c298f49aebbd3276f3-9f7959bd662a4eea97805a6067cfe079",
138 * "notes": "",
139 * "recurrence": "FREQ=WEEKLY;INTERVAL=1;BYDAY=WE;UNTIL=20220101T000000Z",
140 * "scheduleId": "aec380c0-ca2c-43c2-98f4-9aebbd3276f3",
141 * "scheduleOwnerId": "2a843db6-cb3f-4c96-90b8-f2f6e0055cae",
142 * "start": {
143 * "localDateTime": {
144 * "year": 2021,
145 * "monthOfYear": 3,
146 * "dayOfMonth": 1,
147 * "hourOfDay": 10,
148 * "minutesOfHour": 0
149 * }
150 * },
151 * "status": "UPDATED",
152 * "tags": [],
153 * "type": "WORKING_HOURS"
154 * }
155 * ]
156 * }
157 */
Update a resource's schedule from custom to business hours

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