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

545-Replace req user with req userEntity in the user.controller.ts #579

Merged

Conversation

SangilYun
Copy link
Contributor

Issue link / number:

#545

What changes did you make?

Replace req["user"] with req["userEntity"] in the user.controller.ts

Why did you make the changes?

To use the pure UserEntity schema/types for all internal functions.

Did you run tests?

Yes, cypress and unit tests ⭐️

@SangilYun SangilYun marked this pull request as ready for review August 10, 2024 15:36
this.userService.updateUser({ lastActiveAt: new Date() }, user.user.id);
return user as GetUserDto;
await this.userService.updateUser({ lastActiveAt: new Date() }, req['userEntity'].id);
return (await this.userService.getUserProfile(req['userEntity'].id)).userDto;
Copy link
Member

Choose a reason for hiding this comment

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

the lack of await here was intentional - we async update the users lastActiveAt after they have called their user profile.

i don't think we need the new getUserProfile function here, the change required is only

  async getUserByFirebaseId(@Req() req: Request): Promise<UserEntity> {
    const user = req['userEntity'];
    this.userService.updateUser({ lastActiveAt: new Date() }, user.id);
    return formatUserObject(user);

Copy link
Contributor

@eleanorreem eleanorreem Aug 20, 2024

Choose a reason for hiding this comment

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

Sorry to double back on this @SangilYun. @annarhughes I think we do need the getUserProfile here. As far as I understand, this endpoint is how we get all the user details to populate frontend state. Do you have a different understanding? This ticket was to ensure we still returned the same information but didn't have to grab it in the firebaseAuthGuard and mean that the GetUserDto is passed everywhere. There might be a further refactor at a later date where we break down how we grab the profile but this isn't yet implemented.

Copy link
Contributor

Choose a reason for hiding this comment

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

Anna is away so i'll update you on this @SangilYun - sorry for the delay. I would to keep the service method getUserProfile. The reason this change still works is because the firebaseAuthguard is still pulling too much data. If you look at getUserByFirebaseId which the firebaseAuthguard calls, it;s getting subscriptions, sessions, partnerAdmin data. We just don't need that on every request. So I'd like the getUserProfile to be the function that adds all this contextual data. Does that make sense? Then after this change, I can return to the authGuard and only pull the data from the user repository. This means we can drop all the complex module dependencies. I hope that makes sense and sorry for the confusion in the team!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eleanorreem Appreciate the feedback! I've added the service function back in, please have a look :)

Copy link
Member

@annarhughes annarhughes left a comment

Choose a reason for hiding this comment

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

Thanks so much for this contribution @SangilYun 🌟 i've just added a couple of comments to review!

@@ -84,7 +83,7 @@ export class UserController {
@Patch()
@UseGuards(FirebaseAuthGuard)
async updateUser(@Body() updateUserDto: UpdateUserDto, @Req() req: Request) {
Copy link
Member

Choose a reason for hiding this comment

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

It'd be good to add the return type : Promise<UserEntity> to the updateUser function here and in the controller!

@annarhughes annarhughes self-assigned this Aug 14, 2024
@SangilYun
Copy link
Contributor Author

@annarhughes Thank you for reviewing! I've made the updates, please take a look!

@eleanorreem eleanorreem merged commit ca7a904 into chaynHQ:develop Sep 10, 2024
3 checks passed
@eleanorreem
Copy link
Contributor

Brilliant thanks!

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.

3 participants