Skip to content

Refactor WorkspaceMemberDto transpilation #12110

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

prastoin
Copy link
Contributor

@prastoin prastoin commented May 18, 2025

Introduction

Following #11914

closing twentyhq/core-team-issues#1011

@prastoin prastoin marked this pull request as ready for review May 18, 2025 10:20
Copy link
Contributor

github-actions bot commented May 18, 2025

TODOs/FIXMEs:

  • // TODO Refactor to be transpiled to WorkspaceMember instead: packages/twenty-server/src/engine/core-modules/user/user.resolver.ts
  • // TODO Refactor to be transpiled to WorkspaceMember instead: packages/twenty-server/src/engine/core-modules/user/user.resolver.ts
  • // TODO Refactor should not throw ? typed as nullable ?: packages/twenty-server/src/engine/core-modules/user/user.resolver.ts
  • // TODO: Fix typing disrepency between Entity and DTO: packages/twenty-server/src/engine/core-modules/user/user.resolver.ts

Generated by 🚫 dangerJS against cc86019

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 consolidates workspace member DTO transpilation by introducing a new WorkspaceMemberTranspiler service and removing the redundant DeletedWorkspaceMemberTranspiler.

  • Introduced WorkspaceMemberTranspiler service in /packages/twenty-server/src/engine/core-modules/user/services/workspace-member-transpiler.service.ts to handle both active and deleted workspace member transformations
  • Refactored UserResolver to use the new transpiler service with improved error handling and type safety
  • Added fromRoleEntityToRoleDto utility in /packages/twenty-server/src/engine/metadata-modules/role/utils/fromRoleEntityToRoleDto.util.ts for consistent role mapping
  • Modified PermissionsService to support a new UserWorkspacePermissions type and prepare for V2 permissions
  • Removed redundant DeletedWorkspaceMemberTranspiler service and its references in UserModule

7 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 134 to 135
// NULLABLE ?
avatarUrl: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider adding @WorkspaceIsNullable() decorator if avatarUrl should be optional. Remove the comment after decision is made.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @charlesBochet I've been facing few assertion within the code expecting this field to be nullable, do you please have more information regarding this ?

Copy link
Member

Choose a reason for hiding this comment

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

Sure!

Main concern: have only one value (null or '') to represent an "empty" string in DB. This simplifies our code.

Previous vision: use ''
New vision: use null

Why this change: NULLs don't take disk space in postgres + it's easier to make unicity constraint where not null

So, avatarUrl should become Nullable but is not for now. The migration effort hasn't started yet and it might be too ambitious to tackle it now. In the current codebase, avatarUrl is of type TEXT and should not be nullable.

Note: this null state is also true for JSON ({} vs null}, ARRAY ([] vs null) and TEXT ('' vs null). Composite Fields should respect their subField types, which is not the case at all yet

Copy link
Contributor Author

@prastoin prastoin May 20, 2025

Choose a reason for hiding this comment

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

Thanks for the clarification,
I think we should tackle all of the raised points pretty soon to avoid building any legacy on them, or at least update their typing through the applications to start bullet proofing the application to these about to become nullable fields.
Because from my understanding some eng has started coding having this in mind, leading to sometimes assertions checking the nullability of the data and sometimes not. Not knowing which assertion side should be considered as legacy, in order to prevent such mind gym, for the workspace entity we could add string | null | '' to the avatarUrl typing

Lets discuss this when you have some free time

Copy link
Contributor

github-actions bot commented May 18, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:22340

This environment will automatically shut down when the PR is closed or after 5 hours.

@prastoin
Copy link
Contributor Author

I still want to implement integration tests on these

Copy link
Member

@charlesBochet charlesBochet left a comment

Choose a reason for hiding this comment

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

Thanks @prastoin, the PR seems reasonable, let's add integration test on the resolver indeed!

@prastoin prastoin force-pushed the user-resolver-refactor branch from 5f00025 to 1afcf1b Compare May 27, 2025 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants