-
Notifications
You must be signed in to change notification settings - Fork 0
Scc 5050 make async #600
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
base: main
Are you sure you want to change the base?
Scc 5050 make async #600
Conversation
nonword
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good
lib/utils/resource-helpers.js
Outdated
| // Create promise to resolve deliveryLocationTypes by patron type: | ||
| const lookupPatronType = async function (params) { | ||
| try { | ||
| await AvailableDeliveryLocationTypes.getScholarRoomByPatronId(params.patronId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem like this returns anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the only purpose of this function is to throw an error if something goes wrong. Maybe a more descriptive comment would clear that up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like getScholarRoomByPatronId returns a location code, which you use to determine delivery locations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, added a return
| } | ||
| } | ||
|
|
||
| const makeRelevanceReport = (params) => (r, ind) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate that this came from even more confusing code, but let's make it clearer what's happening here through documentation and better var names?
lib/resources.js
Outdated
| itemUri: (uri) => { | ||
| return { term: { 'items.uri': uri } } | ||
| } | ||
| const [resp] = Promise.all([fetchItems, lookupPatronType]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem right. I think you probably want to destructure as const [items, scholarRoomCode] = ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/utils/resource-helpers.js
Outdated
|
|
||
| app.logger.debug('Resources#itemsByFilter', body) | ||
| return app.esClient.search(body) | ||
| .then((resp) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still using promise chaining. can you update to make async/await?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use async and cleaned up
lib/resources.js
Outdated
| itemUri: (uri) => { | ||
| return { term: { 'items.uri': uri } } | ||
| } | ||
| const [resp] = Promise.all([fetchItems, lookupPatronType]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this Promise.all needs to be await-ed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep
Beginning of refactor of
discovery-api, focusing onlib/routesThe goal is to make the
lib/routesfile easier to read, with every method corresponding to a route, and each route-related function being relatively simple.Most of this PR is just moving code out of the
lib/routesfile to util files.In addition, the methods in
lib/routesare rewritten using async/await instead of promises.I'd like to rewrite the
elastic-body-buildermethods as well, but that is only started. In particular the body for finding by uri uses the newinnerHitsmethod instead ofaddInnerHits, but it isn't quite working for the search request, so that method still needsaddInnerHits. Reworking the body builder is still ongoing.