Skip to content

Feat/user send enrollment request#192

Open
NicoAntonelli wants to merge 41 commits intomainfrom
feat/user-send-enrollment-request
Open

Feat/user send enrollment request#192
NicoAntonelli wants to merge 41 commits intomainfrom
feat/user-send-enrollment-request

Conversation

@NicoAntonelli
Copy link
Contributor

Enrollment invitations from a user admin to a potential interested user

@NicoAntonelli NicoAntonelli added the help wanted Extra attention is needed label Sep 11, 2024
@NicoAntonelli NicoAntonelli self-assigned this Sep 11, 2024
@JAcciarri JAcciarri self-requested a review September 11, 2024 12:37
import { Exclude, Expose } from 'class-transformer';
import { CurrentUserWithoutTokens } from '../../auth/dtos/current-user.dto';
import { Project } from '../../project/project.entity';
import { UserSimpleShowDto } from 'src/user/dtos/user.show.dto';
Copy link
Contributor

Choose a reason for hiding this comment

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

replace with relative import

} from 'class-transformer';
import { IsOptional } from 'class-validator';
import * as sanitizeHtml from 'sanitize-html';
import { ExposeType } from 'src/utils/decorators/expose-type.decorator';
Copy link
Contributor

Choose a reason for hiding this comment

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

replace with relative import

import { IsEmailVerifiedGuard } from 'src/auth/is-email-verified.guard';
import { EnrollmentRequestFromLeaderDto } from 'src/enrollment/dtos/enrollment-request.dto';
import { RequestWithUser } from 'src/utils/request-with-user';

Copy link
Contributor

Choose a reason for hiding this comment

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

replace all with relative import

EnrollmentRequestShowDto,
EnrollmentRequestsShowDto,
} from 'src/enrollment/dtos/enrollment-request.show.dto';

Copy link
Contributor

Choose a reason for hiding this comment

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

lots of relative import in user service, modify them all please

@UseGuards(...IsEmailVerifiedGuard)
@ApiCookieAuth()
@Put(':id/invitation/accept')
async acceptEnrollRequest(
Copy link
Contributor

Choose a reason for hiding this comment

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

We might need to modify this method name to 'acceptEnrollInvitation' in order to match what is being called from the service (better readability)

Copy link
Contributor

@JAcciarri JAcciarri left a comment

Choose a reason for hiding this comment

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

Half Pull request reviewed, I will continue later 👍

@UseGuards(...IsEmailVerifiedGuard)
@ApiCookieAuth()
@Put(':id/invitation/decline')
async declineEnrollRequest(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, We might need to modify this method name to 'declineEnrollInvitation' in order to match what is being called from the service and better readability

throw new BadRequest(
'Este usuario ya ha sido invitado para inscribirse en este proyecto',
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this validation will never enter as per our logic, an admin won't see invitation button if user has been already invited. Having said that, we could keep it, double verification from backend is always good

enrollment.id,
enrollRequestAdminDto.message,
action === 'approve' ? 'approved' : 'rejected',
);
Copy link
Contributor

Choose a reason for hiding this comment

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

We are asking twice for action to equal 'approve', can this be avoided?
Additionally, do we really need last parameter passed? It is only being used by debugger.

In case we really want it to be passed, can't we make a const action only one time and then pass it wherever needed - We would be passing a RequestState.Accepted or RequestState.Rejected instead of hardcoded string

Copy link
Contributor Author

@NicoAntonelli NicoAntonelli Sep 15, 2024

Choose a reason for hiding this comment

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

If I remove this parameter and directly use RequestState for the debugger message (inside the private function), this would go against the suggestion we took based on your feedback at the last meet, which was that there were unnecessarily nested conditions. Passing this parameter solved that problem since it eliminates the need to make nested ternaries (in this case, for the debug message).

enrollment.id,
enrollRequestAdminDto.message,
action === 'accept' ? 'accepted' : 'declined',
);
Copy link
Contributor

Choose a reason for hiding this comment

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

all of the above comments apply as well here :)

}

private async getUser(userId: number): Promise<User> {
const user = await this.userRepository.findOne({
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm feeling it's not a good practice to create methods under Project service that are handling other entities. Responsibility for getting one user shouldn't be under UserService? Or in case we need to use userRepository I feel like we could go ahead and just use it under ProjectService methods themselves

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the functio name to getUserWithInvitations to make it clear that they are functions associated with enrollments that will only be used in this file and not in userService. However, if that is not enough, I can move them to UserService and make them public so that they can be used from ProjectService, even if they are not used there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

Enrollment invitations from a user admin to a potential interested user

3 participants