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

refactor: move logic for validateEncryptSubmission to utility #627

Closed
wants to merge 1 commit into from

Conversation

tshuli
Copy link
Contributor

@tshuli tshuli commented Nov 12, 2020

No description provided.

@tshuli
Copy link
Contributor Author

tshuli commented Nov 12, 2020

@karrui thanks for discussing earlier today, could I trouble you to take a look to see if this approach is roughly correct? :)

will clean up / write tests and work on submissions thereafter since you are refactoring the rest of encrypt-submissions

@tshuli tshuli force-pushed the refactor/ts-encrypt-submissions branch from d468602 to e4e2298 Compare November 12, 2020 13:54
Copy link
Contributor

@karrui karrui left a comment

Choose a reason for hiding this comment

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

I think the things you've refactored out as utilities actually belong in the domain of the controller and does not need to be extracted.

I think what you can do is to convert the utility functions currently being used into neverthrown functions so you don't need to wrap them in a try catch block.


type ReqWithForm<T> = T & { form: IPopulatedForm }

export const isValidEncryptSubmission = (req: Request): boolean => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to create the isValidEncryptSubmission function, can't we use the checkIsEncryptedEncoding function directly?

I think we can update the checkIsEncryptedEncoding function into a neverthrown function instead.


type ReqWithForm<T> = T & { form: IPopulatedForm }

export const isValidEncryptSubmission = (req: Request): boolean => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Utility functions should also not need to be aware of other layers, in this case this function needs to know about req from the controller layer, which is not what we want

return true
}

export const processResponses = (req: Request): void => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here. The argument for this function should not be Request, but scoped to the variable it is going to act on. In this case, this whole block seems to be the domain of the controller and does not need to be extracted.

Also strive to make utility functions pure. In this function, we are assigning to req.body.parsedResponses as a side effect, which can be hard to realize

@tshuli
Copy link
Contributor Author

tshuli commented Nov 15, 2020

@karrui Thanks a lot!
Will close this and open a PR for neverthrow refactoring

@tshuli tshuli closed this Nov 15, 2020
@liangyuanruo liangyuanruo deleted the refactor/ts-encrypt-submissions branch January 26, 2021 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants