Skip to content

Commit

Permalink
Update flight-booking-manager.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ghareeb-falazi committed Dec 9, 2024
1 parent 10a059e commit 9c5a718
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/flight-booking-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,17 @@ class FlightBookingManager extends Contract {
}

async isSeatAvailable(ctx, txId, tm, seatNumber) {
let seatsCount = await this.querySeatsCount(ctx, txId, tm);
let reserved = await this.queryBookedSeatsCount(ctx, txId, tm);
let seatOwner = await this._queryVariable(ctx, txId, 'seatOwner_' + seatNumber, null, tm);

return seatNumber >= reserved && seatNumber < seatsCount;
return seatOwner !== null && seatNumber !== undefined;
}

async queryNextAvailableSeat(ctx, txId, tm) {
let seatsCount = await this.querySeatsCount(ctx, txId, tm);
let reserved = await this.queryBookedSeatsCount(ctx, txId, tm);

if (seatsCount > reserved) {
return reserved;
let seats = await this.querySeatsCount(ctx, txId, tm);
for (let i = 0; i < seats; i++) {
if (await this.isSeatAvailable(ctx, txId, tm, i)) {
return i;
}
}

return -1;
Expand All @@ -131,8 +130,8 @@ class FlightBookingManager extends Contract {
* @returns {Promise<Boolean>}
*/
async hasReservation(ctx, txId, tm) {
let reservations = await this.queryBookedSeatsCount(ctx, txId, tm);
for (let i = 0; i < reservations; i++) {
let seats = await this.querySeatsCount(ctx, txId, tm);
for (let i = 0; i < seats; i++) {
if (await this.isSeatBookedByClient(ctx, txId, tm, i)) {
return true;
}
Expand Down

0 comments on commit 9c5a718

Please sign in to comment.