-
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 transfer ownership flow to TypeScript #718
Conversation
@awhdesmond this touches your code, so please review it if you want to! Will greatly appreciate it :) |
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.
minor changes requested! let me know your thoughts
Updated the responsibility into the service layer. Please rereview and let me know your thoughts. A con of this change is that the service function now looks a little intimidating, even though it's still (imho) fairly readable. |
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.
Approving first as it's all pretty much there
f271810
to
4fe3124
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.
to refactor error handling in transferFormOwnership
function
Not needed, since the form the instance method is acting on should already have the required information, and should only have a single source of truth. The issue where the current logged in user calling this method to transfer ownership of the form even when the logged in user is not the given form's owner should be mitigated in the controller layer, where checks for whether the current user is the form admin should (and currently is) undertaken.
4fe3124
to
9c11b20
Compare
Ready for rereview. |
# Conflicts: # src/app/models/form.server.model.ts # src/app/modules/form/admin-form/__tests__/admin-form.controller.spec.ts # src/app/modules/form/admin-form/__tests__/admin-form.service.spec.ts # src/app/modules/form/admin-form/admin-form.controller.ts # src/app/modules/form/admin-form/admin-form.service.ts # src/app/modules/form/admin-form/admin-form.utils.ts # src/types/form.ts # tests/unit/backend/controllers/admin-forms.server.controller.spec.js # tests/unit/backend/models/form.server.model.spec.ts
this.permissionList = | ||
this.permissionList?.filter((item) => item.email !== newOwner.email) ?? [] |
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.
did we ever figure out if a default value would be provided by mongoose on read, if it wasn't present in the DB?
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.
yea, will automatically have an empty array: https://mongoosejs.com/docs/schematypes.html#arrays
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.
so this should be safe?
this.permissionList = | |
this.permissionList?.filter((item) => item.email !== newOwner.email) ?? [] | |
this.permissionList = | |
this.permissionList.filter((item) => item.email !== newOwner.email) |
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.
TypeScript will complain, but that is because it is optional in the schema. Will probably make a IFormDocument
type that has all the default optionals populated as required to avoid this then.
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'll do the retyping in a separate PR to avoid polluting this even more
const validationError = this.invalidate( | ||
'admin', | ||
'Admin for this form is not found.', | ||
) as mongoose.Error.ValidationError | ||
return next(validationError) |
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.
nice use of invalidate()
, this is what we should be doing
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.
minor nitpicks, feel free to leave aside. lgtm otherwise
# Conflicts: # src/app/modules/form/admin-form/__tests__/admin-form.service.spec.ts # src/app/modules/form/admin-form/admin-form.controller.ts # src/app/modules/form/admin-form/admin-form.service.ts
Problem
This PR migrates the transfer ownership flow to TypeScript.
Solution
Features:
Improvements:
Form.transferOwner
instance method to return.save()
Form.transferOwner
to accept both a currentOwner and newOwnerIUserSchema
object, forcing the caller to retrieve those before calling the functionTests
Add tests for all new functions in the service and controller layer.
Note that the route layer has not been migrated and thus do not have integration tests yet.