Reputation: 65
I am trying to book create a time slot and find between time in two-time value this code is always returned value 0.
async store({request, auth, response}) {
let {uuid, start_timestamp, end_timestamp, price} = request.all();
try {
let influencer = await auth.getUser();
let avaliabelBookinSlot = await Database.from('booking_slots')
.where('influencer_id', influencer.id)
.where(function () {
this
.where(function () {
this
.where('start_timestamp', '>', start_timestamp)
.where('start_timestamp', '<', end_timestamp)
}).orWhere(function () {
this
.where('end_timestamp', '>', start_timestamp)
.where('end_timestamp', '<', end_timestamp)
})
}).orWhere(function () {
this
.where('start_timestamp', '>', start_timestamp)
.where('end_timestamp', '<', end_timestamp)
})
console.log(avaliabelBookinSlot.length)
}
Upvotes: 3
Views: 519
Reputation: 818
instead of where you need to use where and andWhere
this.where('start_timestamp', '>', start_timestamp).andWhere('end_timestamp', '<', end_timestamp)
Upvotes: 1
Reputation: 93
you can try to use where condition like this:
await Database.from('booking_slots').where({
{'start_timestamp', '>', start_timestamp},
{'start_timestamp', '<', end_timestamp} });
Upvotes: 0