2

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)

}

Ruwan Bandara
  • 55
  • 1
  • 9

2 Answers2

1

instead of where you need to use where and andWhere

this.where('start_timestamp', '>', start_timestamp).andWhere('end_timestamp', '<', end_timestamp)
Amit Kadivar
  • 798
  • 4
  • 12
0

you can try to use where condition like this:

await Database.from('booking_slots').where({
        {'start_timestamp', '>', start_timestamp},
        {'start_timestamp', '<', end_timestamp} });