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 9f86f29 commit 40f678f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/flight-booking-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const ResourceManager = require('./resourceManager');

class FlightBookingManager extends Contract {
// variables:
// hash(user)__balance
// hash(user)__balance
// seatOwner_<#>
// seatCount
// bookedSeats
Expand Down Expand Up @@ -121,7 +121,7 @@ class FlightBookingManager extends Contract {
async isSeatBookedByClient(ctx, txId, tm, seatNumber) {
let seatOwner = await this._queryVariable(ctx, txId, 'seatOwner_' + seatNumber, null, tm);

return seatOwner && seatOwner === ctx.clientIdentity.getID();
return seatOwner !== null && seatNumber !== undefined && seatOwner === ctx.clientIdentity.getID();
}

/**
Expand Down Expand Up @@ -177,12 +177,12 @@ class FlightBookingManager extends Contract {
* @returns {Promise<number>}
*/
async queryBookedSeatsCount(ctx, txId, tm) {
var bookedSeatsString = (await this._queryVariable(ctx, txId, 'bookedSeats', '', tm));
let bookedSeatsString = (await this._queryVariable(ctx, txId, 'bookedSeats', '', tm));

if (bookedSeatsString === '') {
return 0;
}

return bookedSeatsString.split(':').length;
}

Expand Down Expand Up @@ -266,7 +266,7 @@ class FlightBookingManager extends Contract {
let ticketPrice = await this.querySeatPrice(ctx, txId, tm);
await this._deductFromClientBalance(ctx, txId, ticketPrice, tm);

var bookedSeatsString = (await this._queryVariable(ctx, txId, 'bookedSeats', '', tm));
let bookedSeatsString = (await this._queryVariable(ctx, txId, 'bookedSeats', '', tm));

if (bookedSeatsString === '') {
bookedSeatsString = seatNumber.toString();
Expand All @@ -286,7 +286,7 @@ class FlightBookingManager extends Contract {
async endFlight(ctx, txId, tm) {
let reservations = await this.queryBookedSeatsCount(ctx, txId, tm);

for (let i = 0; i < reservations - 1; i++) {
for (let i = 0; i < reservations; i++) {
if (!await (new ResourceManager()).setValue(ctx, txId, 'seatOwner_' + i, null, tm)) {
throw new Error('Cannot change seat status. Data item is locked by another transaction!');
}
Expand Down

0 comments on commit 40f678f

Please sign in to comment.