Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ghareeb-falazi committed Dec 9, 2024
1 parent 0038b50 commit 1dc9cd8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/flight-booking-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class FlightBookingManager extends Contract {
async isSeatAvailable(ctx, txId, tm, seatNumber) {
let seatOwner = await this._queryVariable(ctx, txId, 'seatOwner_' + seatNumber, null, tm);

return seatOwner === null;
return seatOwner === null || seatOwner === undefined || seatOwner.length === 0;
}

async queryNextAvailableSeat(ctx, txId, tm) {
Expand Down Expand Up @@ -282,10 +282,10 @@ class FlightBookingManager extends Contract {
}

async endFlight(ctx, txId, tm) {
let reservations = await this.queryBookedSeatsCount(ctx, txId, tm);
let seats = await this.querySeatsCount(ctx, txId, tm);

for (let i = 0; i < reservations; i++) {
if (!await (new ResourceManager()).setValue(ctx, txId, 'seatOwner_' + i, null, tm)) {
for (let i = 0; i < seats; i++) {
if (!await (new ResourceManager()).setValue(ctx, txId, 'seatOwner_' + i, '', tm)) {
throw new Error('Cannot change seat status. Data item is locked by another transaction!');
}
}
Expand Down
5 changes: 4 additions & 1 deletion lib/resourceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ class ResourceManager extends Contract {

if (tx) {
const tm = tx.getTm();
const tmClientName = tm.split(',').filter(x => x[0] === 'C' && x[1] === 'N')[0].split('=')[1];
const currentClientName = ctx.clientIdentity.getID().split('::')[1].split('/').filter(x => x[0] === 'C' && x[1] === 'N')[0].split('=')[1];

if (tm !== ctx.clientIdentity.getID()) {

if (tmClientName !== currentClientName) {
throw new Error('Message sender (' + ctx.clientIdentity.getID() + ') is not the designated transaction manager of global transaction!');
}
} else {
Expand Down

0 comments on commit 1dc9cd8

Please sign in to comment.