Hi
I have the following code to send an update to the server and on success, update some properties of the eventRecord like so
/** Send the request to the server to update the booking */
updateBooking(booking)
.then(async ({ data: { attributes: bookingAttributes } }) => {
/** Once a bookinng is updated, fetch the updated by user details */
const updatedBy = await getBookingUpdatedBy(bookingid);
const updatedAt = bookingAttributes.updatedAt;
/**
* We need to update the following attributes on the eventRecord
* to ensure that they are in sync with the database
*/
const updates = {
duration: bookingAttributes.duration,
endDate: bookingAttributes.endDate,
startDate: bookingAttributes.startDate,
updatedBy,
updatedAt,
};
await eventRecord.setAsync(updates);
})
.catch(err => {
IS_DEV && console.log(err);
console.log('An error occured. Reverting dates for event record.');
/**
* If an error occcured, we reset the eventRecord's
* start and end date
*/
console.log(originalData);
eventRecord.set({
startDate: originalData.startDate,
endDate: originalData.endDate,
});
});
Is there a way to set the originalData to the new data on success? The issue is that if a user makes a second update to the same record and there is an error, the originalData refers to the data on first load.
So is there a way to set the originalData or to revert changes 2 to changes 1?
I look forward to your help.
Regards
David