Skip to content

fix(kits): custody card showing for partially checked-in kits #2231

Merged
DonKoko merged 2 commits intomainfrom
fix-custody-card-on-partially-checked-in-kits
Dec 4, 2025
Merged

fix(kits): custody card showing for partially checked-in kits #2231
DonKoko merged 2 commits intomainfrom
fix-custody-card-on-partially-checked-in-kits

Conversation

@DonKoko
Copy link
Copy Markdown
Contributor

@DonKoko DonKoko commented Dec 4, 2025

The custody card was incorrectly displaying for kits that had been partially checked in. The getKitCurrentBooking function was returning bookings based only on their ONGOING/OVERDUE status without verifying that the assets were actually checked out.

This fix adds a filter to check asset.status === CHECKED_OUT before considering a booking as current, matching the behavior of the asset detail page. Now the custody card only shows when at least one asset in the kit is actually in custody.

Changes:

  • Add status field to getKitCurrentBooking function signature
  • Filter assets by CHECKED_OUT status before finding bookings
  • Add comprehensive JSDoc and inline comments explaining the logic

The custody card was incorrectly displaying for kits that had been
partially checked in. The getKitCurrentBooking function was returning
bookings based only on their ONGOING/OVERDUE status without verifying
that the assets were actually checked out.

This fix adds a filter to check asset.status === CHECKED_OUT before
considering a booking as current, matching the behavior of the asset
detail page. Now the custody card only shows when at least one asset
in the kit is actually in custody.

Changes:
- Add status field to getKitCurrentBooking function signature
- Filter assets by CHECKED_OUT status before finding bookings
- Add comprehensive JSDoc and inline comments explaining the logic
@vercel
Copy link
Copy Markdown

vercel Bot commented Dec 4, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
shelf-docs Ignored Ignored Dec 4, 2025 10:01am

@DonKoko DonKoko requested a review from Copilot December 4, 2025 10:01
@DonKoko DonKoko self-assigned this Dec 4, 2025
@DonKoko DonKoko added the bug Something isn't working label Dec 4, 2025
@DonKoko DonKoko merged commit d0fe05e into main Dec 4, 2025
11 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where the custody card was incorrectly displaying for kits that had been partially checked in. The fix adds a filter to ensure that only assets with CHECKED_OUT status are considered when determining if a kit has a current booking, preventing the custody card from showing for assets that have ongoing bookings but have been checked back in.

Key Changes:

  • Added status field to asset type in getKitCurrentBooking function signature
  • Added filter to check asset.status === CHECKED_OUT before considering booking status
  • Enhanced documentation with comprehensive JSDoc and inline comments

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
app/modules/kit/service.server.ts Added status filtering logic to getKitCurrentBooking to ensure custody card only shows when assets are actually checked out, plus added JSDoc and inline comments
package-lock.json Lockfile changes from dependency resolution (unrelated to the functional fix)
Comments suppressed due to low confidence (1)

app/modules/kit/service.server.ts:967

  • The function getKitCurrentBooking lacks test coverage. Consider adding unit tests to cover key scenarios:
  1. Kit with checked-out assets having ongoing bookings (should return booking)
  2. Kit with checked-out assets having no bookings (should return undefined)
  3. Kit with assets that are not checked out but have ongoing bookings (should return undefined)
  4. Kit with multiple assets, only some checked out with bookings (should return first valid booking)
  5. Kit with assets having overdue bookings

This is particularly important since the fix addresses a bug where the custody card was incorrectly showing.

export function getKitCurrentBooking(kit: {
  id: string;
  assets: {
    status: AssetStatus;
    bookings: CurrentBookingType[];
  }[];
}) {
  const ongoingBookingAsset = kit.assets
    // Filter each asset's bookings to only ongoing or overdue ones
    .map((a) => ({
      ...a,
      bookings: a.bookings.filter(
        (b) =>
          b.status === BookingStatus.ONGOING ||
          b.status === BookingStatus.OVERDUE
      ),
    }))
    // Only consider assets that are actually checked out
    .filter((a) => a.status === AssetStatus.CHECKED_OUT)
    // Find the first asset that has any ongoing/overdue bookings
    .find((a) => a.bookings.length > 0);

  const ongoingBooking = ongoingBookingAsset
    ? ongoingBookingAsset.bookings[0]
    : undefined;

  return ongoingBooking;
}

Comment thread app/modules/kit/service.server.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants