updateReservationLocation( )
Updates a reservation location. Supports partial updates.
Description
Each time the reservation location is updated, revision
increments by 1. The existing revision must be included when updating the reservation location. This ensures you're working with the latest reservation location information, and it prevents unintended overwrites.
You cannot use this endpoint to change a reservation location's location
object. Attempting to do so will cause the server to return an application error.
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function updateReservationLocation(_id: string, reservationLocation: UpdateReservationLocation): Promise<ReservationLocation>
updateReservationLocation Parameters
NAME
TYPE
DESCRIPTION
Reservation location ID.
Reservation location information to update.
Returns
The updated reservation location.
Return Type:
NAME
TYPE
DESCRIPTION
The date and time this reservation location was created.
Reservation location ID.
The date and time this reservation location was last updated.
Whether this reservation location's location
is archived.
Reservation location configuration.
Whether this reservation location's location
is the default location of the business.
Physical location details.
Locations can be created and configured using the Locations API or on the Business Info page in the Dashboard.
Represents the current state of a reservation location. Each time the reservation location is modified, its revision
changes. For an update operation to succeed, you must pass the latest revision.
Was this helpful?
This function call requires elevation to get the necessary permissions
1import { Permissions, webMethod } from 'wix-web-module';2import { reservationLocations } from 'wix-table-reservations.v2';3import { elevate } from 'wix-auth';45/* Sample reservationLocationId value: 'fab8cc1f-31cf-462f-b5bb-392594624bf2'6 *7 * Sample reservationLocationObject value:8 * {9 * "revision": "11",10 * "configuration": {11 * "onlineReservations": {12 * "minimumReservationNotice": {13 * "number": 40,14 * "unit": "MINUTES"15 * },16 * "onlineReservationsEnabled": false17 * }18 * }19 * }20 */2122export const myUpdateReservationLocationFunction = webMethod(Permissions.Anyone, async (reservationLocationId, reservationLocationObject) => {23 const elevatedUpdateReservationLocation = elevate(reservationLocations.updateReservationLocation);2425 try {26 const result = await elevatedUpdateReservationLocation(reservationLocationId, reservationLocationObject);27 return result;28 } catch (error) {29 console.error(error);30 // Handle the error31 }32});3334/* Promise resolves to:35 * {36 * "revision": "12",37 * "location": {38 * "name": "Nemal Tel Aviv Street",39 * "fax": "",40 * "timeZone": "Europe/Dublin",41 * "email": "",42 * "phone": "",43 * "address": {44 * "formatted": "Tel Aviv Port, Nemal Tel Aviv Street, Tel Aviv, Israel",45 * "location": {46 * "latitude": 32.0972612,47 * "longitude": 34.7737654999999948 * },49 * "streetAddress": {50 * "name": "Nemal Tel Aviv Street",51 * "number": "",52 * "apt": ""53 * },54 * "city": "Tel Aviv-Yafo",55 * "country": "IL"56 * },57 * "businessSchedule": {58 * "periods": [59 * {60 * "openDay": "SUNDAY",61 * "openTime": "00:00",62 * "closeDay": "MONDAY",63 * "closeTime": "00:00"64 * },65 * {66 * "openDay": "THURSDAY",67 * "openTime": "00:00",68 * "closeDay": "SUNDAY",69 * "closeTime": "00:00"70 * }71 * ],72 * "specialHourPeriod": []73 * },74 * "_id": "f1f59093-6842-45a4-b9d1-106429ec8313"75 * },76 * "configuration": {77 * "onlineReservations": {78 * "seatPacing": {79 * "number": 11,80 * "enabled": false81 * },82 * "partyPacing": {83 * "number": 6,84 * "enabled": true85 * },86 * "partiesSize": {87 * "min": 1,88 * "max": 689 * },90 * "partySize": {91 * "min": 1,92 * "max": 693 * },94 * "minimumReservationNotice": {95 * "number": 40,96 * "unit": "MINUTES"97 * },98 * "defaultTurnoverTime": 90,99 * "turnoverTimeRules": [],100 * "turnoverRules": [],101 * "businessSchedule": {102 * "periods": [103 * {104 * "openDay": "SUNDAY",105 * "openTime": "00:00",106 * "closeDay": "TUESDAY",107 * "closeTime": "00:00"108 * },109 * {110 * "openDay": "WEDNESDAY",111 * "openTime": "00:00",112 * "closeDay": "THURSDAY",113 * "closeTime": "00:00"114 * },115 * {116 * "openDay": "FRIDAY",117 * "openTime": "00:00",118 * "closeDay": "SUNDAY",119 * "closeTime": "00:00"120 * }121 * ],122 * "specialHourPeriod": []123 * },124 * "onlineReservationsEnabled": false125 * },126 * "reservationForm": {127 * "customFieldDefinitions": [128 * {129 * "name": "Allergies",130 * "required": false,131 * "_id": "f4283b2d-6340-4cf9-bae7-8769e6b62127"132 * }133 * ]134 * },135 * "myReservationsFields": [136 * {137 * "fieldType": "TABLE",138 * "shown": true139 * },140 * {141 * "fieldType": "START_DATE",142 * "shown": true143 * },144 * {145 * "fieldType": "END_DATE",146 * "shown": true147 * },148 * {149 * "fieldType": "CREATED_DATE",150 * "shown": true151 * },152 * {153 * "fieldType": "UPDATED_DATE",154 * "shown": true155 * },156 * {157 * "fieldType": "PARTY_SIZE",158 * "shown": true159 * },160 * {161 * "fieldType": "FIRST_NAME",162 * "shown": true163 * },164 * {165 * "fieldType": "LAST_NAME",166 * "shown": true167 * },168 * {169 * "fieldType": "EMAIL",170 * "shown": true171 * },172 * {173 * "fieldType": "PHONE",174 * "shown": true175 * },176 * {177 * "fieldType": "ADDITIONAL_INFO",178 * "shown": true179 * },180 * {181 * "fieldType": "TEAM_MESSAGE",182 * "shown": true183 * },184 * {185 * "fieldType": "STATUS",186 * "shown": true187 * },188 * {189 * "fieldType": "CUSTOM_FIELD",190 * "customFieldId": "f4283b2d-6340-4cf9-bae7-8769e6b62127",191 * "shown": false192 * }193 * ],194 * "tableManagement": {195 * "tableDefinitions": [196 * {197 * "name": "Small table",198 * "seatsMin": 1,199 * "seatsMax": 4,200 * "isActive": true,201 * "_id": "1ed802ae-708f-4da6-9177-54c3df5d3dd5"202 * },203 * {204 * "name": "Big table",205 * "seatsMin": 3,206 * "seatsMax": 6,207 * "isActive": true,208 * "_id": "2c8aed3a-20c5-404c-b075-84a92f90a996"209 * }210 * ],211 * "deletedTableDefinitions": [],212 * "tableCombinations": [213 * {214 * "tableIds": [215 * "1ed802ae-708f-4da6-9177-54c3df5d3dd5",216 * "2c8aed3a-20c5-404c-b075-84a92f90a996"217 * ],218 * "seatsMin": 7,219 * "seatsMax": 10,220 * "isActive": true,221 * "_id": "6df9a875-d30d-4c0f-9faa-0a5ae18cd6f6"222 * }223 * ]224 * }225 * },226 * "default": true,227 * "archived": false,228 * "_id": "fab8cc1f-31cf-462f-b5bb-392594624bf2",229 * "_createdDate": "2023-07-10T09:06:07.507Z",230 * "_updatedDate": "2024-01-10T11:13:37.920Z"231 * }232 */233
This scenario sets up an interface that allows a site owner to update minimumReservationNotice
in all their reservation locations at once.
1/* This example requires the following elements:2 * A slider element named `noticeSlider`.3 * A button named `setMinNoticeButton` with an onClick() event handler named `setMinNoticeButton_click`.4 */56/**********************************************7 * Backend code - reservationLocations.web.js *8 **********************************************/910import { Permissions, webMethod } from 'wix-web-module';11import { reservationLocations } from 'wix-table-reservations.v2';12import { elevate } from 'wix-auth';1314export const updateRestaurantDetails = webMethod(Permissions.Anyone, async (reservationLocationId, reservationLocationObject) => {15 const elevatedUpdateReservationLocation = elevate(reservationLocations.updateReservationLocation);1617 try {18 const result = await elevatedUpdateReservationLocation(reservationLocationId, reservationLocationObject);19 return result;20 } catch (error) {21 console.error(error);22 // Handle the error23 }24});2526export const listRestaurantLocations = webMethod(Permissions.Anyone, async (options) => {27 const elevatedListReservationLocations = elevate(reservationLocations.listReservationLocations);2829 try {30 const result = await elevatedListReservationLocations(options);31 return result;32 } catch (error) {33 console.error(error);34 // Handle the error35 }36});3738/*************39 * Page code *40 *************/4142import { listRestaurantLocations, updateRestaurantDetails } from 'backend/reservationLocations.web.js';4344export async function setMinNoticeButton_click(event) {45 const options = {46 "fieldsets": ["FULL"],47 };4849 const locationList = await listRestaurantLocations(options);5051 //Loop through each reservationLocation and update `minimumReservationNotice`52 for (const item in locationList.reservationLocations) {53 const selectedLocation = locationList.reservationLocations[item];5455 selectedLocation.configuration.onlineReservations.minimumReservationNotice = {56 "number": $w("#noticeSlider").value,57 "unit": "MINUTES"58 };5960 await updateRestaurantDetails(selectedLocation._id, selectedLocation);61 }62}63
This function requires additional permissions and can only be called without elevation from a dashboard page
1import { myUpdateReservationLocationFunction } from 'backend/reservationLocations.jsw';23/* Sample reservationLocationId value: 'fab8cc1f-31cf-462f-b5bb-392594624bf2'4 *5 * Sample reservationLocationObject value:6 * {7 * "revision": "11",8 * "configuration": {9 * "onlineReservations": {10 * "minimumReservationNotice": {11 * "number": 40,12 * "unit": "MINUTES"13 * },14 * "onlineReservationsEnabled": false15 * }16 * }17 * }18 */1920reservationLocations.updateReservationLocation(reservationLocationId, reservationLocationObject)21 .then((updatedReservationLocation) => {22 const address = updatedReservationLocation.default;23 const minNotice = updatedReservationLocation.configuration.onlineReservations.minimumReservationNotice;2425 console.log('Success! Updated reservation location:', updatedReservationLocation);26 return updatedReservationLocation;27 })28 .catch((error) => {29 console.error(error);30 // Handle the error31 });3233/* Promise resolves to:34 * {35 * "revision": "12",36 * "location": {37 * "name": "Nemal Tel Aviv Street",38 * "fax": "",39 * "timeZone": "Europe/Dublin",40 * "email": "",41 * "phone": "",42 * "address": {43 * "formatted": "Tel Aviv Port, Nemal Tel Aviv Street, Tel Aviv, Israel",44 * "location": {45 * "latitude": 32.0972612,46 * "longitude": 34.7737654999999947 * },48 * "streetAddress": {49 * "name": "Nemal Tel Aviv Street",50 * "number": "",51 * "apt": ""52 * },53 * "city": "Tel Aviv-Yafo",54 * "country": "IL"55 * },56 * "businessSchedule": {57 * "periods": [58 * {59 * "openDay": "SUNDAY",60 * "openTime": "00:00",61 * "closeDay": "MONDAY",62 * "closeTime": "00:00"63 * },64 * {65 * "openDay": "THURSDAY",66 * "openTime": "00:00",67 * "closeDay": "SUNDAY",68 * "closeTime": "00:00"69 * }70 * ],71 * "specialHourPeriod": []72 * },73 * "_id": "f1f59093-6842-45a4-b9d1-106429ec8313"74 * },75 * "configuration": {76 * "onlineReservations": {77 * "seatPacing": {78 * "number": 11,79 * "enabled": false80 * },81 * "partyPacing": {82 * "number": 6,83 * "enabled": true84 * },85 * "partiesSize": {86 * "min": 1,87 * "max": 688 * },89 * "partySize": {90 * "min": 1,91 * "max": 692 * },93 * "minimumReservationNotice": {94 * "number": 40,95 * "unit": "MINUTES"96 * },97 * "defaultTurnoverTime": 90,98 * "turnoverTimeRules": [],99 * "turnoverRules": [],100 * "businessSchedule": {101 * "periods": [102 * {103 * "openDay": "SUNDAY",104 * "openTime": "00:00",105 * "closeDay": "TUESDAY",106 * "closeTime": "00:00"107 * },108 * {109 * "openDay": "WEDNESDAY",110 * "openTime": "00:00",111 * "closeDay": "THURSDAY",112 * "closeTime": "00:00"113 * },114 * {115 * "openDay": "FRIDAY",116 * "openTime": "00:00",117 * "closeDay": "SUNDAY",118 * "closeTime": "00:00"119 * }120 * ],121 * "specialHourPeriod": []122 * },123 * "onlineReservationsEnabled": false124 * },125 * "reservationForm": {126 * "customFieldDefinitions": [127 * {128 * "name": "Allergies",129 * "required": false,130 * "_id": "f4283b2d-6340-4cf9-bae7-8769e6b62127"131 * }132 * ]133 * },134 * "myReservationsFields": [135 * {136 * "fieldType": "TABLE",137 * "shown": true138 * },139 * {140 * "fieldType": "START_DATE",141 * "shown": true142 * },143 * {144 * "fieldType": "END_DATE",145 * "shown": true146 * },147 * {148 * "fieldType": "CREATED_DATE",149 * "shown": true150 * },151 * {152 * "fieldType": "UPDATED_DATE",153 * "shown": true154 * },155 * {156 * "fieldType": "PARTY_SIZE",157 * "shown": true158 * },159 * {160 * "fieldType": "FIRST_NAME",161 * "shown": true162 * },163 * {164 * "fieldType": "LAST_NAME",165 * "shown": true166 * },167 * {168 * "fieldType": "EMAIL",169 * "shown": true170 * },171 * {172 * "fieldType": "PHONE",173 * "shown": true174 * },175 * {176 * "fieldType": "ADDITIONAL_INFO",177 * "shown": true178 * },179 * {180 * "fieldType": "TEAM_MESSAGE",181 * "shown": true182 * },183 * {184 * "fieldType": "STATUS",185 * "shown": true186 * },187 * {188 * "fieldType": "CUSTOM_FIELD",189 * "customFieldId": "f4283b2d-6340-4cf9-bae7-8769e6b62127",190 * "shown": false191 * }192 * ],193 * "tableManagement": {194 * "tableDefinitions": [195 * {196 * "name": "Small table",197 * "seatsMin": 1,198 * "seatsMax": 4,199 * "isActive": true,200 * "_id": "1ed802ae-708f-4da6-9177-54c3df5d3dd5"201 * },202 * {203 * "name": "Big table",204 * "seatsMin": 3,205 * "seatsMax": 6,206 * "isActive": true,207 * "_id": "2c8aed3a-20c5-404c-b075-84a92f90a996"208 * }209 * ],210 * "deletedTableDefinitions": [],211 * "tableCombinations": [212 * {213 * "tableIds": [214 * "1ed802ae-708f-4da6-9177-54c3df5d3dd5",215 * "2c8aed3a-20c5-404c-b075-84a92f90a996"216 * ],217 * "seatsMin": 7,218 * "seatsMax": 10,219 * "isActive": true,220 * "_id": "6df9a875-d30d-4c0f-9faa-0a5ae18cd6f6"221 * }222 * ]223 * }224 * },225 * "default": true,226 * "archived": false,227 * "_id": "fab8cc1f-31cf-462f-b5bb-392594624bf2",228 * "_createdDate": "2023-07-10T09:06:07.507Z",229 * "_updatedDate": "2024-01-10T11:13:37.920Z"230 * }231 */232
This scenario sets up an interface that allows a site owner to select a reservation location and a date, and then close the restaurant on that date. We start by creating a day-long special hour period during which reservations can't be made. We then cancel all reservations on that date.
1/* This example requires the following elements:2 * A dropdown element named `locationDropdown`.3 * A date picker element named 'datePicker`.4 * A button named `confirmButton`.5 * A text element named `cancellationNotice`.6 */78/**********************************************9 * Backend code - reservationLocations.web.js *10 **********************************************/1112import { Permissions, webMethod } from 'wix-web-module';13import { reservationLocations } from 'wix-table-reservations.v2';14import { locations } from 'wix-business-tools.v2';15import { elevate } from 'wix-auth';1617export const getRestaurantLocation = webMethod(Permissions.Anyone, async (location_id) => {18 const elevatedGetLocation = elevate(locations.getLocation);1920 try {21 const result = await elevatedGetLocation(location_id);22 return result;23 } catch (error) {24 console.error(error);25 // Handle the error26 }27});2829export const getRestaurantDetails = webMethod(Permissions.Anyone, async (reservationLocationId, options) => {30 const elevatedGetReservationLocations = elevate(reservationLocations.getReservationLocation);3132 try {33 const result = await elevatedGetReservationLocations(reservationLocationId, options);34 return result;35 } catch (error) {36 console.error(error);37 // Handle the error38 }39});4041export const updateRestaurantDetails = webMethod(Permissions.Anyone, async (reservationLocationId, reservationLocationObject) => {42 const elevatedUpdateReservationLocation = elevate(reservationLocations.updateReservationLocation);4344 try {45 const result = await elevatedUpdateReservationLocation(reservationLocationId, reservationLocationObject);46 return result;47 } catch (error) {48 console.error(error);49 // Handle the error50 }51});5253/*******************************************54 * Backend code - reservations.web.js *55 *******************************************/5657import { Permissions, webMethod } from 'wix-web-module';58import { reservations } from 'wix-table-reservations.v2';59import { elevate } from 'wix-auth';6061export const queryReservationsInDateRange = webMethod(Permissions.Anyone, async (startDate, endDate) => {62 const elevatedQueryReservations = elevate(reservations.queryReservations);6364 try {65 const result = await elevatedQueryReservations()66 .ge('details.startDate', startDate)67 .lt('details.startDate', endDate)68 .find();69 return result;70 } catch (error) {71 console.error(error);72 // Handle the error73 }74});7576/*************77 * Page code *78 *************/7980import { reservationLocations } from 'wix-table-reservations.v2';81import { reservations } from 'wix-table-reservations.v2';8283import { getRestaurantLocation } from 'backend/reservationLocations.web.js';84import { getRestaurantDetails } from 'backend/reservationLocations.web.js';85import { updateRestaurantDetails } from 'backend/reservationLocations.web.js';86import { queryReservationsInDateRange } from 'backend/reservations.web.js';878889$w.onReady(async function () {90 $w('#datePicker').hide();91 $w('#confirmButton').hide();92 $w('#cancellationNotice').hide();9394 // Set the earliest selectable date to the day after the current date95 var tomorrowsDate = new Date();96 tomorrowsDate.setDate(tomorrowsDate.getDate() + 1);97 $w('#datePicker').minDate = tomorrowsDate;98 $w('#datePicker').value = tomorrowsDate;99100 //Get the list of reservation locations101 const myReservationLocationList = await (async () => {102 try {103 let fullListObject = await reservationLocations.listReservationLocations();104 return fullListObject.reservationLocations;105 } catch (error) {106 console.error(error);107 // Handle the error108 }109 })();110111 //Create an array to hold names and values for our dropdown list112 let dropdownOptions = [];113 for (const object in myReservationLocationList){114 //Use the _id stored in the reservation location's location object to get the location's name from the `locations` service115 const locationObject = await getRestaurantLocation(myReservationLocationList[object].location._id);116 dropdownOptions.push({117 "label": locationObject.name,118 "value": myReservationLocationList[object]._id119 })120 }121 //Populate our dropdown list with the array122 $w("#locationDropdown").options = dropdownOptions;123124 $w('#locationDropdown').onChange( (event) => {125 if ($w('#locationDropdown').value) {126 $w('#datePicker').show();127 $w('#confirmButton').show();128 }129 });130131 $w('#confirmButton').onClick( async (event) => {132 const options = {133 "fieldsets": "FULL"134 }135 const selectedLocation = await getRestaurantDetails($w('#locationDropdown').value, options)136137 //Create a new special hour period to push to the list in our reservation location's business schedule138 const selectedDate = $w('#datePicker').value;139 const dayAfterSelectedDate = new Date(selectedDate);140 dayAfterSelectedDate.setDate(selectedDate.getDate() + 1);141 const mySpecialHourPeriod = {142 "startDate": selectedDate,143 "endDate": dayAfterSelectedDate,144 "isClosed": true145 }146147 if(!("businessSchedule" in selectedLocation.configuration.onlineReservations)){148 //Handle business schedule configuration149 }150 selectedLocation.configuration.onlineReservations.businessSchedule.specialHourPeriod.push(mySpecialHourPeriod);151152 await updateRestaurantDetails(selectedLocation._id, selectedLocation);153154 //Create a variable to hold of names and phone numbers of canceled reservations.155 let canceledReservationsNote = "Notify of cancellation:\n";156157 //Query for reservations on the selected date and cancel any at our selected reservation location158 let reservationsOnSelectedDate = await queryReservationsInDateRange(selectedDate, dayAfterSelectedDate);159 for(let reservation in reservationsOnSelectedDate._items){160 if(reservationsOnSelectedDate._items[reservation].details.reservationLocationId == selectedLocation._id){161 let options = {162 "phone" : reservationsOnSelectedDate._items[reservation].reservee.phone163 }164165 const canceledReservation = await (async () => {166 try {167 return reservations.cancelReservation(reservationsOnSelectedDate._items[reservation]._id, reservationsOnSelectedDate._items[reservation].revision, options)168 } catch (error) {169 console.error(error);170 // Handle the error171 return false;172 }173 })();174175 if(canceledReservation){176 canceledReservationsNote += "First name: " + reservationsOnSelectedDate._items[reservation].reservee.firstName +177 ". Last name: " + reservationsOnSelectedDate._items[reservation].reservee.lastName +178 ". Phone: " + reservationsOnSelectedDate._items[reservation].reservee.phone + "\n";179 }180 }181 }182183 $w('#cancellationNotice').text = canceledReservationsNote;184 $w('#cancellationNotice').show();185 });186});187