-
Notifications
You must be signed in to change notification settings - Fork 87
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
ref: migrate fetch form submission counts flow to Typescript #592
Conversation
56d8b9b
to
0129b96
Compare
0129b96
to
52d7771
Compare
} | ||
|
||
// Successfully retrieved count. | ||
return res.json(countResult.value) |
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.
if we use isErr
like this, isn't it basically as good as try
-catch
? do you think it might be cleaner to actually chain the results and use a single map
and mapErr
at the end?
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's different from try-catch though. To reach the next step, you have to actively unwrap the Result
unlike in try catch where devs may forget to throw.
Doing it this way allows for better error logs, though it also makes sense to chain them and map/mapErr since the service themselves already logs errors
Thoughts, @liangyuanruo?
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 imo it's fine for the logs to get more generic at higher and higher layers, as long as each layer is responsible for logging the error. I think it's better to have cleaner code here by taking advantage of chaining, since there's no significant benefit to having duplicative log messages between the controller and service.
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.
We just go back and forth, the initial implementation was chaining, then it became distinct steps, then etc etc HAHAHA. I'll go with this for now, can always open a PR to chain it again. Too many rebases now :P
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.
yup this is ok with me too, as long as the Result
type is narrowed by testing with isErr()
. I wouldn't want to be too opinionated here.
52d7771
to
711315b
Compare
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.
lgtm, the question on chaining is still outstanding but not a dealbreaker
Util function to check whether given user has read permissions to given form
`with` allows for a query with only `endDate` since only `startDate` is required, which is wrong
711315b
to
f2479ea
Compare
Problem
This PR add full flow for
GET /{formId}/adminform/submissions/count
endpoint.This initial implementation is free of middlewares, and all checks are done in the handler.Authentication middleware is being used for the route now that #568 is in.Note that the routes are not migrated to typescript yet, and will be done in a separate PR.
Solution
Features:
SubmissionService#getFormSubmissionsCount
neverthrown functionadminFormUtils#assertHasReadPermissions
function to check if user has read permissions.app.route('/:formId([a-fA-F0-9]{24})/adminform/submissions/count')
handler flowAdminFormController#handleCountFormSubmissions
functionquery.startDate
andquery.endDate
params.Improvements:
modules/submissions/__tests__
directorydateUtils#createQueryWithDateParam
UserController#getUserIdFromSession
toauthUtils#getUserIdFromSession
Bug Fixes:
Tests
handleCountFormSubmissions
tests inadmin-form.controller.spec.ts
getFormSubmissionsCount
tests insubmission.service.spec.ts