mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 15:07:13 +01:00
make form just simple
This commit is contained in:
19
db/index.js
19
db/index.js
@@ -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 })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user