Skip to content

Commit

Permalink
refactor: change board module types for constants (#1418)
Browse files Browse the repository at this point in the history
Co-authored-by: Patrícia Dias <116013814+patricia-mdias@users.noreply.github.com>
  • Loading branch information
CatiaAntunes96 and patricia-mdias authored Apr 20, 2023
1 parent 4dd7fb1 commit e9e09c0
Show file tree
Hide file tree
Showing 74 changed files with 433 additions and 369 deletions.
4 changes: 2 additions & 2 deletions backend/src/libs/guards/boardRoles.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import {
Injectable
} from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import * as Boards from 'src/modules/boards/interfaces/types';
import * as BoardUsers from 'src/modules/boardUsers/interfaces/types';
import TeamUser from 'src/modules/teamUsers/entities/team.user.schema';
import { GET_TEAM_USER_SERVICE } from 'src/modules/teamUsers/constants';
import { GET_BOARD_SERVICE } from 'src/modules/boards/constants';

@Injectable()
export class BoardUserGuard implements CanActivate {
constructor(
@Inject(GET_TEAM_USER_SERVICE)
private readonly getTeamUserService: GetTeamUserServiceInterface,
private readonly reflector: Reflector,
@Inject(Boards.TYPES.services.GetBoardService)
@Inject(GET_BOARD_SERVICE)
private readonly getBoardService: GetBoardServiceInterface,
@Inject(BoardUsers.TYPES.services.GetBoardUserService)
private readonly getBoardUserService: GetBoardUserServiceInterface
Expand Down
8 changes: 4 additions & 4 deletions backend/src/libs/guards/getBoardPermissions.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ import {
Inject,
Injectable
} from '@nestjs/common';
import * as Boards from 'src/modules/boards/interfaces/types';
import * as BoardUsers from 'src/modules/boardUsers/interfaces/types';
import TeamUser from 'src/modules/teamUsers/entities/team.user.schema';
import Team from 'src/modules/teams/entities/team.schema';
import User from 'src/modules/users/entities/user.schema';
import { Reflector } from '@nestjs/core';
import { GetBoardServiceInterface } from 'src/modules/boards/interfaces/services/get.board.service.interface';
import { GetBoardUserServiceInterface } from 'src/modules/boardUsers/interfaces/services/get.board.user.service.interface';
import { GET_BOARD_SERVICE } from 'src/modules/boards/constants';

@Injectable()
export class GetBoardGuard implements CanActivate {
constructor(
private readonly reflector: Reflector,
@Inject(Boards.TYPES.services.GetBoardService)
private getBoardService: GetBoardServiceInterface,
@Inject(GET_BOARD_SERVICE)
private readonly getBoardService: GetBoardServiceInterface,
@Inject(BoardUsers.TYPES.services.GetBoardUserService)
private getBoardUserService: GetBoardUserServiceInterface
private readonly getBoardUserService: GetBoardUserServiceInterface
) {}

async canActivate(context: ExecutionContext) {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/libs/guards/teamRoles.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class TeamUserGuard implements CanActivate {
constructor(
private readonly reflector: Reflector,
@Inject(GET_TEAM_USER_SERVICE)
private getTeamUserService: GetTeamUserServiceInterface
private readonly getTeamUserService: GetTeamUserServiceInterface
) {}

async canActivate(context: ExecutionContext) {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/libs/guards/updateBoardPermissions.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {
Injectable,
NotFoundException
} from '@nestjs/common';
import * as Boards from 'src/modules/boards/interfaces/types';
import User from 'src/modules/users/entities/user.schema';
import UpdateBoardUserDto from 'src/modules/boardUsers/dto/update-board-user.dto';
import { GET_BOARD_SERVICE } from 'src/modules/boards/constants';

@Injectable()
export class UpdateBoardPermissionsGuard implements CanActivate {
constructor(
@Inject(Boards.TYPES.services.GetBoardService)
@Inject(GET_BOARD_SERVICE)
private readonly getBoardService: GetBoardServiceInterface
) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Inject, Injectable } from '@nestjs/common';
import * as User from 'src/modules/users/interfaces/types';
import * as Boards from 'src/modules/boards/interfaces/types';
import { GetUserServiceInterface } from 'src/modules/users/interfaces/services/get.user.service.interface';
import { StatisticsAuthUserUseCaseInterface } from '../interfaces/applications/statistics.auth.use-case.interface';
import { GetTeamUserServiceInterface } from 'src/modules/teamUsers/interfaces/services/get.team.user.service.interface';
import { GetBoardServiceInterface } from 'src/modules/boards/interfaces/services/get.board.service.interface';
import { GET_TEAM_USER_SERVICE } from 'src/modules/teamUsers/constants';
import { GET_BOARD_SERVICE } from 'src/modules/boards/constants';

@Injectable()
export default class StatisticsAuthUserUseCase implements StatisticsAuthUserUseCaseInterface {
Expand All @@ -14,7 +14,7 @@ export default class StatisticsAuthUserUseCase implements StatisticsAuthUserUseC
private readonly getUserService: GetUserServiceInterface,
@Inject(GET_TEAM_USER_SERVICE)
private readonly getTeamUserService: GetTeamUserServiceInterface,
@Inject(Boards.TYPES.services.GetBoardService)
@Inject(GET_BOARD_SERVICE)
private readonly getBoardService: GetBoardServiceInterface
) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import { BoardRoles } from 'src/libs/enum/board.roles';
import { MongoGenericRepository } from 'src/libs/repositories/mongo/mongo-generic.repository';
import BoardUserDto from 'src/modules/boardUsers/dto/board.user.dto';
import Board from 'src/modules/boards/entities/board.schema';
import BoardUser, { BoardUserDocument } from 'src/modules/boardUsers/entities/board.user.schema';
import BoardUser from 'src/modules/boardUsers/entities/board.user.schema';
import { BoardUserRepositoryInterface } from '../interfaces/repositories/board-user.repository.interface';
import { BulkWriteResult } from 'mongodb';

@Injectable()
export class BoardUserRepository
extends MongoGenericRepository<BoardUserDocument>
extends MongoGenericRepository<BoardUser>
implements BoardUserRepositoryInterface
{
constructor(@InjectModel(BoardUser.name) private model: Model<BoardUserDocument>) {
constructor(@InjectModel(BoardUser.name) private model: Model<BoardUser>) {
super(model);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Test, TestingModule } from '@nestjs/testing';
import * as Boards from 'src/modules/boards/interfaces/types';
import { DeepMocked, createMock } from '@golevelup/ts-jest';
import { CreateBoardUserServiceInterface } from 'src/modules/boardUsers/interfaces/services/create.board.user.service.interface';
import faker from '@faker-js/faker';
Expand All @@ -9,6 +8,7 @@ import { UseCase } from 'src/libs/interfaces/use-case.interface';
import CreateBoardUseCaseDto from '../dto/useCase/create-board.use-case.dto';
import Board from '../entities/board.schema';
import { CreateBoardUseCase } from './create-board.use-case';
import { CREATE_BOARD_SERVICE } from 'src/modules/boards/constants';

describe('CreateBoardUseCase', () => {
let useCase: UseCase<CreateBoardUseCaseDto, Board>;
Expand All @@ -19,14 +19,14 @@ describe('CreateBoardUseCase', () => {
providers: [
CreateBoardUseCase,
{
provide: Boards.TYPES.services.CreateBoardService,
provide: CREATE_BOARD_SERVICE,
useValue: createMock<CreateBoardUserServiceInterface>()
}
]
}).compile();

useCase = module.get(CreateBoardUseCase);
createBoardServiceMock = module.get(Boards.TYPES.services.CreateBoardService);
createBoardServiceMock = module.get(CREATE_BOARD_SERVICE);
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Inject, Injectable } from '@nestjs/common';
import { TYPES } from '../interfaces/types';
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import Board from '../entities/board.schema';
import { CreateBoardServiceInterface } from '../interfaces/services/create.board.service.interface';
import CreateBoardUseCaseDto from '../dto/useCase/create-board.use-case.dto';
import { CREATE_BOARD_SERVICE } from 'src/modules/boards/constants';

@Injectable()
export class CreateBoardUseCase implements UseCase<CreateBoardUseCaseDto, Board> {
constructor(
@Inject(TYPES.services.CreateBoardService)
@Inject(CREATE_BOARD_SERVICE)
private readonly createBoardService: CreateBoardServiceInterface
) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Test, TestingModule } from '@nestjs/testing';
import * as Boards from 'src/modules/boards/interfaces/types';
import { DeepMocked, createMock } from '@golevelup/ts-jest';
import { BoardFactory } from 'src/libs/test-utils/mocks/factories/board-factory.mock';
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import { deleteBoardUseCase } from '../boards.providers';
import { DeleteBoardServiceInterface } from '../interfaces/services/delete.board.service.interface';
import { BoardRepositoryInterface } from '../repositories/board.repository.interface';
import { NotFoundException } from '@nestjs/common';
import DeleteBoardUseCaseDto from 'src/modules/boards/dto/useCase/delete-board.use-case';
import { BOARD_REPOSITORY, DELETE_BOARD_SERVICE } from 'src/modules/boards/constants';
import { DeleteBoardUseCase } from 'src/modules/boards/applications/delete-board.use-case';

const board = BoardFactory.create({
dividedBoards: BoardFactory.createMany(2),
Expand All @@ -22,21 +22,21 @@ describe('DeleteBoardUseCase', () => {
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
deleteBoardUseCase,
DeleteBoardUseCase,
{
provide: Boards.TYPES.services.DeleteBoardService,
provide: DELETE_BOARD_SERVICE,
useValue: createMock<DeleteBoardServiceInterface>()
},
{
provide: Boards.TYPES.repositories.BoardRepository,
provide: BOARD_REPOSITORY,
useValue: createMock<BoardRepositoryInterface>()
}
]
}).compile();

useCase = module.get(Boards.TYPES.applications.DeleteBoardUseCase);
deleteBoardServiceMock = module.get(Boards.TYPES.services.DeleteBoardService);
boardRepositoryMock = module.get(Boards.TYPES.repositories.BoardRepository);
useCase = module.get(DeleteBoardUseCase);
deleteBoardServiceMock = module.get(DELETE_BOARD_SERVICE);
boardRepositoryMock = module.get(BOARD_REPOSITORY);
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import { Inject, Injectable, NotFoundException } from '@nestjs/common';
import { TYPES } from '../interfaces/types';
import { BOARD_REPOSITORY, DELETE_BOARD_SERVICE } from '../constants';
import { BoardRepositoryInterface } from '../repositories/board.repository.interface';
import { BOARD_NOT_FOUND } from 'src/libs/exceptions/messages';
import { ObjectId } from 'mongoose';
Expand All @@ -11,9 +11,9 @@ import DeleteBoardUseCaseDto from 'src/modules/boards/dto/useCase/delete-board.u
@Injectable()
export class DeleteBoardUseCase implements UseCase<DeleteBoardUseCaseDto, boolean> {
constructor(
@Inject(TYPES.repositories.BoardRepository)
@Inject(BOARD_REPOSITORY)
private readonly boardRepository: BoardRepositoryInterface,
@Inject(TYPES.services.DeleteBoardService)
@Inject(DELETE_BOARD_SERVICE)
private readonly deleteBoardService: DeleteBoardServiceInterface
) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing';
import * as BoardUsers from 'src/modules/boardUsers/interfaces/types';
import * as Boards from 'src/modules/boards/interfaces/types';
import * as Users from 'src/modules/users/interfaces/types';
import { DeepMocked, createMock } from '@golevelup/ts-jest';
import { UseCase } from 'src/libs/interfaces/use-case.interface';
Expand All @@ -16,6 +15,7 @@ import { UserFactory } from 'src/libs/test-utils/mocks/factories/user-factory';
import { DuplicateBoardDto, DuplicateBoardUseCase } from './duplicate-board.use-case';
import { BoardUserDtoFactory } from 'src/libs/test-utils/mocks/factories/dto/boardUserDto-factory.mock';
import { CreateFailedException } from 'src/libs/exceptions/createFailedBadRequestException';
import { BOARD_REPOSITORY, GET_BOARD_SERVICE } from 'src/modules/boards/constants';

const DEFAULT_PROPS = {
boardId: faker.datatype.uuid(),
Expand Down Expand Up @@ -43,11 +43,11 @@ describe('DuplicateBoardUseCase', () => {
useValue: createMock<GetUserServiceInterface>()
},
{
provide: Boards.TYPES.services.GetBoardService,
provide: GET_BOARD_SERVICE,
useValue: createMock<GetBoardServiceInterface>()
},
{
provide: Boards.TYPES.repositories.BoardRepository,
provide: BOARD_REPOSITORY,
useValue: createMock<BoardRepositoryInterface>()
},
{
Expand All @@ -60,8 +60,8 @@ describe('DuplicateBoardUseCase', () => {
duplicateBoardMock = module.get(DuplicateBoardUseCase);

getUserServiceMock = module.get(Users.TYPES.services.GetUserService);
getBoardServiceMock = module.get(Boards.TYPES.services.GetBoardService);
boardRepositoryMock = module.get(Boards.TYPES.repositories.BoardRepository);
getBoardServiceMock = module.get(GET_BOARD_SERVICE);
boardRepositoryMock = module.get(BOARD_REPOSITORY);
createBoardUserServiceMock = module.get(BoardUsers.TYPES.services.CreateBoardUserService);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ import { GetUserServiceInterface } from 'src/modules/users/interfaces/services/g
import * as Users from 'src/modules/users/interfaces/types';
import Board from '../entities/board.schema';
import { GetBoardServiceInterface } from '../interfaces/services/get.board.service.interface';
import { TYPES } from '../interfaces/types';
import { BOARD_REPOSITORY, GET_BOARD_SERVICE } from '../constants';
import { BoardRepositoryInterface } from '../repositories/board.repository.interface';

export type DuplicateBoardDto = { boardId: string; userId: string; boardTitle: string };

@Injectable()
export class DuplicateBoardUseCase implements UseCase<DuplicateBoardDto, Board> {
constructor(
@Inject(TYPES.services.GetBoardService)
@Inject(GET_BOARD_SERVICE)
private readonly getBoardService: GetBoardServiceInterface,
@Inject(Users.TYPES.services.GetUserService)
private readonly getUserService: GetUserServiceInterface,
@Inject(TYPES.repositories.BoardRepository)
@Inject(BOARD_REPOSITORY)
private readonly boardRepository: BoardRepositoryInterface,
@Inject(BoardUsers.TYPES.services.CreateBoardUserService)
private readonly createBoardUserService: CreateBoardUserServiceInterface
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Test, TestingModule } from '@nestjs/testing';
import * as Boards from 'src/modules/boards/interfaces/types';
import { DeepMocked, createMock } from '@golevelup/ts-jest';
import { GetBoardServiceInterface } from '../interfaces/services/get.board.service.interface';
import faker from '@faker-js/faker';
Expand All @@ -9,6 +8,7 @@ import { UseCase } from 'src/libs/interfaces/use-case.interface';
import GetAllBoardsUseCaseDto from '../dto/useCase/get-all-boards.use-case.dto';
import BoardsPaginatedPresenter from '../presenter/boards-paginated.presenter';
import { GetAllBoardsUseCase } from './get-all-boards.use-case';
import { GET_BOARD_SERVICE } from 'src/modules/boards/constants';

const teams = TeamFactory.createMany(2);
const teamIds = teams.map((team) => team._id);
Expand All @@ -31,14 +31,14 @@ describe('GetAllBoardsUseCase', () => {
providers: [
GetAllBoardsUseCase,
{
provide: Boards.TYPES.services.GetBoardService,
provide: GET_BOARD_SERVICE,
useValue: createMock<GetBoardServiceInterface>()
}
]
}).compile();

useCase = module.get(GetAllBoardsUseCase);
getBoardServiceMock = module.get(Boards.TYPES.services.GetBoardService);
getBoardServiceMock = module.get(GET_BOARD_SERVICE);
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { Inject, Injectable } from '@nestjs/common';
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import GetAllBoardsUseCaseDto from '../dto/useCase/get-all-boards.use-case.dto';
import { GetBoardServiceInterface } from '../interfaces/services/get.board.service.interface';
import { TYPES } from '../interfaces/types';
import { GET_BOARD_SERVICE } from '../constants';
import BoardsPaginatedPresenter from '../presenter/boards-paginated.presenter';

@Injectable()
export class GetAllBoardsUseCase
implements UseCase<GetAllBoardsUseCaseDto, BoardsPaginatedPresenter>
{
constructor(
@Inject(TYPES.services.GetBoardService)
@Inject(GET_BOARD_SERVICE)
private readonly getBoardService: GetBoardServiceInterface
) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Test, TestingModule } from '@nestjs/testing';
import * as Boards from 'src/modules/boards/interfaces/types';
import * as BoardUsers from 'src/modules/boardUsers/interfaces/types';
import * as Auth from 'src/modules/auth/interfaces/types';
import * as Users from 'src/modules/users/interfaces/types';
Expand All @@ -20,6 +19,7 @@ import { BoardUserFactory } from 'src/libs/test-utils/mocks/factories/boardUser-
import { Tokens } from 'src/libs/interfaces/jwt/tokens.interface';
import { hideVotesFromColumns } from '../utils/hideVotesFromColumns';
import { GetBoardUseCase } from './get-board.use-case';
import { BOARD_REPOSITORY } from 'src/modules/boards/constants';

const mainBoard = BoardFactory.create({ isSubBoard: false, isPublic: false });
const subBoard = BoardFactory.create({ isSubBoard: true, isPublic: false });
Expand All @@ -37,7 +37,7 @@ describe('GetBoardUseCase', () => {
providers: [
GetBoardUseCase,
{
provide: Boards.TYPES.repositories.BoardRepository,
provide: BOARD_REPOSITORY,
useValue: createMock<BoardRepositoryInterface>()
},
{
Expand All @@ -60,7 +60,7 @@ describe('GetBoardUseCase', () => {
}).compile();

useCase = module.get(GetBoardUseCase);
boardRepositoryMock = module.get(Boards.TYPES.repositories.BoardRepository);
boardRepositoryMock = module.get(BOARD_REPOSITORY);
getBoardUserServiceMock = module.get(BoardUsers.TYPES.services.GetBoardUserService);
getTokenAuthServiceMock = module.get(Auth.TYPES.services.GetTokenAuthService);
});
Expand Down
4 changes: 2 additions & 2 deletions backend/src/modules/boards/applications/get-board.use-case.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import { BadRequestException, Inject, Injectable, NotFoundException } from '@nestjs/common';
import { TYPES } from '../interfaces/types';
import { BOARD_REPOSITORY } from '../constants';
import * as BoardUsers from 'src/modules/boardUsers/interfaces/types';
import * as Auth from 'src/modules/auth/interfaces/types';
import * as Users from 'src/modules/users/interfaces/types';
Expand All @@ -22,7 +22,7 @@ import BoardGuestUserDto from 'src/modules/boardUsers/dto/board.guest.user.dto';
@Injectable()
export class GetBoardUseCase implements UseCase<GetBoardUseCaseDto, BoardUseCasePresenter> {
constructor(
@Inject(TYPES.repositories.BoardRepository)
@Inject(BOARD_REPOSITORY)
private readonly boardRepository: BoardRepositoryInterface,
@Inject(BoardUsers.TYPES.services.GetBoardUserService)
private readonly getBoardUserService: GetBoardUserServiceInterface,
Expand Down
Loading

0 comments on commit e9e09c0

Please sign in to comment.