-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[1/n]: Migrate deleteOne
Rest API to use TwentyORM directly
#9784
base: main
Are you sure you want to change the base?
Conversation
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.
PR Summary
This PR introduces direct TwentyORM integration for the DELETE REST API endpoint, replacing the previous GraphQL-based implementation with a more efficient direct database access approach.
- Added new
RestApiCoreServiceV2
in/packages/twenty-server/src/engine/api/rest/core/rest-api-core-v2.service.ts
for direct TwentyORM operations - Implemented
RestCoreMiddleware
in/packages/twenty-server/src/engine/middlewares/rest-core-middleware.ts
for authentication and metadata validation - Created
CommonMiddlewareOperationsService
in/packages/twenty-server/src/engine/middlewares/common/common.service.ts
to share middleware logic between REST and GraphQL - Modified
RestApiCoreController
to useRestApiCoreServiceV2
for DELETE operations while maintaining backward compatibility for other endpoints - Added utility function
extractObjectIdFromPath
in/packages/twenty-server/src/engine/api/rest/core/utils/extract-id-from-path.utils.ts
for UUID validation
12 file(s) reviewed, 14 comment(s)
Edit PR Review Bot Settings | Greptile
packages/twenty-server/src/engine/api/rest/core/controllers/rest-api-core.controller.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/api/rest/core/rest-api-core-v2.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/api/rest/core/rest-api-core-v2.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/api/rest/core/utils/extract-id-from-path.utils.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/middlewares/common/common.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/middlewares/rest-core-middleware.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/middlewares/rest-core-middleware.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/middlewares/rest-core-middleware.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/middlewares/rest-core-middleware.ts
Outdated
Show resolved
Hide resolved
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.
Hey, very nice code and strategy. Like the way you factorized middlewares and the new rest-api-core-v2 service is a great seed for the migration
I put some comments about code standard we have at twenty and some simplification suggestions. Feel free to comment. Thank you
packages/twenty-server/src/engine/middlewares/common/common-middleware-operations.module.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/middlewares/common/common.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/middlewares/rest-core-middleware.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/middlewares/common/common.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/middlewares/common/common-middleware-operations.module.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/api/rest/core/rest-api-core-v2.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/api/rest/core/rest-api-core-v2.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/api/rest/core/rest-api-core-v2.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/api/rest/core/rest-api-core-v2.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/api/rest/core/utils/extract-id-from-path.utils.ts
Outdated
Show resolved
Hide resolved
32469c4
to
7a2a2a6
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.
Hello there ! Hope you're doing great
GG for this great PR
I've just reviewed the integrations tests left few comments, no big deal !
About to review main logic afterwards !
If I can provide any further information of course let me know !
packages/twenty-server/test/integration/rest/suites/rest-api-core.integration-spec.ts
Show resolved
Hide resolved
packages/twenty-server/test/integration/rest/suites/rest-api-core.integration-spec.ts
Show resolved
Hide resolved
packages/twenty-server/test/integration/rest/suites/rest-api-core.integration-spec.ts
Show resolved
Hide resolved
packages/twenty-server/test/integration/rest/suites/rest-api-core.integration-spec.ts
Show resolved
Hide resolved
packages/twenty-server/test/integration/rest/suites/rest-api-core.integration-spec.ts
Show resolved
Hide resolved
packages/twenty-server/test/integration/rest/utils/make-rest-api-request.util.ts
Show resolved
Hide resolved
Thank you for the review @prastoin, great suggestions |
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.
Second review on the logic this time !
Indeed there're some very neat refactor out there, good scoping !
Sorry for the long review, I'm available whenever you are tomorrow for peer review session if you wish to !
Please let me know, have a great evening
...es/twenty-server/src/engine/middlewares/constants/excluded-middleware-operations.constant.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/middlewares/graphql-hydrate-request-from-token.middleware.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/middlewares/graphql-hydrate-request-from-token.middleware.ts
Show resolved
Hide resolved
Nice! |
904f938
to
40a828e
Compare
packages/twenty-server/src/engine/api/rest/core/rest-api-core-v2.service.ts
Show resolved
Hide resolved
: error instanceof Error | ||
? 500 | ||
: error.status || 500, |
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 think we should not set 500 status for all Error, we should
: error instanceof Error | |
? 500 | |
: error.status || 500, | |
: error.status || 500, |
What do you think?
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.
Thanks for the suggestion
I got it, pushing the latest changes asap
40a828e
to
aa4be76
Compare
This PR
Addressing Make REST API use Twenty ORM direclty #3644
Migrates the
DELETE /rest/*
endpoint to use TwentyORMFactorizes common middleware logic into a common module
[WIP] 🚧 Writing integration tests for the endpoint updated