fix(kits): custody card showing for partially checked-in kits #2231
Merged
fix(kits): custody card showing for partially checked-in kits #2231
Conversation
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 latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
There was a problem hiding this comment.
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
statusfield to asset type ingetKitCurrentBookingfunction signature - Added filter to check
asset.status === CHECKED_OUTbefore 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
getKitCurrentBookinglacks test coverage. Consider adding unit tests to cover key scenarios:
- Kit with checked-out assets having ongoing bookings (should return booking)
- Kit with checked-out assets having no bookings (should return undefined)
- Kit with assets that are not checked out but have ongoing bookings (should return undefined)
- Kit with multiple assets, only some checked out with bookings (should return first valid booking)
- 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;
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The custody card was incorrectly displaying for kits that had been partially checked in. The
getKitCurrentBookingfunction 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_OUTbefore 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:
getKitCurrentBookingfunction signatureCHECKED_OUTstatus before finding bookings