Updates a resource's schedule.
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.
updateResourceSchedule()
to remove the business's scheduleId from the availability.linkedSchedules
array.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.
updateResourceSchedule()
to add the business resource's scheduleId
to the availability.linkedSchedules
array.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:
options.suppressAuth
parameter to true
.function updateResourceSchedule(
resourceId: string,
scheduleId: string,
scheduleInfo: ResourceScheduleInfo,
options: Options,
): Promise<ResourceSchedule>;
Resource ID to update.
Schedule ID.
Updated schedule information.
An object representing the available options for updating a resource schedule.
Update a resource's schedule from the business's default working hours to 2 custom days per week.
import { Permissions, webMethod } from "wix-web-module";
import { resources, sessions } from "wix-bookings-backend";
export const getResourceById = webMethod(
Permissions.Anyone,
async (resourceId) => {
return resources
.queryResourceCatalog()
.eq("_id", resourceId)
.find()
.then((results) => {
if (results.items.length > 0) return results.items[0].resource;
});
},
);
export const updateResourceToCustomHours = webMethod(
Permissions.Anyone,
async (resourceId) => {
let resource = await getResourceById(resourceId);
let recurrenceRules = [
"FREQ=WEEKLY;INTERVAL=1;BYDAY=MO;UNTIL=20220101T000000Z",
];
recurrenceRules.push(
"FREQ=WEEKLY;INTERVAL=1;BYDAY=WE;UNTIL=20220101T000000Z",
);
let recurringSession = {
scheduleId: resource.scheduleIds[0],
start: {
localDateTime: {
year: 2021,
monthOfYear: 3,
dayOfMonth: 1,
hourOfDay: 10,
minutesOfHour: 0,
},
},
end: {
localDateTime: {
year: 2021,
monthOfYear: 3,
dayOfMonth: 1,
hourOfDay: 16,
minutesOfHour: 0,
},
},
type: "WORKING_HOURS",
recurrence: "placeholder",
};
let updateResourceScheduleInfo = {
availability: {
linkedSchedules: [],
},
};
try {
var resourceSchedule = await resources.updateResourceSchedule(
resourceId,
resource.scheduleIds[0],
updateResourceScheduleInfo,
);
} catch (error) {
console.error("Failed to update resource: ", error);
}
let promiseList = [];
recurrenceRules.forEach((rule) => {
try {
recurringSession.recurrence = rule;
console.log("Rec sess", rule, recurringSession);
promiseList.push(sessions.createSession(recurringSession, []));
} catch (error) {
console.error("Failed to create session:", error);
}
});
return Promise.all(promiseList)
.then((sessions) => {
const resourceSessions = {
resource: resource,
schedule: resourceSchedule,
sessions: sessions,
};
return resourceSessions;
})
.catch((error) => {
console.error(error);
});
},
);
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.