Search.../

updateReservationLocation( )

Developer Preview

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.

Admin Method

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
_id
string

Reservation location ID.

reservationLocation
UpdateReservationLocation

Reservation location information to update.

Returns

The updated reservation location.

Return Type:

Promise<
ReservationLocation
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

The date and time this reservation location was created.

_id
string

Reservation location ID.

_updatedDate
Date

The date and time this reservation location was last updated.

archived
boolean

Whether this reservation location's location is archived.

configuration
Configuration

Reservation location configuration.

default
boolean

Whether this reservation location's location is the default location of the business.

location
Location

Physical location details.

Locations can be created and configured using the Locations API or on the Business Info page in the Dashboard.

revision
string

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?

Update a reservation location (backend)

This function call requires elevation to get the necessary permissions

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { reservationLocations } from 'wix-table-reservations.v2';
3import { elevate } from 'wix-auth';
4
5/* 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": false
17 * }
18 * }
19 * }
20 */
21
22export const myUpdateReservationLocationFunction = webMethod(Permissions.Anyone, async (reservationLocationId, reservationLocationObject) => {
23 const elevatedUpdateReservationLocation = elevate(reservationLocations.updateReservationLocation);
24
25 try {
26 const result = await elevatedUpdateReservationLocation(reservationLocationId, reservationLocationObject);
27 return result;
28 } catch (error) {
29 console.error(error);
30 // Handle the error
31 }
32});
33
34/* 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.77376549999999
48 * },
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": false
81 * },
82 * "partyPacing": {
83 * "number": 6,
84 * "enabled": true
85 * },
86 * "partiesSize": {
87 * "min": 1,
88 * "max": 6
89 * },
90 * "partySize": {
91 * "min": 1,
92 * "max": 6
93 * },
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": false
125 * },
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": true
139 * },
140 * {
141 * "fieldType": "START_DATE",
142 * "shown": true
143 * },
144 * {
145 * "fieldType": "END_DATE",
146 * "shown": true
147 * },
148 * {
149 * "fieldType": "CREATED_DATE",
150 * "shown": true
151 * },
152 * {
153 * "fieldType": "UPDATED_DATE",
154 * "shown": true
155 * },
156 * {
157 * "fieldType": "PARTY_SIZE",
158 * "shown": true
159 * },
160 * {
161 * "fieldType": "FIRST_NAME",
162 * "shown": true
163 * },
164 * {
165 * "fieldType": "LAST_NAME",
166 * "shown": true
167 * },
168 * {
169 * "fieldType": "EMAIL",
170 * "shown": true
171 * },
172 * {
173 * "fieldType": "PHONE",
174 * "shown": true
175 * },
176 * {
177 * "fieldType": "ADDITIONAL_INFO",
178 * "shown": true
179 * },
180 * {
181 * "fieldType": "TEAM_MESSAGE",
182 * "shown": true
183 * },
184 * {
185 * "fieldType": "STATUS",
186 * "shown": true
187 * },
188 * {
189 * "fieldType": "CUSTOM_FIELD",
190 * "customFieldId": "f4283b2d-6340-4cf9-bae7-8769e6b62127",
191 * "shown": false
192 * }
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
Update the minimum required notice for reservations at all locations

This scenario sets up an interface that allows a site owner to update minimumReservationNotice in all their reservation locations at once.

Copy Code
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 */
5
6/**********************************************
7 * Backend code - reservationLocations.web.js *
8 **********************************************/
9
10import { Permissions, webMethod } from 'wix-web-module';
11import { reservationLocations } from 'wix-table-reservations.v2';
12import { elevate } from 'wix-auth';
13
14export const updateRestaurantDetails = webMethod(Permissions.Anyone, async (reservationLocationId, reservationLocationObject) => {
15 const elevatedUpdateReservationLocation = elevate(reservationLocations.updateReservationLocation);
16
17 try {
18 const result = await elevatedUpdateReservationLocation(reservationLocationId, reservationLocationObject);
19 return result;
20 } catch (error) {
21 console.error(error);
22 // Handle the error
23 }
24});
25
26export const listRestaurantLocations = webMethod(Permissions.Anyone, async (options) => {
27 const elevatedListReservationLocations = elevate(reservationLocations.listReservationLocations);
28
29 try {
30 const result = await elevatedListReservationLocations(options);
31 return result;
32 } catch (error) {
33 console.error(error);
34 // Handle the error
35 }
36});
37
38/*************
39 * Page code *
40 *************/
41
42import { listRestaurantLocations, updateRestaurantDetails } from 'backend/reservationLocations.web.js';
43
44export async function setMinNoticeButton_click(event) {
45 const options = {
46 "fieldsets": ["FULL"],
47 };
48
49 const locationList = await listRestaurantLocations(options);
50
51 //Loop through each reservationLocation and update `minimumReservationNotice`
52 for (const item in locationList.reservationLocations) {
53 const selectedLocation = locationList.reservationLocations[item];
54
55 selectedLocation.configuration.onlineReservations.minimumReservationNotice = {
56 "number": $w("#noticeSlider").value,
57 "unit": "MINUTES"
58 };
59
60 await updateRestaurantDetails(selectedLocation._id, selectedLocation);
61 }
62}
63
Update a reservation location (dashboard page)

This function requires additional permissions and can only be called without elevation from a dashboard page

Copy Code
1import { myUpdateReservationLocationFunction } from 'backend/reservationLocations.jsw';
2
3/* 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": false
15 * }
16 * }
17 * }
18 */
19
20reservationLocations.updateReservationLocation(reservationLocationId, reservationLocationObject)
21 .then((updatedReservationLocation) => {
22 const address = updatedReservationLocation.default;
23 const minNotice = updatedReservationLocation.configuration.onlineReservations.minimumReservationNotice;
24
25 console.log('Success! Updated reservation location:', updatedReservationLocation);
26 return updatedReservationLocation;
27 })
28 .catch((error) => {
29 console.error(error);
30 // Handle the error
31 });
32
33/* 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.77376549999999
47 * },
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": false
80 * },
81 * "partyPacing": {
82 * "number": 6,
83 * "enabled": true
84 * },
85 * "partiesSize": {
86 * "min": 1,
87 * "max": 6
88 * },
89 * "partySize": {
90 * "min": 1,
91 * "max": 6
92 * },
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": false
124 * },
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": true
138 * },
139 * {
140 * "fieldType": "START_DATE",
141 * "shown": true
142 * },
143 * {
144 * "fieldType": "END_DATE",
145 * "shown": true
146 * },
147 * {
148 * "fieldType": "CREATED_DATE",
149 * "shown": true
150 * },
151 * {
152 * "fieldType": "UPDATED_DATE",
153 * "shown": true
154 * },
155 * {
156 * "fieldType": "PARTY_SIZE",
157 * "shown": true
158 * },
159 * {
160 * "fieldType": "FIRST_NAME",
161 * "shown": true
162 * },
163 * {
164 * "fieldType": "LAST_NAME",
165 * "shown": true
166 * },
167 * {
168 * "fieldType": "EMAIL",
169 * "shown": true
170 * },
171 * {
172 * "fieldType": "PHONE",
173 * "shown": true
174 * },
175 * {
176 * "fieldType": "ADDITIONAL_INFO",
177 * "shown": true
178 * },
179 * {
180 * "fieldType": "TEAM_MESSAGE",
181 * "shown": true
182 * },
183 * {
184 * "fieldType": "STATUS",
185 * "shown": true
186 * },
187 * {
188 * "fieldType": "CUSTOM_FIELD",
189 * "customFieldId": "f4283b2d-6340-4cf9-bae7-8769e6b62127",
190 * "shown": false
191 * }
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
Close a restaurant and cancel all reservations on a given day

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.

Copy Code
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 */
7
8/**********************************************
9 * Backend code - reservationLocations.web.js *
10 **********************************************/
11
12import { 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';
16
17export const getRestaurantLocation = webMethod(Permissions.Anyone, async (location_id) => {
18 const elevatedGetLocation = elevate(locations.getLocation);
19
20 try {
21 const result = await elevatedGetLocation(location_id);
22 return result;
23 } catch (error) {
24 console.error(error);
25 // Handle the error
26 }
27});
28
29export const getRestaurantDetails = webMethod(Permissions.Anyone, async (reservationLocationId, options) => {
30 const elevatedGetReservationLocations = elevate(reservationLocations.getReservationLocation);
31
32 try {
33 const result = await elevatedGetReservationLocations(reservationLocationId, options);
34 return result;
35 } catch (error) {
36 console.error(error);
37 // Handle the error
38 }
39});
40
41export const updateRestaurantDetails = webMethod(Permissions.Anyone, async (reservationLocationId, reservationLocationObject) => {
42 const elevatedUpdateReservationLocation = elevate(reservationLocations.updateReservationLocation);
43
44 try {
45 const result = await elevatedUpdateReservationLocation(reservationLocationId, reservationLocationObject);
46 return result;
47 } catch (error) {
48 console.error(error);
49 // Handle the error
50 }
51});
52
53/*******************************************
54 * Backend code - reservations.web.js *
55 *******************************************/
56
57import { Permissions, webMethod } from 'wix-web-module';
58import { reservations } from 'wix-table-reservations.v2';
59import { elevate } from 'wix-auth';
60
61export const queryReservationsInDateRange = webMethod(Permissions.Anyone, async (startDate, endDate) => {
62 const elevatedQueryReservations = elevate(reservations.queryReservations);
63
64 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 error
73 }
74});
75
76/*************
77 * Page code *
78 *************/
79
80import { reservationLocations } from 'wix-table-reservations.v2';
81import { reservations } from 'wix-table-reservations.v2';
82
83import { 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';
87
88
89$w.onReady(async function () {
90 $w('#datePicker').hide();
91 $w('#confirmButton').hide();
92 $w('#cancellationNotice').hide();
93
94 // Set the earliest selectable date to the day after the current date
95 var tomorrowsDate = new Date();
96 tomorrowsDate.setDate(tomorrowsDate.getDate() + 1);
97 $w('#datePicker').minDate = tomorrowsDate;
98 $w('#datePicker').value = tomorrowsDate;
99
100 //Get the list of reservation locations
101 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 error
108 }
109 })();
110
111 //Create an array to hold names and values for our dropdown list
112 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` service
115 const locationObject = await getRestaurantLocation(myReservationLocationList[object].location._id);
116 dropdownOptions.push({
117 "label": locationObject.name,
118 "value": myReservationLocationList[object]._id
119 })
120 }
121 //Populate our dropdown list with the array
122 $w("#locationDropdown").options = dropdownOptions;
123
124 $w('#locationDropdown').onChange( (event) => {
125 if ($w('#locationDropdown').value) {
126 $w('#datePicker').show();
127 $w('#confirmButton').show();
128 }
129 });
130
131 $w('#confirmButton').onClick( async (event) => {
132 const options = {
133 "fieldsets": "FULL"
134 }
135 const selectedLocation = await getRestaurantDetails($w('#locationDropdown').value, options)
136
137 //Create a new special hour period to push to the list in our reservation location's business schedule
138 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": true
145 }
146
147 if(!("businessSchedule" in selectedLocation.configuration.onlineReservations)){
148 //Handle business schedule configuration
149 }
150 selectedLocation.configuration.onlineReservations.businessSchedule.specialHourPeriod.push(mySpecialHourPeriod);
151
152 await updateRestaurantDetails(selectedLocation._id, selectedLocation);
153
154 //Create a variable to hold of names and phone numbers of canceled reservations.
155 let canceledReservationsNote = "Notify of cancellation:\n";
156
157 //Query for reservations on the selected date and cancel any at our selected reservation location
158 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.phone
163 }
164
165 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 error
171 return false;
172 }
173 })();
174
175 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 }
182
183 $w('#cancellationNotice').text = canceledReservationsNote;
184 $w('#cancellationNotice').show();
185 });
186});
187