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: Remove VerifyAddUserInGroupUseCase and related files #763

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 1 addition & 64 deletions backend/src/entities/group/group.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,34 @@ import {
Inject,
Injectable,
Put,
Req,
Res,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import { Response, Request } from 'express';
import { UseCaseType } from '../../common/data-injection.tokens.js';
import { SlugUuid, UserId, VerificationString } from '../../decorators/index.js';
import { SlugUuid, UserId } from '../../decorators/index.js';
import { AmplitudeEventTypeEnum, InTransactionEnum } from '../../enums/index.js';
import { Messages } from '../../exceptions/text/messages.js';
import { GroupEditGuard, GroupReadGuard } from '../../guards/index.js';
import { Cacher } from '../../helpers/cache/cacher.js';
import { Constants } from '../../helpers/constants/constants.js';
import { SentryInterceptor } from '../../interceptors/index.js';
import { AmplitudeService } from '../amplitude/amplitude.service.js';
import { FoundUserInGroupDs } from '../user/application/data-structures/found-user-in-group.ds.js';
import { IToken, ITokenExp } from '../user/utils/generate-gwt-token.js';
import { AddUserInGroupDs, AddUserInGroupWithSaaSDs } from './application/data-sctructures/add-user-in-group.ds.js';
import { AddedUserInGroupDs } from './application/data-sctructures/added-user-in-group.ds.js';
import { DeletedGroupResultDs } from './application/data-sctructures/deleted-group-result.ds.js';
import { FoundGroupDataInfoDs, FoundUserGroupsDs } from './application/data-sctructures/found-user-groups.ds.js';
import { RemoveUserFromGroupResultDs } from './application/data-sctructures/remove-user-from-group-result.ds.js';
import { VerifyAddUserInGroupDs } from './application/data-sctructures/verify-add-user-in-group.ds.js';
import {
IAddUserInGroup,
IDeleteGroup,
IFindAllUsersInGroup,
IFindUserGroups,
IRemoveUserFromGroup,
IUpdateGroupTitle,
IVerifyAddUserInGroup,
} from './use-cases/use-cases.interfaces.js';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { AddUserInGroupDto } from './dto/add-user-ingroup-dto.js';
import { TokenExpirationResponseDto } from '../company-info/application/dto/token-expiration-response.dto.js';
import { DeleteUserFromGroupDTO } from './dto/delete-user-from-group-dto.js';
import { VerifyUserInGroupInvitationDto } from './dto/verify-user-in-group-invitation-request-body.dto.js';
import { getCookieDomainOptions } from '../user/utils/get-cookie-domain-options.js';
import { UpdateGroupTitleDto } from './dto/update-group-title.dto.js';

@UseInterceptors(SentryInterceptor)
Expand All @@ -57,8 +47,6 @@ export class GroupController {
constructor(
@Inject(UseCaseType.INVITE_USER_IN_GROUP)
private readonly addUserInGroupUseCase: IAddUserInGroup,
@Inject(UseCaseType.VERIFY_INVITE_USER_IN_GROUP)
private readonly verifyAddUserInGroupUseCase: IVerifyAddUserInGroup,
@Inject(UseCaseType.FIND_ALL_USER_GROUPS)
private readonly findAllUserGroupsUseCase: IFindUserGroups,
@Inject(UseCaseType.FIND_ALL_USERS_IN_GROUP)
Expand Down Expand Up @@ -147,57 +135,6 @@ export class GroupController {
}
}

@ApiOperation({ summary: 'Verify user in group invitation' })
@ApiBody({ type: VerifyUserInGroupInvitationDto })
@ApiResponse({
status: 200,
description: 'Verify user in group invitation.',
type: TokenExpirationResponseDto,
})
@Put('/group/user/verify/:verificationString')
async verifyUserInvitation(
@Body() verificationData: VerifyUserInGroupInvitationDto,
@Res({ passthrough: true }) response: Response,
@VerificationString('verificationString') verificationString: string,
@Req() req: Request,
): Promise<ITokenExp> {
const { password, name } = verificationData;
try {
const tokenInReq = req.cookies[Constants.JWT_COOKIE_KEY_NAME];
if (tokenInReq) {
response.clearCookie(Constants.JWT_COOKIE_KEY_NAME);
}
throw new HttpException(
{
message: Messages.TRY_VERIFY_ADD_USER_WHEN_LOGGED_IN,
},
HttpStatus.BAD_REQUEST,
);
} catch (e) {}

const inputData: VerifyAddUserInGroupDs = {
verificationString: verificationString,
user_password: password,
user_name: name,
};
const token: IToken = await this.verifyAddUserInGroupUseCase.execute(inputData, InTransactionEnum.ON);
response.cookie(Constants.JWT_COOKIE_KEY_NAME, token.token, {
httpOnly: true,
secure: true,
expires: token.exp,
...getCookieDomainOptions(),
});
response.cookie(Constants.ROCKETADMIN_AUTHENTICATED_COOKIE, token.exp.getTime(), {
httpOnly: false,
expires: token.exp,
...getCookieDomainOptions(),
});
return {
expires: token.exp,
isTemporary: token.isTemporary,
};
}

@ApiOperation({ summary: 'Delete group' })
@ApiResponse({
status: 200,
Expand Down
5 changes: 0 additions & 5 deletions backend/src/entities/group/group.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { DeleteGroupUseCase } from './use-cases/delete-group.use.case.js';
import { FindAllUserGroupsUseCase } from './use-cases/find-all-user-groups.use.case.js';
import { FindAllUsersInGroupUseCase } from './use-cases/find-all-users-in-group.use.case.js';
import { RemoveUserFromGroupUseCase } from './use-cases/remove-user-from-group.use.case.js';
import { VerifyAddUserInGroupUseCase } from './use-cases/verify-add-user-in-group.use.case.js';
import { AddUserInGroupUseCase } from './use-cases/saas-add-user-in-group-v2.use.case.js';
import { UpdateGroupTitleUseCase } from './use-cases/update-group-title.use.case.js';

Expand All @@ -42,10 +41,6 @@ import { UpdateGroupTitleUseCase } from './use-cases/update-group-title.use.case
provide: UseCaseType.INVITE_USER_IN_GROUP,
useClass: AddUserInGroupUseCase,
},
{
provide: UseCaseType.VERIFY_INVITE_USER_IN_GROUP,
useClass: VerifyAddUserInGroupUseCase,
},
{
provide: UseCaseType.FIND_ALL_USER_GROUPS,
useClass: FindAllUserGroupsUseCase,
Expand Down

This file was deleted.

Loading