Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] - Add checkoutByTag API endpoint for assets #11417

Merged
merged 6 commits into from
Jun 29, 2022

Conversation

ntbutler-nbcs
Copy link
Contributor

Description

Seeing as asset tags are unique, it should be safe to, and would be useful to be able to call the API and check out an asset using it's asset tag. We have each asset tagged with a barcode, and have an internally developed mobile app to quickly scan user ID cards, then the asset tag.

This extra endpoint means we no longer need to run a separate API call to look up the asset to get it's internal snipe ID first.

This uses essentially the same code from the GET /hardware/bytag/:asset_tag endpoint, and if the asset is found, calls the existing checkout function.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update
    NOTE - there seems to be an undocumented new API endpoint for checkinByTag, which should be updated too.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test API call with existing deployable check-in asset - asset checked out as expected
  • Test API call with existing deployable check-out asset - asset not available to be checked out as expected
  • Test API call with non-existing asset tag - asset not found as expected

Test Configuration:

  • PHP version: 8.0.20
  • MySQL version: 8.0
  • Webserver version: 6.0.2
  • OS version: Windows Server 2019

Checklist:

@welcome
Copy link

welcome bot commented Jun 29, 2022

💖 Thanks for this pull request! 💖

We use semantic commit messages to streamline the release process and easily generate changelogs between versions. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix if it doesn't have one already.

Examples of commit messages with semantic prefixes:

  • Fixed #<issue number>: don't overwrite prevent_default if default wasn't prevented
  • Added #<issue number>: add checkout functionality to assets
  • Improved Asset Checkout: use new notification method for checkout

Things that will help get your PR across the finish line:

  • Document any user-facing changes you've made.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

*/
public function checkoutByTag(AssetCheckoutRequest $request, $tag)
{
if ($asset = Asset::with('assetstatus')->with('assignedTo')->where('asset_tag', $tag)->first()) {
Copy link
Owner

Choose a reason for hiding this comment

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

Do we actually need the with('assetstatus')->with('assignedTo') stuff? The checkout() method already tries to determine if we can check the item out or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely - my bad, I did remove it but at one point, but must have added it back when I was working on my own checkinByTag function (before I found there already was one). Changes applied.

Copy link
Owner

@snipe snipe left a comment

Choose a reason for hiding this comment

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

Some small changes requested

config/version.php Outdated Show resolved Hide resolved
@snipe snipe merged commit 5af6330 into snipe:develop Jun 29, 2022
@welcome
Copy link

welcome bot commented Jun 29, 2022

Congrats on merging your first pull request! 🎉🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants