Skip to content

Commit

Permalink
unitItems can't be empty when patching booking
Browse files Browse the repository at this point in the history
  • Loading branch information
mogii committed Mar 13, 2024
1 parent c2b08c8 commit 16f1d98
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,18 +378,22 @@ class Plugin {
})) : [];
// for answers to custom fields, ventrata suggest to modify the booking
if (answers.length) {
const modifierBooking = {
let modifierBooking = {
questionAnswers: booking.questionAnswers.map(o => {
const answer = answers.find(a => a.questionId === o.questionId);
return answer || o;
}),
unitItems: booking.unitItems.map(u => ({
...u,
questionAnswers: u.questionAnswers.map(o => {
const answer = answers.find(a => a.questionId === o.questionId);
return answer || o;
}),
})).filter(u => u.questionAnswers.length),
})),
};
if (!modifierBooking.unitItems.find(u => u.questionAnswers && u.questionAnswers.length)) {
modifierBooking = R.omit(['unitItems'], modifierBooking);
}
booking = R.path(['data'], await axios({
method: 'patch',
url: `${endpoint || this.endpoint}/bookings/${booking.uuid}`,
Expand Down

0 comments on commit 16f1d98

Please sign in to comment.