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(admin-form-api): duplicate adminform form endpoints for /api/v3i #1635

Merged
merged 6 commits into from
Apr 19, 2021

Conversation

orbitalsqwib
Copy link
Contributor

Problem

Updates current adminform form-related endpoints to their /api rooted endpoints to follow a RESTful hierarchy.

Closes #1501

Solution

Features:

  • duplicate and update adminform form related endpoints
  • duplicate integration tests for new endpoint
  • update v3 router to use new endpoints
  • update frontend api calls to use new endpoints

Tests

  • Check that the current logged in user can see the list of their forms in their dashboard (GET /api/v3/admin/forms/)
  • Check that you can create a new form (POST /api/v3/admin/forms)
  • Check that you can duplicate a form (POST /api/v3/admin/forms/:formId/duplicate)
  • Check that you can delete a form (DELETE /api/v3/admin/forms/:formId)
  • Check that you can transfer ownership of a form (POST /api/v3/admin/forms/:formId/collaborators/transfer-owner)

…/v3i

- duplicate and update adminform form related endpoints
- duplicate integration tests for new endpoint
- update v3 router to use new endpoints
- update frontend api calls to use new endpoints
@orbitalsqwib orbitalsqwib requested a review from karrui April 14, 2021 01: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.

lgtm after removing unneeded Joi extension

@orbitalsqwib orbitalsqwib requested a review from mantariksh April 14, 2021 06:39
@orbitalsqwib orbitalsqwib requested a review from mantariksh April 15, 2021 05:51
@orbitalsqwib orbitalsqwib marked this pull request as draft April 15, 2021 05:55
- shift validators into admin-form controller
- update handler methods to include validators as request handler array
- update controller integration tests
- update old routes to use new handler
- update new routes to use new handler
@orbitalsqwib orbitalsqwib marked this pull request as ready for review April 15, 2021 06:29
@orbitalsqwib orbitalsqwib requested a review from karrui April 15, 2021 06:29
@orbitalsqwib orbitalsqwib merged commit bd98c65 into develop Apr 19, 2021
@orbitalsqwib orbitalsqwib deleted the ref/admin-form-api branch April 19, 2021 06:38
@tshuli tshuli mentioned this pull request Apr 20, 2021
karrui added a commit that referenced this pull request Apr 21, 2021
#1640)

* feat: add FormField type that is a union for every possible field

* feat: return http 422 status code on EditFieldError instead of 400

* feat(AdminFormService): add updateFormField to update single field

* feat(AdminFormCtl): add handleUpdateFormField fn

* feat(AdminFormRoutes): add PUT endpoint for updating single form field

* feat(AdminFormClientCtl): add specific update field handling in update

* feat: update types of mongo subdocs to allow for DocumentArray

allows for special array methods such as `id()`, `pull()`, etc

* test(AdminForm): update test for invalid field update to return 422

* feat(formUtils): add getFormFieldById helper method

uses DocumentArray#id method if available, else uses Array#find

* test(formUtils): add unit tests for getFormFieldById

* ref: rename admin-forms.build.routes to admin-forms.form.routes

for consistency with #1635

* feat: add Form instance method updateFormFieldById

seems like a better place to for the manipulation of the form instead of in the service directly

* ref(AdminFormSvc): use Form model method in update field service fn

* feat(AdminFormRoutes): strengthen Joi validation for update field

ensures body._id given is the same as the params.fieldId so ids of fields cannot be changed so easily

* feat: add FormFieldDto type for use in update form field handler

* fix(formUtils): fix evaluation of whether array is mongoose doc array

* test(FormModel): add unit tests for updateFormFieldById instance fn

* test(AdminFormSvc): add unit tests for updateFormField fn

* test(AdminFormCtl): add unit tests for handleUpdateFormField

* ref: group joi validation middleware with controller fn in export

* feat: only merge updated field if index of updated field exists

* feat(client): call update field endpoint on updating myinfo fields too

* test(AdminFormCtl): correct name of _handleUpdateFormField in desc

* ref(mongooseUtils): move isMongooseDocumentArray to own util file

* ref(formUtils): remove profane usage of else after return

* ref: convert constants/update-form-types.js to TypeScript

* feat: show error Toast when returned field don't map to current fields
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.

[API] Duplicate admin form related endpoints to their new /api counterparts
3 participants