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

fix: delete query to db to get mainboardid #1194

Merged
merged 25 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c4ebfb6
feat: start of board user repository
CatiaAntunes96 Feb 28, 2023
6eb9251
feat: add get mainboard functions to repository
CatiaAntunes96 Feb 28, 2023
ebdfa87
feat: add getBoard queries to board repository
CatiaAntunes96 Mar 1, 2023
091c7b4
feat: add delete queries to board repository
CatiaAntunes96 Mar 1, 2023
1b2fb0a
fix: fix tests
CatiaAntunes96 Mar 2, 2023
edd62e0
feat: add delete queries to board repositories
CatiaAntunes96 Mar 2, 2023
a04a39e
feat: add update queries to board repositories
CatiaAntunes96 Mar 2, 2023
5a496c2
feat: add update queries to board repositories
CatiaAntunes96 Mar 2, 2023
044aaa7
feat: add create board queries to board repository
CatiaAntunes96 Mar 2, 2023
4fdc2c0
fix: add generic to create method of baseMongo
CatiaAntunes96 Mar 3, 2023
22b6be9
Merge branch 'main' into refactor/create-repository-fix
CatiaAntunes96 Mar 3, 2023
c912093
feat: added socket when creating board user
patricia-mdias Mar 3, 2023
33e64a8
fix: remove unused imports
CatiaAntunes96 Mar 3, 2023
f6500cd
fix: added imports to tests
patricia-mdias Mar 3, 2023
b0ca4b7
fix: esslint error
patricia-mdias Mar 3, 2023
cf958f7
Merge branch 'main' into refactor/create-repository-fix
patricia-mdias Mar 3, 2023
4eb4254
fix: sAdmin access to board when he is a boarduser
patricia-mdias Mar 3, 2023
89e8635
fix: access get board service instead of boards repositories on guard
CatiaAntunes96 Mar 3, 2023
b463493
fix: applied pr suggestions
patricia-mdias Mar 6, 2023
6b3600b
fix: selectDividedBoards is defined locally
patricia-mdias Mar 6, 2023
827a0b1
fix: remove query to fetch mainBoardId from db
CatiaAntunes96 Mar 6, 2023
a17f7bc
fix: fix boards count by team
CatiaAntunes96 Mar 6, 2023
5c5f128
Merge branch 'main'
CatiaAntunes96 Mar 6, 2023
b9644d2
fix: fix missed imports on testing files
CatiaAntunes96 Mar 6, 2023
d037056
fix: remove comments from code
CatiaAntunes96 Mar 7, 2023
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
16 changes: 9 additions & 7 deletions backend/src/modules/auth/controller/auth.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { boardUserRepository, createBoardUserService } from './../../boards/boards.providers';
import {
boardRepository,
boardUserRepository,
createBoardService,
createBoardUserService,
getBoardApplication,
getBoardService
} from './../../boards/boards.providers';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { INestApplication, ValidationPipe } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
Expand All @@ -18,12 +25,6 @@ import {
registerAuthService
} from 'src/modules/auth/auth.providers';
import AuthController from 'src/modules/auth/controller/auth.controller';
import {
boardRepository,
createBoardService,
getBoardApplication,
getBoardService
} from 'src/modules/boards/boards.providers';
import EmailModule from 'src/modules/mailer/mailer.module';
import {
createTeamService,
Expand Down Expand Up @@ -92,6 +93,7 @@ describe('AuthController', () => {
SchedulerRegistry,
ConfigService,
boardUserRepository,
createBoardService,
{
provide: CommunicationsType.TYPES.services.SlackCommunicationService,
useValue: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConfigService } from '@nestjs/config';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { JwtService } from '@nestjs/jwt';
import { getModelToken } from '@nestjs/mongoose';
import { Test } from '@nestjs/testing';
Expand All @@ -7,6 +8,13 @@ import configService from 'src/libs/test-utils/mocks/configService.mock';
import jwtService from 'src/libs/test-utils/mocks/jwtService.mock';
import mockedUser from 'src/libs/test-utils/mocks/user.mock';
import ValidateUserAuthServiceImpl from 'src/modules/auth/services/validate-user.auth.service';
import {
boardRepository,
boardUserRepository,
createBoardUserService,
getBoardService
} from 'src/modules/boards/boards.providers';
import SocketGateway from 'src/modules/socket/gateway/socket.gateway';
import {
getTeamService,
teamRepository,
Expand All @@ -15,7 +23,12 @@ import {
} from 'src/modules/teams/providers';
import { GetUserService } from 'src/modules/users/interfaces/services/get.user.service.interface';
import { TYPES } from 'src/modules/users/interfaces/types';
import { getUserService, userRepository } from 'src/modules/users/users.providers';
import {
getUserService,
updateUserService,
userRepository
} from 'src/modules/users/users.providers';
import { getTokenAuthService } from '../auth.providers';

jest.mock('bcrypt');
jest.mock('src/modules/schedules/services/create.schedules.service.ts');
Expand All @@ -38,14 +51,22 @@ describe('The AuthenticationService', () => {
(bcrypt.compare as jest.Mock) = bcryptCompare;

const module = await Test.createTestingModule({
imports: [EventEmitterModule.forRoot()],
providers: [
ValidateUserAuthServiceImpl,
SocketGateway,
getUserService,
getTeamService,
userRepository,
teamRepository,
teamUserRepository,
updateTeamService,
getBoardService,
createBoardUserService,
getTokenAuthService,
boardUserRepository,
boardRepository,
updateUserService,
{
provide: ConfigService,
useValue: configService
Expand All @@ -54,6 +75,14 @@ describe('The AuthenticationService', () => {
provide: JwtService,
useValue: jwtService
},
{
provide: getModelToken('Board'),
useValue: {}
},
{
provide: getModelToken('BoardUser'),
useValue: {}
},
{
provide: getModelToken('User'),
useValue: usersRepository
Expand All @@ -65,6 +94,10 @@ describe('The AuthenticationService', () => {
{
provide: getModelToken('TeamUser'),
useValue: {}
},
{
provide: getModelToken('ResetPassword'),
useValue: {}
}
]
}).compile();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createBoardUserService } from './../boards.providers';
import { ConfigService } from '@nestjs/config';
import configService from 'src/libs/test-utils/mocks/configService.mock';
import { EventEmitterModule } from '@nestjs/event-emitter';
Expand All @@ -10,6 +9,7 @@ import {
boardUserRepository,
createBoardApplication,
createBoardService,
createBoardUserService,
deleteBoardApplication,
deleteBoardService,
getBoardApplication,
Expand Down Expand Up @@ -75,6 +75,7 @@ describe('BoardsController', () => {
createBoardUserService,
getTokenAuthService,
updateUserService,
getBoardService,
{
provide: getModelToken('User'),
useValue: {}
Expand Down
4 changes: 4 additions & 0 deletions backend/src/modules/boards/dto/update-board.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ export class UpdateBoardDto extends PartialType(BoardDto) {
@IsOptional()
@Type(() => String)
deletedColumns?: string[];

@ApiPropertyOptional({ type: String })
@IsOptional()
mainBoardId?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ export interface GetBoardServiceInterface {
getBoardData(boardId: string): Promise<Board>;

getBoardUsers(board: string, user: string): Promise<BoardUser[]>;

getAllMainBoards(): Promise<Board[]>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface BoardRepositoryInterface extends BaseInterfaceRepository<Board>
): Promise<Board[]>;
getResponsiblesSlackId(boardId: string): Promise<Board>;
getBoardByQuery(query: FilterQuery<any>): Promise<Board>;
getAllMainBoards(): Promise<Board[]>;
deleteManySubBoards(
dividedBoards: Board[] | ObjectId[] | string[],
withSession: boolean
Expand Down
10 changes: 10 additions & 0 deletions backend/src/modules/boards/repositories/board.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ export class BoardRepository
return this.findOneById(boardId);
}

getAllMainBoards(): Promise<Board[]> {
return this.findAllWithQuery(
{
$and: [{ isSubBoard: false }]
},
null,
'team'
);
}

getBoardPopulated(boardId: string, populate?: PopulateType) {
return this.findOneById(boardId, {}, populate);
}
Expand Down
4 changes: 4 additions & 0 deletions backend/src/modules/boards/services/get.board.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ export default class GetBoardServiceImpl implements GetBoardServiceInterface {
return this.boardUserRepository.getBoardUsers(board, user);
}

getAllMainBoards() {
return this.boardRepository.getAllMainBoards();
}

/* --------------- HELPERS --------------- */

private async getBoards(allBoards: boolean, query: QueryType, page = 0, size = 10) {
Expand Down
8 changes: 2 additions & 6 deletions backend/src/modules/boards/services/update.board.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ export default class UpdateBoardServiceImpl implements UpdateBoardServiceInterfa
await Promise.all(promises);
}

/**
* TODO:
* When the mainBoardId starts to be returned by the board, remove this query from the board repository
*/
const mainBoardId = await this.boardRepository.getMainBoardOfSubBoard(boardId);
const mainBoardId = boardData.mainBoardId;

const promises = boardData.users
.filter((boardUser) =>
Expand All @@ -119,7 +115,7 @@ export default class UpdateBoardServiceImpl implements UpdateBoardServiceInterfa
const typedBoardUser = boardUser.user as unknown as User;

return this.boardUserRepository.updateBoardUserRole(
mainBoardId._id,
mainBoardId,
typedBoardUser._id,
boardUser.role
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe('ColumnsController', () => {
getTokenAuthService,
updateUserService,
boardUserRepository,
createBoardUserService,
{
provide: getModelToken('User'),
useValue: {}
Expand Down
10 changes: 0 additions & 10 deletions backend/src/modules/teams/entities/teams.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
import * as leanVirtualsPlugin from 'mongoose-lean-virtuals';
import BaseModel from 'src/libs/models/base.model';
import Board from '../../boards/entities/board.schema';
import TeamUser from './team.user.schema';

export type TeamDocument = Team & Document;
Expand All @@ -16,8 +15,6 @@ export default class Team extends BaseModel {
@Prop({ nullable: false, required: true, unique: true })
name!: string;

boards?: Board[];

users?: TeamUser[];
}

Expand All @@ -31,10 +28,3 @@ TeamSchema.virtual('users', {
foreignField: 'team',
justOne: false
});

TeamSchema.virtual('boards', {
ref: 'Board',
localField: '_id',
foreignField: 'team',
justOne: false
});
26 changes: 22 additions & 4 deletions backend/src/modules/teams/services/get.team.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ import { ForbiddenException, Inject, Injectable } from '@nestjs/common';
import { GetTeamServiceInterface } from '../interfaces/services/get.team.service.interface';
import Team from '../entities/teams.schema';
import { TYPES } from '../interfaces/types';
import * as Boards from 'src/modules/boards/interfaces/types';
import { TeamRepositoryInterface } from '../repositories/team.repository.interface';
import { TeamUserRepositoryInterface } from '../repositories/team-user.repository.interface';
import User from 'src/modules/users/entities/user.schema';
import UserDto from 'src/modules/users/dto/user.dto';
import { GetBoardServiceInterface } from 'src/modules/boards/interfaces/services/get.board.service.interface';

@Injectable()
export default class GetTeamService implements GetTeamServiceInterface {
constructor(
@Inject(TYPES.repositories.TeamRepository)
private readonly teamRepository: TeamRepositoryInterface,
@Inject(TYPES.repositories.TeamUserRepository)
private readonly teamUserRepository: TeamUserRepositoryInterface
private readonly teamUserRepository: TeamUserRepositoryInterface,
@Inject(Boards.TYPES.services.GetBoardService)
private getBoardService: GetBoardServiceInterface
) {}

countTeams(userId: string) {
Expand Down Expand Up @@ -47,9 +51,17 @@ export default class GetTeamService implements GetTeamServiceInterface {
teamsUser.map((teamUser) => teamUser._id)
);

return teams.map((team) => {
return { ...team, boardsCount: team.boards?.length ?? 0, boards: undefined };
const allBoards = await this.getBoardService.getAllMainBoards();

const teamsResult = teams.map((team) => {
return {
...team,
boardsCount:
allBoards.filter((board) => String(board.team) === String(team._id)).length ?? 0
};
});

return teamsResult;
}

getUsersOnlyWithTeams(users: User[]) {
Expand All @@ -65,8 +77,14 @@ export default class GetTeamService implements GetTeamServiceInterface {

const teams = await this.teamRepository.getAllTeams();

const allBoards = await this.getBoardService.getAllMainBoards();

return teams.map((team) => {
return { ...team, boardsCount: team.boards?.length ?? 0, boards: undefined };
return {
...team,
boardsCount:
allBoards.filter((board) => String(board.team) === String(team._id)).length ?? 0
};
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const AlertDeleteColumn: React.FC<AlertDeleteColumnProps> = ({
columns,
addCards,
},
mainBoard,
} = useRecoilValue(boardInfoState);

// State used to change values
Expand Down Expand Up @@ -82,6 +83,7 @@ const AlertDeleteColumn: React.FC<AlertDeleteColumnProps> = ({
responsible: users?.find((user) => user.role === BoardUserRoles.RESPONSIBLE),
deletedColumns,
socketId,
mainBoardId: mainBoard?._id,
});
};

Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Board/DragDropArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const DragDropArea: React.FC<Props> = ({
columns: columnsArray,
responsible: boardState.board.users?.find((user) => user.role === BoardUserRoles.RESPONSIBLE),
socketId,
mainBoardId: boardState.mainBoard?._id,
});
};

Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/Board/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const BoardSettings = ({
addCards,
postAnonymously,
},
mainBoard,
} = useRecoilValue(boardInfoState);

const [deletedColumns, setDeletedColumns] = useRecoilState(deletedColumnsState);
Expand Down Expand Up @@ -243,6 +244,7 @@ const BoardSettings = ({
deletedColumns,
socketId,
responsible: data.users?.find((user) => user.role === BoardUserRoles.RESPONSIBLE),
mainBoardId: mainBoard?._id,
});

setDeletedColumns([]);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/board/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export type UpdateBoardType = {
team?: string;
phase?: string;
createdBy?: string;
mainBoardId?: string;
};

export type UpdateBoardPhaseType = {
Expand Down