make form just simple

This commit is contained in:
Thomas Ruoff
2020-07-29 00:01:54 +02:00
parent a26e58b43e
commit 526c625a57
7 changed files with 116 additions and 119 deletions

View File

@@ -34,16 +34,15 @@ export async function getBookedDays() {
}
export async function createBooking({ name, email, startDate, endDate }) {
const booker = new Booker({ name, email })
await booker.save()
const ignoreCaseEmailMatcher = new RegExp(email, 'i')
let booker = await Booker.findOne({ email: ignoreCaseEmailMatcher }).exec()
if (!booker) {
booker = new Booker({ name, email })
await booker.save()
}
const booking = new Booking({ startDate, endDate, booker: booker._id })
await booking.save()
return {
booker: booking.booker._id,
startDate: booking.startDate,
endDate: booking.endDate,
bookedDate: booking.bookedDate,
confirmed: booking.confirmed,
confirmedDate: booking.confimredDate,
}
await booking.populate('booker').execPopulate()
return booking.toJSON({ getters: true, virtuals: true })
}