-
Notifications
You must be signed in to change notification settings - Fork 27
Refactor getEntry endpoint #310
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
Conversation
a3d0c33 to
09cb85c
Compare
97c7157 to
ac582a5
Compare
| throw new AppError(US_ERRORS.NOT_EXIST_ENTRY, { | ||
| code: US_ERRORS.NOT_EXIST_ENTRY, | ||
| }); |
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.
In this file I just raised the error above to reduce code nesting
src/routes.ts
Outdated
| getEntryV2: makeRoute({ | ||
| route: 'GET /v2/entries/:entryId', | ||
| handler: entries.getEntryV2Controller, | ||
| }), | ||
| privateGetEntry: makeRoute({ | ||
| route: 'GET /private/entries/:entryId', | ||
| handler: entries.getEntry, | ||
| authPolicy: AuthPolicy.disabled, | ||
| private: true, | ||
| }), | ||
| privateGetEntryV2: makeRoute({ | ||
| route: 'GET /v2/private/entries/:entryId', | ||
| handler: entries.getEntryV2Controller, | ||
| authPolicy: AuthPolicy.disabled, | ||
| private: true, | ||
| }), |
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 endpoint has the same contract as the old one, except for includeFavorite param
It seems we can just start sending includeFavorite where necessary in the UI and simply replace the controllers in the old endpoints, i guess we can even switch controllers with flag in US
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 guess we can even switch controllers with flag in US" – good idea
|
|
||
| let userLoginPromise; | ||
| if (includeFavorite) { | ||
| userLoginPromise = user.login ? user.login : getEntryResolveUserLogin({ctx}); |
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.
It works correctly, but is it possible to store only promises in userLoginPromise?
user.login ? Promise.resolve(user.login) : getEntryResolveUserLogin({ctx})
| }; | ||
| } | ||
|
|
||
| case US_ERRORS.OPERATION_TIMEOUT: { |
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.
Operation is used for existing entity, can we use Action or Request here?
src/routes.ts
Outdated
| getEntryV2: makeRoute({ | ||
| route: 'GET /v2/entries/:entryId', | ||
| handler: entries.getEntryV2Controller, | ||
| }), | ||
| privateGetEntry: makeRoute({ | ||
| route: 'GET /private/entries/:entryId', | ||
| handler: entries.getEntry, | ||
| authPolicy: AuthPolicy.disabled, | ||
| private: true, | ||
| }), | ||
| privateGetEntryV2: makeRoute({ | ||
| route: 'GET /v2/private/entries/:entryId', | ||
| handler: entries.getEntryV2Controller, | ||
| authPolicy: AuthPolicy.disabled, | ||
| private: true, | ||
| }), |
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 guess we can even switch controllers with flag in US" – good idea
| .where((builder) => { | ||
| builder.where({ | ||
| [`${Entry.tableName}.entryId`]: entryId, | ||
| [`${Entry.tableName}.isDeleted`]: false, |
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.
It was the same in the old method, but I think we need to add tenantId here, it's checked below but I don't see the point in not checking it right in the select. Maybe @jhoncool knows the reason why we shouldn't do this.
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 don't know but I think it's okay to use it here
| builder.andWhere({mirrored: true}); | ||
| } | ||
| }) | ||
| .withGraphJoined(`[${graphRelations.join(', ')}]`) |
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.
As we discussed, we no longer use withGraphJoined, need to create a new presentation (example #318).
| } else if (branch === 'saved') { | ||
| graphRelations.push('savedRevision(revisionModifier)'); | ||
| } else { | ||
| graphRelations.push('publishedRevision(revisionModifier)'); |
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.
Here should be a fallback to saved revision if the published one does not exist.
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 was wrong, everything works correctly, because we have branch = 'saved' by default
| !isPrivateRoute && !onlyPublic && !onlyMirrored && !isEmbedding; | ||
|
|
||
| if (checkWorkbookEnabled) { | ||
| iamPermissions = await checkWorkbookEntry({ |
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.
Should we wrap the checkWorkbookEntry function with withTimeout?
3d06410 to
3f117fe
Compare
No description provided.